#include "dl_file_xlsx.h" #include #include #include "io/dl_log.h" #include "io/dl_file.h" namespace dl::FileXlsx { /** * @brief 读取xlsx文件,拆解为每行 * @param[in] path_name 路径名称 * @retval 如果失败,会输出日志 * * @note 出于性能考虑不判断是否为utf8编码,而是使用其他函数提前转换 */ bool Read(std::string_view path_name, Vector2& ret) { assert(ret.IsEmpty()); using namespace OpenXLSX; g_log->PushLevel(LogSystem::Level::TEST); XLDocument doc; doc.open(std::string{ path_name }); XLWorkbook workbook = doc.workbook(); std::vector vec_sheet = workbook.worksheetNames(); for (auto& sheet_name : vec_sheet) { log("Sheet: " + sheet_name); XLWorksheet sheet = workbook.worksheet(sheet_name); uint16_t count_x = sheet.columnCount(); uint32_t count_y = sheet.rowCount(); ret.Resize(toSize(count_x, 0)); for (uint32_t y = 0; y < count_y; ++y) { std::vector line; line.resize(count_x); for (uint16_t x = 0; x < count_x; ++x) { line[x] = sheet.cell(y + 1, x + 1).value().get(); } ret.PushBack(line); } break; } g_log->Pop(); return true; } }