C#读取Excel表格中的内容
随手记录,我自己也搞不明白。直接拿去用了
public static string ReadXLSX(string filePath) { string sb=""; using (var file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { var hssfworkbook = new XSSFWorkbook(file); var sheet = hssfworkbook.GetSheetAt(0); var rows = sheet.GetRowEnumerator(); while (rows.MoveNext()) { var row = (XSSFRow)rows.Current; for (var i = 0; i < row.LastCellNum; i++) { string cell = row.GetCell(i).ToString(); sb += "\r\n" + cell; } } } return sb; }