| | |
| | | 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; |
| | | } |
| | | |