private static void AddRow(IXlRowData rowData, SheetData sheetData, XlSharedStringsTable stringsTable, int rowIndex) { int columnIndex = 1; Row row = new Row() { RowIndex = (uint)rowIndex }; //sheetData.AppendChild(row); foreach (IXlCell cell in rowData) { string cellReference = CellIndexHelper.FormatCellIndex(rowIndex, columnIndex); Cell newCell = new Cell() { CellReference = cellReference, StyleIndex = cell.CellStyle }; row.AppendChild(newCell); SetCellValue(cell.CellValue, cell.CellType, newCell, stringsTable); columnIndex++; } sheetData.AppendChild(row); //moved from above to ensure all cell writes are on the "standalone" row then just 1 DOM manip to insert row into sheet. }
private static void AddRow(XlWorksheet worksheet, XlSharedStringsTable stringTable, Row row) { int expectedColumn = 1; bool columnsInOrder = true; XlRowData rowData = new XlRowData(); IEnumerable <Cell> cells = row.Elements <Cell>(); foreach (Cell cell in cells) { //if (columnsInOrder) //{ if (cell.CellReference == null) { columnsInOrder = false; } else { int[] indexes = CellIndexHelper.IndexesFromReference(cell.CellReference); int rowIndex = indexes[0]; int columnIndex = indexes[1]; AddCell(rowData, stringTable, cell, columnIndex); if (columnIndex == expectedColumn && rowIndex == row.RowIndex) { expectedColumn++; } else { columnsInOrder = false; } } //} } //if (columnsInOrder) //{ worksheet.Rows.AddRow(rowData); //} }