Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Wed Jan 05, 2022 4:18 am

If you have a row with more than one checkbox it can be a little difficult reading each CheckState into separate variables. For example, let's say you have a sheet with three columns: ProductID, BackRelieved and EndMatched. BackRelieved and EndMatched are checkboxes. If you read each row, BackRelieved will be sheet.CheckBoxes[0].CheckState and EndMatched will be sheet.CheckBoxes[1].CheckState. Then the next row will be BackRelieved sheet.CheckBoxes[2].CheckState and EndMatched sheet.CheckBoxes[3].CheckState. So if you have 50 rows, you will have 100 checkbox items. To separate each checkbox on the row as you iterate through the sheet, use a separate counter (j) instead of the sheet row count (i). Then you can increment the checkbox counter (j) for each checkbox in the row.

Code: Select all
       int j = 0; // for checkbox counter
       for (int i = 1; i < sheet.Rows.Length; i++)
        {
            string ProductID = sheet.Rows[i].Columns[0].DisplayedText;           

            bool BackRelieved = false;           
            if (sheet.CheckBoxes[j].CheckState.ToString() == "Checked")
                BackRelieved = true;
            j = j + 1;

            bool EndMatched = false;           
            if (sheet.CheckBoxes[j].CheckState.ToString() == "Checked")
                EndMatched = true;
            j = j + 1;

       }
 

surfdmountain
 
Posts: 8
Joined: Wed Dec 15, 2021 9:49 pm

Wed Jan 05, 2022 7:03 am

Hello,

Thank you surfdmountain for sharing your question and solution. You are all kindness. I believe this will help others in need.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1643
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.XLS