-2

I need to add a checkbox in Excel using Spreadsheet gear. The documentation for Spreadsheet Gear is terrible and doesn't include any methods or info on how to initialize these properly. How do you:

  1. Create the checkbox object using correct syntax
  2. Add Alt text to object
  3. Control check true or false feature - I see this may be checkboxtrue or false methods but want to be sure.

1 Answers1

0

See my responses to your questions below, but I do need to mention a current limitation in the SpreadsheetGear 2017 / V8 version when dealing with Form Controls. As described on this Limitations page in the doc, Form Controls are not yet read from or written to a file when using the Open XML (*.xlsx or *.xlsm) file formats. So to persist a CheckBox to an Excel file you will need to save to the Excel 97-2003 (*.xls) file format for now. The next major release of SpreadsheetGear, V9, will address this limitation.

1. Create the checkbox object using correct syntax

// 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. Add Alt text to object

SpreadsheetGear does not support specifying the Alternative Text of a form control.

3. Control check true or false feature - I see this may be checkboxtrue or false methods but want to be sure.

// Set the value of the checkBox to "checked" with a value of 1 (0 == unchecked,
// some other value == indeterminate).
checkBox.Value = 1;
Tim Andersen
  • 3,014
  • 1
  • 15
  • 11