自动化 Excel 时,如何将文本框对象放置在特定单元格上? [英] How do you place a textbox object over a specific Cell when automating Excel?

查看:13
本文介绍了自动化 Excel 时,如何将文本框对象放置在特定单元格上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用 VB.Net 自动化 Excel,并尝试将多行文本放置在我们可以设置为不打印的 Excel 工作表上.在这些之间,我们会有可打印的报告.如果我们添加文本框对象,并将打印对象设置为 false,我们就可以做到这一点.(如果你有其他方法,请指导我)

We are automating Excel using VB.Net, and trying to place multiple lines of text on an Excel worksheet that we can set to not print. Between these we would have printable reports. We can do this if we add textbox objects, and set the print object setting to false. (If you have another way, please direct me)

添加文本框的代码是:

ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 145.5, 227.25, 304.5, 21#)

但定位是点.我们需要一种方法将它放在特定的单元格上,并根据单元格调整大小.当我们只知道把它放在哪个单元格上时,我们怎么知道把它放在哪里?

but the positioning is in points. We need a way to place it over a specific cell, and size it with the cell. How can we find out where to put it when we just know which cell to put it over?

推荐答案

如果你有单元格名称或位置,你可以这样做:

If you have the cell name or position, you can do:

With ActiveSheet
  .Shapes.AddTextbox msoTextOrientationHorizontal, .Cells(3,2).Left, .Cells(3,2).Top, .Cells(3,2).Width, .Cells(3,2).Height
End With

这将在单元格 B3 上添加一个文本框.调整 B3 大小时,文本框也是.

This will add a textbox over cell B3. When B3 is resized, the textbox is also.

这篇关于自动化 Excel 时,如何将文本框对象放置在特定单元格上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆