From 62608682f362ff5ecddb03ef80cb441f2ccea49b Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期五, 30 九月 2022 19:19:07 +0800 Subject: [PATCH] 'bug修复' --- app/ExcelUtil.cpp | 32 +++++++++++++++++++++----------- 1 files changed, 21 insertions(+), 11 deletions(-) diff --git a/app/ExcelUtil.cpp b/app/ExcelUtil.cpp index 8567f2e..5ad3de4 100644 --- a/app/ExcelUtil.cpp +++ b/app/ExcelUtil.cpp @@ -96,40 +96,50 @@ wb.Dump(path); } -void ExcelUtil::read(string path) +std::list<ExcelGPCodeInfo> ExcelUtil::readGPCodes(string path) { xlsWorkBook* pWB = NULL; // 工作表 xlsWorkSheet* pWS = NULL; - // 单元格 - xlsCell* cell = NULL; + - int sheetIndex; + int sheetIndex=0; int row, col; // 打开文件 - pWB = xls_open(path.c_str(), "UTF-8"); + pWB = xls_open(path.c_str(), "GBK"); if (!pWB) { throw string("Open File Error!"); } // 解析xls文件,这个不要忘了 xls_parseWorkBook(pWB); - fprintf(stderr, "Sheet count:%d\n", pWB->sheets.count); + pWS = xls_getWorkSheet(pWB, 0); // 解析工作表 xls_parseWorkSheet(pWS); - fprintf(stderr, "Sheet %d name: %s\n", sheetIndex, (char*)pWB->sheets.sheet[sheetIndex].name); - - fprintf(stderr, "Sheet Data:\n"); + // 单元格 + xlsCell* cell = NULL; // 每行 - for (row = 0; row < pWS->rows.lastrow; ++row) { - cell = xls_cell(pWS, row, 1); + std::list<ExcelGPCodeInfo> codes; + for (row = 0; row <= pWS->rows.lastrow; ++row) { + ExcelGPCodeInfo info; + cell = xls_cell(pWS, row, 0); if (cell && cell->str) { fprintf(stderr, "%s", (char*)cell->str); + info.zyltgb = std::string((char*)cell->str); + } + cell = xls_cell(pWS, row, 1); + if (cell && cell->str) { + fprintf(stderr, " %s\n", (char*)cell->str); + info.code = std::string((char*)cell->str); + } + codes.push_back(info); } + + return codes; } -- Gitblit v1.8.0