diff --git a/src/reports/ExcelFile.cpp b/src/reports/ExcelFile.cpp index 1e457ad..bc162a9 100644 --- a/src/reports/ExcelFile.cpp +++ b/src/reports/ExcelFile.cpp @@ -22,6 +22,27 @@ namespace platform { colorOdd = 0xDCE6F1; colorEven = 0xFDE9D9; } + lxw_worksheet* ExcelFile::createWorksheet(const std::string& name) + { + lxw_worksheet* sheet; + std::string suffix = ""; + std::string efectiveName; + int num = 1; + // Create a sheet with the name of the model + while (true) { + efectiveName = name + suffix; + if (workbook_get_worksheet_by_name(workbook, efectiveName.c_str())) { + suffix = std::to_string(++num); + } else { + sheet = workbook_add_worksheet(workbook, efectiveName.c_str()); + break; + } + if (num > 100) { + throw std::invalid_argument("Couldn't create sheet " + efectiveName); + } + } + return sheet; + } lxw_workbook* ExcelFile::getWorkbook() { diff --git a/src/reports/ExcelFile.h b/src/reports/ExcelFile.h index d7a77fc..a78b2e0 100644 --- a/src/reports/ExcelFile.h +++ b/src/reports/ExcelFile.h @@ -24,6 +24,7 @@ namespace platform { void boldBlue(); //set blue color for the bold styles void boldGreen(); //set green color for the bold styles void createStyle(const std::string& name, lxw_format* style, bool odd); + lxw_worksheet* createWorksheet(const std::string& name); void addColor(lxw_format* style, bool odd); lxw_format* efectiveStyle(const std::string& name); lxw_workbook* workbook; diff --git a/src/reports/ReportExcel.cpp b/src/reports/ReportExcel.cpp index 256bd11..01579bc 100644 --- a/src/reports/ReportExcel.cpp +++ b/src/reports/ReportExcel.cpp @@ -17,26 +17,7 @@ namespace platform { worksheet_set_column(worksheet, i, i, columns_sizes.at(i), NULL); } } - void ReportExcel::createWorksheet() - { - const std::string name = data["model"].get(); - std::string suffix = ""; - std::string efectiveName; - int num = 1; - // Create a sheet with the name of the model - while (true) { - efectiveName = name + suffix; - if (workbook_get_worksheet_by_name(workbook, efectiveName.c_str())) { - suffix = std::to_string(++num); - } else { - worksheet = workbook_add_worksheet(workbook, efectiveName.c_str()); - break; - } - if (num > 100) { - throw std::invalid_argument("Couldn't create sheet " + efectiveName); - } - } - } + void ReportExcel::createFile() { @@ -44,7 +25,8 @@ namespace platform { workbook = workbook_new((Paths::excel() + Paths::excelResults()).c_str()); } if (worksheet == NULL) { - createWorksheet(); + const std::string name = data["model"].get(); + worksheet = createWorksheet(name); } setProperties(data["title"].get()); formatColumns(); @@ -209,7 +191,8 @@ namespace platform { } void ReportExcel::create_classification_report(const json& result) { - auto matrix_sheet = workbook_add_worksheet(workbook, "classif_report"); + + auto matrix_sheet = createWorksheet("clf_report"); lxw_worksheet* tmp = worksheet; worksheet = matrix_sheet; if (matrix_sheet == NULL) { diff --git a/src/reports/ReportExcel.h b/src/reports/ReportExcel.h index 740ac69..88af143 100644 --- a/src/reports/ReportExcel.h +++ b/src/reports/ReportExcel.h @@ -15,7 +15,6 @@ namespace platform { private: void formatColumns(); void createFile(); - void createWorksheet(); void header() override; void body() override; void showSummary() override;