From a04e8ad8377cbe1a7f57d68b7d13b7efb5f0492d Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Thu, 9 Aug 2018 12:52:15 +0200 Subject: [PATCH] open excel files with umlauts on win works now --- src/core/excelreader.cpp | 12 +++++++++--- src/gui/mainwindow.cpp | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/core/excelreader.cpp b/src/core/excelreader.cpp index 0cbf9b3..4453988 100644 --- a/src/core/excelreader.cpp +++ b/src/core/excelreader.cpp @@ -1,16 +1,22 @@ #include "excelreader.h" #include +#include void ExcelReader::readSellersFromFile(const std::filesystem::path& filePath, Marketplace* market) { + xlnt::workbook wb; + std::ifstream mystream(filePath, std::ios::binary); + if(!mystream.is_open()) { + throw std::runtime_error("Could not open ecxel file"); + } + wb.load(mystream); + for (auto& seller : market->getSellers()) { seller->setState(Seller::State::DELETE); } - market->storeToDb(true); - xlnt::workbook wb; - wb.load(filePath); + market->storeToDb(true); auto ws = wb.sheet_by_index(0); const int START_ROW = 5; diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 689beb2..abde041 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -378,7 +378,7 @@ void MainWindow::onImportSellerExcelActionTriggered() if (filename.isEmpty()) return; - std::filesystem::path filePath(filename.toStdU16String()); + std::filesystem::path filePath(filename.toStdWString()); ExcelReader::readSellersFromFile(filePath, marketplace_.get()); }