//Sort of working... incomplete and in progress private static Cell CreateCellBasedOnType(object dataItem, string cellReference, int styleIndex, SpreadsheetDocument ssDoc) { Cell newCell = null; //WorkbookPart workbookPart = ssDoc.WorkbookPart; //var styles = workbookPart.GetPartsOfType<WorkbookStylesPart>().FirstOrDefault(); //CellFormat cellFormat = (CellFormat)(styles.Stylesheet.CellFormats.Elements().ElementAt(styleIndex)); if (dataItem is DateTime) { string universalDate = ((DateTime)dataItem).ToOADate().ToString(); //styleIndex = (int)cellFormat.NumberFormatId.Value; newCell = ExcelReportGenerator.CreateDateCell( universalDate, cellReference, styleIndex); } else if (Utility.IsNumeric(dataItem)) { newCell = ExcelReportGenerator.CreateNumberCell(dataItem.ToString(), cellReference); } else { //newCell = ExcelReportGenerator.CreateSharedStringCell(dataItem.ToString(), cellReference); newCell = ExcelReportGenerator.CreateInlineTextCell(dataItem.ToString(), cellReference); } return newCell; }
private static void OutputRawData(DataTable dataTable, SpreadsheetDocument ssDoc, string sheetName) { SheetData sheetData = ExcelReportGenerator.GetSheetData(ssDoc, sheetName); int currRowIndex = 1; Row headerRow = new Row(); headerRow.RowIndex = (UInt32)currRowIndex; for (int colIndex = 0; colIndex < dataTable.Columns.Count; colIndex++) { Cell newCell = ExcelReportGenerator.CreateInlineTextCell( dataTable.Columns[colIndex].ColumnName, ExcelColumnReferenceLookup[colIndex] + currRowIndex); headerRow.AppendChild(newCell); } currRowIndex++; sheetData.AppendChild(headerRow); for (int row = 0; row < dataTable.Rows.Count; row++) { Row newRow = new Row(); newRow.RowIndex = (UInt32)currRowIndex; for (int colIndex = 0; colIndex < dataTable.Columns.Count; colIndex++) { CellType ct = ExcelReportGenerator.DetermineCellType(dataTable.Rows[row][colIndex]); int styleIndex = (int)(ExcelReportGenerator.DefaultTemplateCells[(int)ct].StyleIndex.Value); object currObj = dataTable.Rows[row][colIndex]; if (dataTable.Rows[row][colIndex] is DBNull) { currObj = "NULL"; } Cell newCell = ExcelReportGenerator.CreateCellBasedOnType(currObj, ExcelColumnReferenceLookup[colIndex] + currRowIndex, styleIndex, ssDoc); newRow.AppendChild(newCell); } sheetData.AppendChild(newRow); currRowIndex++; } }
private static void OutputRawData(object[][] inputData, SpreadsheetDocument ssDoc, string sheetName) { SheetData sheetData = ExcelReportGenerator.GetSheetData(ssDoc, sheetName); int currRowIndex = 1; for (int i = 0; i < inputData.GetLength(0); i++) { Row newRow = new Row(); newRow.RowIndex = (UInt32)(currRowIndex); for (int j = 0; j < inputData[i].Count(); j++) { Cell newCell = ExcelReportGenerator.CreateInlineTextCell( inputData[i][j].ToString(), ExcelColumnReferenceLookup[j] + currRowIndex); newRow.AppendChild(newCell); } sheetData.AppendChild(newRow); currRowIndex++; } }