1
This commit is contained in:
parent
3173ea3cb7
commit
f317d90489
@ -502,8 +502,43 @@ namespace DOAN.Service.MES.product
|
||||
ISheet sheet = workbook.GetSheetAt(0);
|
||||
|
||||
int startRowIndex = 2; // 从第3行开始写数据
|
||||
// 清空第 3 行及之后所有行的内容
|
||||
for (int rowIndex = startRowIndex; rowIndex <= sheet.LastRowNum; rowIndex++)
|
||||
{
|
||||
IRow row = sheet.GetRow(rowIndex);
|
||||
if (row != null)
|
||||
{
|
||||
// 遍历该行的所有单元格,清空内容
|
||||
for (int cellIndex = 0; cellIndex < row.LastCellNum; cellIndex++)
|
||||
{
|
||||
ICell cell = row.GetCell(cellIndex);
|
||||
if (cell != null)
|
||||
{
|
||||
// 根据单元格类型设置为空值
|
||||
switch (cell.CellType)
|
||||
{
|
||||
case CellType.String:
|
||||
cell.SetCellValue("");
|
||||
break;
|
||||
case CellType.Numeric:
|
||||
cell.SetCellValue(0);
|
||||
break;
|
||||
case CellType.Boolean:
|
||||
cell.SetCellValue(false);
|
||||
break;
|
||||
case CellType.Formula:
|
||||
cell.SetCellFormula(""); // 或者可以移除公式,设为其他类型
|
||||
break;
|
||||
// 其它类型根据需要处理
|
||||
default:
|
||||
cell.SetCellValue("");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
for (int i = 0; i < dataList.Count; i++)
|
||||
{
|
||||
var item = dataList[i];
|
||||
IRow row = sheet.GetRow(startRowIndex + i) ?? sheet.CreateRow(startRowIndex + i);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user