kima2/src/core/excelreader.cpp

43 lines
1.2 KiB
C++
Raw Normal View History

2018-08-01 15:36:41 +02:00
#include "excelreader.h"
#include <xlnt/xlnt.hpp>
void ExcelReader::readSellersFromFile(const std::string& filename, Marketplace* market)
{
2018-08-02 14:39:32 +02:00
for (auto& seller : market->getSellers()) {
seller->setState(Seller::State::DELETE);
}
market->storeToDb(true);
2018-08-01 15:36:41 +02:00
xlnt::workbook wb;
wb.load(filename);
auto ws = wb.sheet_by_index(0);
2018-08-02 11:15:15 +02:00
const int START_ROW = 5;
const int END_ROW = 350;
2018-08-01 15:36:41 +02:00
2018-08-01 15:55:13 +02:00
int rowCount{};
2018-08-01 15:36:41 +02:00
for (const auto& row : ws.rows(false)) {
2018-08-01 15:55:13 +02:00
// auto test = row[0].value<int>();
2018-08-02 11:15:15 +02:00
if (rowCount < START_ROW) {
2018-08-02 14:39:32 +02:00
++rowCount;
2018-08-01 15:55:13 +02:00
continue;
2018-08-02 11:15:15 +02:00
} else if (rowCount > END_ROW) {
break;
}
2018-08-02 14:39:32 +02:00
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));
2018-08-01 15:55:13 +02:00
rowCount++;
2018-08-01 15:36:41 +02:00
}
2018-08-02 14:39:32 +02:00
market->storeToDb();
2018-08-01 15:55:13 +02:00
}