private void InsertCellByRow(int beginIndex, int endIndex, DataRow drSource, NPOI.SS.UserModel.IRow currentExcelRow) { for (int cellIndex = beginIndex; cellIndex < endIndex; cellIndex++) { //列名称 NPOI.SS.UserModel.ICell newCell = currentExcelRow.GetCell(cellIndex); newCell.SetCellType(NPOI.SS.UserModel.CellType.NUMERIC); newCell.SetCellValue(Convert.ToDouble(drSource[cellIndex])); } }
/// <summary> /// Get a specific cell from a row. If the cell doesn't exist, /// </summary> /// <param name="row">The row that the cell is part of</param> /// <param name="column">The column index that the cell is in.</param> /// <returns>The cell indicated by the column.</returns> public static NPOI.SS.UserModel.ICell GetCell(NPOI.SS.UserModel.IRow row, int column) { NPOI.SS.UserModel.ICell cell = row.GetCell(column); if (cell == null) { cell = row.CreateCell(column); } return cell; }
private NPOI.SS.UserModel.ICell CreateCell(NPOI.SS.UserModel.IRow newRow, SysConext.Rectangle rectangle) { NPOI.SS.UserModel.ICell newCell = newRow.GetCell(rectangle.col1); if (newCell == null) newCell = newRow.CreateCell(rectangle.col1); newCell.SetCellValue(rectangle.titleName); if (rectangle.isMegerCell) newsheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(rectangle.row1, rectangle.row2, rectangle.col1, rectangle.col2)); return newCell; }