0

I have a Excel Tamplate in which i have Checkbox placed in it. I want to do Check uncheck/Checkbox depending on some condition in Spreadsheet Gear. Checkbox is already available in the Excel Sheet. I am using Spreadsheetgear 2008. I googled but cant find answer. Can Comeone please give me any refernce for this.

Jankya
  • 966
  • 2
  • 12
  • 34

1 Answers1

2

You can set the state of a CheckBox one of two ways:

  1. Set the CheckBox's IControlFormat.Value property to the desired value.
  2. If the CheckBox is linked to a cell (see IControlFormat.LinkedCell), set the linked cell's value and it should update accordingly.

Example:

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;
Tim Andersen
  • 3,014
  • 1
  • 15
  • 11