NOPI读取Excel


string filePath = "C:/Users/29939/Desktop/当前项目文件/图像资源/test/Result/result_202107271603421888/final_result.major";
string sheet = "Confidence";
HSSFWorkbook wb = new HSSFWorkbook(new FileStream(filePath, FileMode.Open, FileAccess.Read));
HSSFSheet sht = (HSSFSheet)wb.GetSheet(sheet); //如果是2003 则用HSS开头的对象。
FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read);
//XSSFWorkbook xworkbook = new XSSFWorkbook(file);
//XSSFSheet xsheet = (XSSFSheet)xworkbook.GetSheet(sheet);
int rowsCount = sht.PhysicalNumberOfRows; //取行Excel的最大行数
int colsCount = sht.GetRow(0).PhysicalNumberOfCells;//取得Excel的列数

一 读取已存的Excel

HSSFWorkbook wb;
FileStream file;
file = new FileStream(filepath, FileMode.Open, FileAccess.Read);
wb = new HSSFWorkbook(file);
file.Close();

二 获取已有表

ISheet image_sheet = wk.GetSheet("Images");
ISheet confidence_sheet = wk.GetSheet("Confidence");

三 读取Excel的行数和列数

int rowsCount = image_sheet.PhysicalNumberOfRows; //取行Excel的最大行数
int colsCount = image_sheet.GetRow(0).PhysicalNumberOfCells;//取得Excel的列数