Reputation: 1636
I am able to open up a pre-set excel document (.xls/.xlsx) and change particular cells using:
Microsoft.Office.Interop.Excel.Range date = theWorkSheet1.UsedRange;
date = date.get_Range("B4");
date.Value = theDate;
However, this only allows me to change the specified cell values (in this case B4). I have come across Radio Buttons
and Check Boxes
and would like to change those values in the current excel sheet using my GUI with custom functionality. So if something in my C# GUI is checked or enabled, the radio buttons/check boxes in the excel file will change accordingly.
There are more than one set of radio buttons and check boxes.
Can anyone help me figure out how to read the different groups of radio buttons and check boxes and properly populate them according to a set of rules?
Upvotes: 1
Views: 1711
Reputation: 1
Assign value to checkbox in Excel file using C# by PradeepLutare
// Get the Excel file location
xlWorkBook = xlApp.Workbooks.Open("C:\LPL\LPLRating.xls", misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue, misValue);
// Pass the Workbook Name from that excel file
workSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item("Rate Sheet - Primary");
// assigne value according to your logic.
workSheet.OLEObjects("CheckBox1").Object.Value = true;
Upvotes: 0
Reputation: 33657
The Worksheet object will have properties on it called CheckBoxes
and OptionButtons
. Each of these is a collection of all the checkboxes and option buttons on the worksheet, respectively. You can set their Value
property to 0 (unchecked), 1 (checked) or 2 (indeterminate), for example:
worksheet.Checkboxes("Checkbox1").Value = 1
Some worksheets may have OLEObjects on them instead of plain old Excel Checkboxes, in which case you'll have to do this:
worksheet.OLEObjects("Checkbox1").Object.Value = 1
Upvotes: 1