When creating Excel documents or reports such as finance documents, sales reports, invoices, student status reports, forms, and others, it is often required to have cells with pre-filled text or fixed data rather than empty or blank cells that can be used in further processing and calculations.
The default value can help in such a scenario and provides a value or formula to be displayed and used in calculations like a normal cell value. DsExcel provides DefaultValue property in IRange interface that allows you to set the default value of a cell to avoid empty cell scenarios.
The default value has certain characteristics that are listed below:
Refer to the following example code to set the default value of cells:
C# |
Copy Code |
---|---|
// Initialize workbook. var workbook = new Workbook(); // Open defaultValue.xlsx. workbook.Open("defaultValue.xlsx"); var worksheet = workbook.ActiveSheet; // Set default value for standard reduction. worksheet.Range["C4:C8"].DefaultValue = "=B4 - B4*0.12"; // Set normal value for specific percent reduction. worksheet.Range["C6"].Formula = "=B6 - B6*0.08"; worksheet.Range["C8"].Formula = "=B8 - B8*0.05"; // Calculate total on default value and specific values. worksheet.Range["C9"].Formula = "=SUM(C4:C8)"; // Save to an Excel file. workbook.Save("DefaultValueOutput.xlsx"); |
Limitations