[TestMethod]
public void Test()
{
_config = new AppSettingOptions() { ResDir = "D:\\VR2\\" };
var resDir = _config.ResDir;
if (Directory.Exists(resDir))
{
DirectoryInfo dir = new DirectoryInfo(resDir);
FileInfo[] files = dir.GetFiles("*.xlsx");
foreach (FileInfo file in files)
{
string filePath = file.FullName;
var workbook = new XSSFWorkbook(filePath);
var sheet01 = workbook.GetSheet("活动");
int rowCount = sheet01.LastRowNum;//总行数
if (rowCount > 0)
{
IRow firstRow = sheet01.GetRow(0);//第一行
int cellCount = firstRow.LastCellNum;//列数
var rowList = new List<string>();
for (int i = 1; i <= rowCount; i++)
{
var row = sheet01.GetRow(i);
if (row == null) continue;
foreach (var cell in row.Cells)
{
rowList.Add(cell.ToString());
}
}
}
}
}
}
c# NPOI读取xlsx
最新推荐文章于 2024-06-17 23:31:56 发布