【发布时间】:2021-11-22 07:01:30
【问题描述】:
我有从左到右阅读EXCEL表格的顺序
for (int i = (sheet.FirstRowNum + 1); i <= sheet.LastRowNum; i++)
{
IRow row = sheet.GetRow(i);
if (row == null) continue;
if (row.Cells.All(d => d.CellType == CellType.Blank)) continue;
for (int j = row.FirstCellNum; j < cellCount; j++)
{
if (row.GetCell(j) != null)
{
if (!string.IsNullOrEmpty(row.GetCell(j).ToString()) &&
!string.IsNullOrWhiteSpace(row.GetCell(j).ToString()))
{
rowList.Add(row.GetCell(j).ToString());
}
}
}
}
我正在从第一张纸中获取所有文本,但我需要从上到下阅读每一列。
这是我尝试过的,但它最终从随机单元格中得到 1 个单词循环...
for (int i = headerRow.FirstCellNum; i < headerRow.LastCellNum; i++)
{
IRow row = sheet.GetRow(i);
if (row == null) continue;
if (row.Cells.All(d => d.CellType == CellType.Blank)) continue;
for (int j = sheet.FirstRowNum; j <= sheet.LastRowNum; j++)
{
if (row.GetCell(i) != null)
{
if (!string.IsNullOrEmpty(row.GetCell(i).ToString()) &&
!string.IsNullOrWhiteSpace(row.GetCell(i).ToString()))
{
rowList.Add(row.GetCell(i).ToString());
}
}
}
}
【问题讨论】: