我需要使用电子表格工具在 Excel 中添加一个复选框。 Spreadsheet Gear 的文档很糟糕,不包含任何方法或有关如何正确初始化这些的信息。你好吗:
答案 0 :(得分:0)
请参阅下面我对您问题的回答,但我确实需要提及在处理表单控件时 SpreadsheetGear 2017 / V8 版本中的当前限制。如文档中此 Limitations 页面所述,使用 Open XML(*.xlsx 或 *.xlsm)文件格式时,尚未从文件中读取或写入表单控件。因此,要将 CheckBox 保留到 Excel 文件中,您现在需要将其保存为 Excel 97-2003 (*.xls) 文件格式。 SpreadsheetGear 的下一个主要版本 V9 将解决这个限制。
1.使用正确的语法创建复选框对象
// Create new workbook and reference to the active sheet.
IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
IWorksheet worksheet = workbook.ActiveWorksheet;
// Add a CheckBox form control to a worksheet, specify position and dimensions, and get its IShape and IControlFormat objects back.
SpreadsheetGear.Shapes.IShape shape = worksheet.Shapes.AddFormControl(
SpreadsheetGear.Shapes.FormControlType.CheckBox, 50, 5, 100, 25);
SpreadsheetGear.Shapes.IControlFormat checkBox = shape.ControlFormat;
// Set label text for the checkBox if desired.
shape.TextFrame.Characters.Text = "My CheckBox";
2.向对象添加 Alt 文本
SpreadsheetGear 不支持指定表单控件的替代文本。
3.控制检查 true 或 false 功能 - 我看到这可能是 checkboxtrue 或 false 方法,但想确定。
// Set the value of the checkBox to "checked" with a value of 1 (0 == unchecked,
// some other value == indeterminate).
checkBox.Value = 1;