如何在 C# 中使用 Spreadsheet Gear 创建复选框?

问题描述 投票:0回答:1

我需要使用电子表格设备在 Excel 中添加一个复选框。 Spreadsheet Gear 的文档非常糟糕,并且不包含任何有关如何正确初始化它们的方法或信息。你怎么样:

  1. 使用正确的语法创建复选框对象
  2. 向对象添加替代文本
  3. 控制检查 true 或 false 功能 - 我看到这可能是 checkboxtrue 或 false 方法,但想确定一下。
c# excel checkbox reporting spreadsheetgear
1个回答
0
投票

更新: SpreadsheetGear 2023 / V9 现已推出,支持使用 Open XML (.xlsx / .xlsm) 文件格式读取和写入表单控件。 请参阅下面我对您的问题的答复,但我确实需要提及 SpreadsheetGear 2017 / V8 版本在处理表单控件时的当前限制。如文档中的限制页面所述,使用 Open XML(*.xlsx 或 *.xlsm)文件格式时,尚无法从文件中读取或写入表单控件。因此,要将复选框保留到 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。将替代文本添加到对象

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;
© www.soinside.com 2019 - 2024. All rights reserved.