How to apply excel formulas in gembox.Spreadsheet

242 Views Asked by At

I want to apply this formula to all C3 cells excluding header '=IF(ISBLANK(B3), "", 10)' to my spreadsheet.

How can I achieve that?

2

There are 2 best solutions below

0
Mario Z On

Try this:

var workbook = new ExcelFile();
var worksheet = workbook.Worksheets.Add("Sheet1");
var cell = worksheet.Cells["C3"];
cell.Formula = "'=IF(ISBLANK(B3), \"\", 10)";
workbook.Save("output.xlsx");
0
Phuluso Ramulifho On

This is what I have finally come to:

     worksheet.Cells.GetSubrange("C2", "C5000").Formula = $@"=IF(ISBLANK(B2:B5000 ), """", {10})";
     
        worksheet.DataValidations.Add(new DataValidation(worksheet.Columns[5].Cells.GetSubrange("C2", "C5000"))
        {
            Type = DataValidationType.WholeNumber,

            Operator = DataValidationOperator.Equal,              
            InputMessageTitle = "Edits Not Allowed",
            InputMessage = "Value in the cell cannot be changed",
            ErrorTitle = "Edits Not Allowed",
            ErrorMessage = "Value in the cell cannot be changed"
        }); ;