Search code examples
c#excelepplus

How to read the state of a checkbox in an excel file with EPPlus ( C# )


The title already explains my problem pretty well. I have an excel file which contains checkboxes and I would like to read their state (checked or not) using the EPPlus library.

enter image description here

I am not sure if this is even supported. So far I have found no documentation or examples for that specific problem using EPPlus.


Solution

  • If you add a Cell link then pulling the value is straight forward. I don't believe that the Drawing Object contains the value. Checkbox Settings

    using System.Linq;
    using OfficeOpenXml;
    using OfficeOpenXml.Drawing;
    
    namespace EPPlus {
                   public void Run() {
                var excelFile = new System.IO.FileInfo(System.IO.Path.Combine(BaseDirectory, "Excel", "Checkbox.xlsx"));
                using (ExcelPackage excel = new ExcelPackage(excelFile))
                {
                    ExcelWorksheet sheet = excel.Workbook.Worksheets.SingleOrDefault(a => a.Name == "Sheet1");
                    ExcelDrawing checkbox2 = sheet.Drawings.SingleOrDefault(a => a.Name == "Check Box 2");
                   var value = sheet.Cells["G5"].Value.ToString();
    
                }
            }
        }
    }