我需要一些快速帮助。如何使用 excellibrary 获取单元格的内容?文档很薄。
我真的没有得到示例代码:
// traverse cells
foreach (Pair<Pair<int, int>, Cell> cell in sheet.Cells)
{
dgvCells[cell.Left.Right, cell.Left.Left].Value = cell.Right.Value;
}
// traverse rows by Index
for (int rowIndex = sheet.Cells.FirstRowIndex;
rowIndex <= sheet.Cells.LastRowIndex; rowIndex++)
{
Row row = sheet.Cells.GetRow(rowIndex);
for (int colIndex = row.FirstColIndex;
colIndex <= row.LastColIndex; colIndex++)
{
Cell cell = row.GetCell(colIndex);
}
}
它似乎过于复杂。我需要做类似的事情:
xlInfo[0,0] = cell 1,1;
xlInfo[0,1] = cell 1,2;
xlInfo[0,2] = cell 1,3;
使用 EPPlus,它看起来像这样:
xlInfo[0,0] = sheet.Cells[1,1];
xlInfo[0,1] = sheet.Cells[1,2];
xlInfo[0,2] = sheet.Cells[1,3];
excellibrary 有类似的方法吗?(免责声明:这些示例片段中可能会出现一些语法错误,但它们只是出于理论目的。)
编辑:
xlInfo[0, 0] = Convert.ToString(sheet.Cells[1, 1]);
给我一个 NullReferenceException (对象引用未设置为对象的实例。)。