private List <ExcelCellValue> GetSheetValues(ISheet sheet) { List <ExcelCellValue> excelCellValues = new List <ExcelCellValue>(); for (int j = 0; j <= sheet.LastRowNum; j++) //LastRowNum 是当前表的总行数 { IRow row = sheet.GetRow(j); //读取当前行数据 if (row == null) { continue; } for (int k = 0; k <= row.LastCellNum; k++) //LastCellNum 是当前行的总列数 { ICell cell = row.GetCell(k); //当前表格 if (cell == null) { continue; } ExcelCellValue cellValue = new ExcelCellValue(); cellValue.row = j; cellValue.col = k; cellValue.value = cell.ToString(); //获取表格中的数据并转换为字符串类型 excelCellValues.Add(cellValue); } } return(excelCellValues); }
private void SetCellValue(ISheet sheet, ExcelCellValue cellValue) { IRow rowData = sheet.GetRow(cellValue.row); //读取当前行数据 if (rowData == null) { rowData = sheet.CreateRow(cellValue.row); } ICell cell = rowData.GetCell(cellValue.col); if (cell == null) { cell = rowData.CreateCell(cellValue.col); } cell.SetCellValue(cellValue.value); }
public void SetCellValue(int sheetIndex, ExcelCellValue cellValue) { ISheet sheet = workBook.GetSheetAt(sheetIndex); SetCellValue(sheet, cellValue); }
/// <summary> /// 向单元格插入数据 /// </summary> /// <param name="sheetName"></param> /// <param name="cellValue"></param> public void SetCellValue(string sheetName, ExcelCellValue cellValue) { ISheet sheet = workBook.GetSheet(sheetName); SetCellValue(sheet, cellValue); }