private static void AppendTextCell(string cellReference, string cellStringValue, DocumentFormat.OpenXml.OpenXmlWriter writer) { // Add a new "text" Cell to our Row #if DATA_CONTAINS_FORMULAE // If this item of data looks like a formula, let's store it in the Excel file as a formula rather than a string. if (cellStringValue.StartsWith("=")) { AppendFormulaCell(cellReference, cellStringValue, writer); return; } void AppendFormulaCell() { // Add a new "formula" Excel Cell to our Row writer.WriteElement(new DocumentFormat.OpenXml.Spreadsheet.Cell { CellFormula = new DocumentFormat.OpenXml.Spreadsheet.CellFormula(cellStringValue), CellReference = cellReference, DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.Number }); } #endif // Add a new Excel Cell to our Row writer.WriteElement(new DocumentFormat.OpenXml.Spreadsheet.Cell { CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(cellStringValue), CellReference = cellReference, DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String }); }
private static void AppendNumericCell(string cellReference, string cellStringValue, DocumentFormat.OpenXml.OpenXmlWriter writer) { // Add a new numeric Excel Cell to our Row. writer.WriteElement(new DocumentFormat.OpenXml.Spreadsheet.Cell { CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(cellStringValue), CellReference = cellReference, DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.Number }); }
private static void AppendHeaderTextCell(string cellReference, string cellStringValue, DocumentFormat.OpenXml.OpenXmlWriter writer) { // Add a new "text" Cell to the first row in our Excel worksheet // We set these cells to use "Style # 3", so they have a gray background color & white text. writer.WriteElement(new DocumentFormat.OpenXml.Spreadsheet.Cell { CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(cellStringValue), CellReference = cellReference, DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String }); }
private static void AppendDateCell(string cellReference, DateTime dateTimeValue, DocumentFormat.OpenXml.OpenXmlWriter writer) { // Add a new "datetime" Excel Cell to our Row. // string cellStringValue = dateTimeValue.ToShortDateString(); writer.WriteElement(new DocumentFormat.OpenXml.Spreadsheet.Cell { CellValue = new DocumentFormat.OpenXml.Spreadsheet.CellValue(cellStringValue), CellReference = cellReference, DataType = DocumentFormat.OpenXml.Spreadsheet.CellValues.String }); }