Spreadsheetgear中的CheckBox操作

时间:2013-07-23 06:02:36

标签: c# spreadsheetgear

我有一个Excel Tamplate,其中放置了Checkbox。 我想根据Spreadsheet Gear中的某些条件检查取消选中/复选框。 复选框已在Excel工作表中提供。我正在使用Spreadsheetgear 2008。 我用谷歌搜索但无法找到答案。 Can Comeone请给我任何参考。

1 个答案:

答案 0 :(得分:2)

您可以通过以下两种方式设置CheckBox的状态:

  1. 将CheckBox的IControlFormat。Value属性设置为所需的值。
  2. 如果CheckBox链接到单元格(请参阅IControlFormat。LinkedCell),请设置链接单元格的值,并相应地更新。
  3. 示例:

    using SpreadsheetGear;
    using SpreadsheetGear.Shapes;
    
    // Open workbook containing the CheckBox
    IWorkbook workbook = Factory.GetWorkbook("CheckBox.xls");
    // Assume CheckBox is in Sheet1
    IWorksheet worksheet = workbook.Worksheets["Sheet1"];
    // CheckBoxes reside within a Shape, so access the shape
    Shapes.IShape shape = worksheet.Shapes["Check Box 1"];
    // Access the CheckBox directly
    Shapes.IControlFormat checkbox = shape.ControlFormat;
    
    // A checkbox’s IControlFormat.Value will be set to 0 if it is unchecked, 
    // 1 if it is checked, and 2 if it is in an "indeterminate" state.  
    checkbox.Value = 1;
    
    // Assume CheckBox is linked to cell A1 in this worksheet
    worksheet.Cells["A1"].Value = true;