Skip to content

Commit

Permalink
some cleanup and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
shun2wang committed Sep 6, 2024
1 parent 334410c commit 4e6a79b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
18 changes: 8 additions & 10 deletions Desktop/data/importers/excel/excel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@

#include "excel.h"
#include "utilities/qutils.h"
#include "utils.h"

#include <QFileInfo>
#include <QDebug>

using namespace std;

Excel::Excel(const string &locator)
Excel::Excel(const std::string &locator)
{
_path = locator;
}
Expand All @@ -35,11 +32,12 @@ void Excel::open()
_fileSize = fi.size();

if (_fileSize < 0)
throw runtime_error("Could not access file");
throw std::runtime_error("Could not access file");

if (_fileSize == 0)
throw runtime_error("File is empty");
throw std::runtime_error("File is empty");
}

void Excel::openWorkbook()
{
QString xlsFilePath = tq(_path);
Expand All @@ -52,24 +50,24 @@ void Excel::openWorkbook()
else if (extension == "xlsx")
ret = freexl_open_xlsx(utf8Path, &_handle);
else
throw runtime_error("Unsupported file format: " + fq(extension));
throw std::runtime_error("Unsupported file format: " + fq(extension));

if(ret != FREEXL_OK)
throw runtime_error("Unexpected error while loading excel file, error code: " + std::to_string(ret));
throw std::runtime_error("Unexpected error while loading excel file, error code: " + std::to_string(ret));
}

void Excel::selectActiveWorksheet()
{
int ret = freexl_select_active_worksheet(_handle, 0); // import the first worksheet(index=0) by default.
if (ret != FREEXL_OK)
throw runtime_error("Could not select active worksheet,\n error code: " + std::to_string(ret));
throw std::runtime_error("Could not select active worksheet,\n error code: " + std::to_string(ret));
}

void Excel::getWorksheetDimensions(uint32_t &rows, uint16_t &cols) {
int ret = freexl_worksheet_dimensions(_handle, &rows, &cols);

if (ret != FREEXL_OK)
throw runtime_error("Could not read worksheet dimensions, error code: " + std::to_string(ret));
throw std::runtime_error("Could not read worksheet dimensions, error code: " + std::to_string(ret));

_numCols = cols; //get cols count while read sheet
}
Expand Down
1 change: 0 additions & 1 deletion Desktop/data/importers/excel/excel.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#ifndef EXCEL_H
#define EXCEL_H

#include <vector>
#include <string>
#include <stdint.h>

Expand Down
8 changes: 3 additions & 5 deletions Desktop/data/importers/excelimporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ ImportDataSet* ExcelImporter::loadFile(const std::string &locator, std::function
std::string colName = colNames[i];
if (colName.empty())
colName = "V" + std::to_string(i + 1);
else if(ColumnUtils::isIntValue(colName))
else if(ColumnUtils::isIntValue(colName) || ColumnUtils::isDoubleValue(colName))
colName = "V" + colName;
//What is the purpose of the `find` here? Maybe explain in a comment here
if (std::find(colNames.begin(), colNames.begin() + i, colName) != colNames.begin() + i)
// distinguish duplicate column names
if(std::find(colNames.begin(), colNames.begin() + i, colName) != colNames.begin() + i)
colName += "_" + std::to_string(i + 1);

colNames[i] = colName;
Expand All @@ -95,9 +95,7 @@ ImportDataSet* ExcelImporter::loadFile(const std::string &locator, std::function
}

for (ExcelImportColumn* col : importColumns)
{
data->addColumn(col);
}

data->buildDictionary();
excel.close();
Expand Down

0 comments on commit 4e6a79b

Please sign in to comment.