Skip to content

Commit 49b5068

Browse files
author
fileformat-cells
authored
Merge pull request #3 from fahadadeel/main
Add "AddFormulaToCell" Feature
2 parents 7159dce + 9b73eec commit 49b5068

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

FileFormat.Cells/Worksheet.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,28 @@ public void saveDataToSheet(int sheetIndex)
149149

150150
}
151151

152+
public void AddFormulaToCell(string cellRef, UInt32 rowIndex, string formula)
153+
{
154+
155+
DocumentFormat.OpenXml.Spreadsheet.Row row = new DocumentFormat.OpenXml.Spreadsheet.Row()
156+
{
157+
RowIndex = rowIndex
158+
};
159+
160+
// Create the CellFormula element
161+
CellFormula cellFormula = new CellFormula
162+
{
163+
CalculateCell = true,
164+
Text = formula
165+
};
166+
DocumentFormat.OpenXml.Spreadsheet.Cell cell = new DocumentFormat.OpenXml.Spreadsheet.Cell()
167+
{
168+
CellReference = cellRef,
169+
CellFormula = cellFormula
170+
};
171+
row.Append(cell);
172+
sheetData.sheetData.Append(row);
173+
}
152174

153175
private static List<UInt32> AddStyle(ref Stylesheet stylesheet)
154176
{

0 commit comments

Comments
 (0)