kima2/src/core/excelreader.cpp

42 lines
1.2 KiB
C++

#include "excelreader.h"
#include <xlnt/xlnt.hpp>
void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace* market)
{
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
}
market->storeToDb(true);
xlnt::workbook wb;
wb.load(filename);
auto ws = wb.sheet_by_index(0);
const int START_ROW = 5;
const int END_ROW = 350;
int rowCount{};
for (const auto& row : ws.rows(false)) {
if (rowCount < START_ROW) {
++rowCount;
continue;
} else if (rowCount > END_ROW) {
break;
}
if (row[2].value<std::string>().empty() && row[3].value<std::string>().empty()) {
++rowCount;
continue;
}
auto seller = std::make_unique<Seller>();
seller->createUuid();
seller->setSellerNo(row[0].value<int>());
seller->setNumArticlesOffered(row[1].value<int>());
seller->setFirstName(row[2].value<std::string>());
seller->setLastName(row[3].value<std::string>());
market->getSellers().push_back(std::move(seller));
rowCount++;
}
market->storeToDb();
}