internal static List <string> Headers(XlWorksheet worksheet) { List <string> headers = new List <string>(); IXlRowData row = worksheet.Rows[0]; foreach (IXlCell o in row) { headers.Add(o.CellValue); } return(headers); }
private void FillRow(Dictionary <string, string> row, List <string> headers, IXlRowData dataRow) { //List<IXlCell> headers = new List<IXlCell>(headerRow); //this is a waste List <IXlCell> values = new List <IXlCell>(dataRow); int numValues = Math.Min(headers.Count, values.Count); //in case they don't match for (int index = 0; index < numValues; index++) { row[headers[index]] = values[index].CellValue; //note that if there's multiple columns with same name this gets last value for that name } }
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. }