public void WriteRange(object[][] data, string startCell) { int startRowIndex = worksheet.GetRowIndex(startCell); int startCellIndex = worksheet.GetRowIndex(startCell); List <Row> newRows = new List <Row>(); for (int i = 0; i < data.Length; i++) { int rowIndex = startRowIndex + 1; Row row = worksheet.GetRow(rowIndex); if (row == null) { row = new Row() { RowIndex = (uint)rowIndex }; newRows.Add(row); } for (int j = 0; j < data[i].Length; j++) { int cellIndex = startCellIndex + j; string cellAddress = SpreadsheetExtender.ToCellAddress(rowIndex, cellIndex); Cell resultCell = row.GetCell(cellAddress); if (resultCell == null) { resultCell = row.CreateCell(cellAddress); } resultCell.SetCellText(data[i][j]); int styleIndex = SpreadsheetExtender.GetCellStyleIndex(styleSheet, data[i][j]); resultCell.SetCellStyle(styleIndex); } sheetData.Append(newRows.ToArray()); } }
public void AppendRange(object[][] data) { if (data == null || data.Length <= 0) { throw new ArgumentNullException("Please confirm whether input datas is empty!"); } int rowIndex = worksheet.GetRowCount(); Row[] rows = new Row[data.Length]; for (int i = 0; i < data.Length; i++) { rowIndex += 1; rows[i] = new Row { RowIndex = (uint)rowIndex }; for (int j = 0; j < data[i].Length; j++) { string cellAddress = SpreadsheetExtender.ToCellAddress(rowIndex, (j + 1)); Cell cell = rows[i].CreateCell(cellAddress); cell.SetCellText(data[i][j]); int styleIndex = SpreadsheetExtender.GetCellStyleIndex(styleSheet, data[i][j]); cell.SetCellStyle(styleIndex); } } sheetData.Append(rows); }
public void WriteRow(object[] data, int row, int column = 1) { object[][] table = new object[1][]; table[0] = data; string cellAddress = SpreadsheetExtender.ToCellAddress(row, column); WriteRange(table, cellAddress); }
public void WriteColumn(object[] data, int column, int row = 1) { object[][] table = new object[data.Length][]; for (int i = 0; i < table.Length; i++) { table[i] = new object[] { data[i] }; } string cellAddress = SpreadsheetExtender.ToCellAddress(row, column); }
public object[] ReadColumn(int columnIndex, bool ignoreHeader = true) { string startCell = string.Empty; string endCell = string.Empty; object[] resultArray; if (!ignoreHeader) { startCell = SpreadsheetExtender.ToCellAddress(header, columnIndex); endCell = SpreadsheetExtender.ToCellAddress(worksheet.GetRowCount(), columnIndex); } var table = ReadRange(startCell, endCell); resultArray = new object[table.Length]; for (int i = 0; i < table.Length; i++) { resultArray[i] = table[i][0]; } return(resultArray); }
private string GetCellAddressByMapping(int rowIndex, MappingAttribute attribute, Dictionary <string, Cell> cellMapping) { int cellIndex = 1; string cellAddress = string.Empty; switch (attribute.MappingOption) { case MappingOption.FieldName: cellIndex = cellMapping[attribute.MappingKey].GetCellIndex(); cellAddress = SpreadsheetExtender.ToCellAddress(rowIndex, cellIndex); break; case MappingOption.ColumnName: cellAddress = attribute.MappingKey + rowIndex; break; case MappingOption.ColumnIndex: cellAddress = SpreadsheetExtender.ToCellAddress(rowIndex, int.Parse(attribute.MappingKey)); break; } return(cellAddress); }
public void WriteRange(object[][] data, int row, int column) { string cellAddress = SpreadsheetExtender.ToCellAddress(row, column); WriteRange(data, cellAddress); }