简体   繁体   English

如何在每个行的Excel电子表格中向单元格添加表单控件

[英]How do you add a forms controls to a cell in a Excel spreadsheet for each row

我如何在Excel中添加表单控件到单元格,我知道我可以绘制它,但我需要使它成为每一行的成员,并且它的值附加到该单元格/行。

There are several ways to do this but the easiest, assuming Excel 2007 is: 有几种方法可以做到这一点,但最简单的,假设Excel 2007是:

Set cb = MyWorkSheet.CheckBoxes.Add(left, top, width, height)
cb.LinkedCell = "$A$1"
cb.Display3DShading = True

You have to experiment a little with placement as I don't think there is a direct way to align the control with a particular cell. 您必须对放置进行一些实验,因为我认为没有直接的方法将控件与特定单元格对齐。 Another way would be to use the Shapes collection of the worksheet: 另一种方法是使用工作表的Shapes集合:

Set shape = MyWorkSheet.Shapes.AddFormControl(xlCheckBox, l, t, w, h)

However, keep in mind that the above method returns a Shape object and not a CheckBox object so you can't manipulate its properties directly. 但是,请记住,上面的方法返回一个Shape对象而不是CheckBox对象,因此您无法直接操作其属性。 There are similar methods to the above like using the OLEObjects collection but that's just adding more pain. 有类似的方法,如使用OLEObjects集合,但这只是增加了更多的痛苦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何向通过 oledb 在 excel 电子表格上运行的计数查询添加参数? - How do you add parameters to a count query ran on an excel spreadsheet via oledb? 在Excel电子表格中访问行单元格计数 - Accessing row cell count in Excel Spreadsheet 如何按名称获取和比较Excel电子表格中单元格的内容? - How do I get and compare the contents of a cell in an Excel spreadsheet by name? 如何从 Excel 电子表格创建一个 .xslt 文件? - How do you create an .xslt file from an Excel spreadsheet? Excel电子表格VSTO控件 - Excel Spreadsheet VSTO Controls 在创建Excel文件时,如何使用OpenXml向单元格添加文本换行? - How do you add text wrapping to a cell using OpenXml when creating excel files? 如何以编程方式将XML Map添加到Excel 2010电子表格中? - How do I add an XML Map programmatically to an Excel 2010 Spreadsheet? C#如何通过Linq查询将列添加到现有数据表中的每个数据行? - C# How do you add a column to an existing datatable for each data row by Linq query? 在保持每个单元格的样式和格式不变的情况下,如何以编程方式将一个Excel文档拆分为多个文档? - How do you programmatically break up one Excel document into several while still maintaining each cell's style and format? 如何使用Excel Dna设置单元格的值? - How do you set the value of a cell using Excel Dna?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM