// main.cpp #include "recurse.hpp" #include "xlsxabstractsheet.h" #include "xlsxcell.h" #include "xlsxcelllocation.h" #include "xlsxcellrange.h" #include "xlsxchart.h" #include "xlsxchartsheet.h" #include "xlsxdocument.h" #include "xlsxrichstring.h" #include "xlsxworkbook.h" #include #include #include #include #include using namespace QXlsx; QString getHtml(QString strFilename); bool loadXlsx(QString fileName, QString &strHtml); QString g_htmlDoc; int main(int argc, char *argv[]) { g_htmlDoc = getHtml(":/test.xlsx"); // convert from xlsx to html Recurse::Application app(argc, argv); app.use([](auto &ctx) { ctx.response.send(g_htmlDoc); }); quint16 listenPort = 3001; // default port auto result = app.listen(listenPort); if (result.error()) { qDebug() << "error upon listening:" << result.lastError(); return (-1); } std::cout << " listening port: " << listenPort << std::endl; return 0; } QString getHtml(QString strFilename) { QString ret; ret = ret + QString("\n"); ret = ret + QString("\n"); ret = ret + QString("") + strFilename + QString("\n"); ret = ret + QString("\n"); ret = ret + QString("\n"); ret = ret + QString("\n"); QString strTableStyle = "\n"; ret = ret + strTableStyle; if (!loadXlsx(strFilename, ret)) return QString(""); ret = ret + QString("\n"); ret = ret + QString("\n"); qDebug() << ret << "\n"; return ret; } bool loadXlsx(QString fileName, QString &strHtml) { // tried to load xlsx using temporary document QXlsx::Document xlsxTmp(fileName); if (!xlsxTmp.isLoadPackage()) { return false; // failed to load } // load new xlsx using new document QXlsx::Document xlsxDoc(fileName); xlsxDoc.isLoadPackage(); int sheetIndexNumber = 0; foreach (QString curretnSheetName, xlsxDoc.sheetNames()) { QXlsx::AbstractSheet *currentSheet = xlsxDoc.sheet(curretnSheetName); if (NULL == currentSheet) continue; // get full cells of sheet int maxRow = -1; int maxCol = -1; currentSheet->workbook()->setActiveSheet(sheetIndexNumber); Worksheet *wsheet = (Worksheet *) currentSheet->workbook()->activeSheet(); if (NULL == wsheet) continue; QString strSheetName = wsheet->sheetName(); // sheet name strHtml = strHtml + QString("") + strSheetName + QString("
\n"); // UTF-8 strHtml = strHtml + QString(""); QVector clList = wsheet->getFullCells(&maxRow, &maxCol); QVector> cellValues; for (int rc = 0; rc < maxRow; rc++) { QVector tempValue; for (int cc = 0; cc < maxCol; cc++) { tempValue.push_back(QString("")); } cellValues.push_back(tempValue); } for (int ic = 0; ic < clList.size(); ++ic) { // cell location CellLocation cl = clList.at(ic); int row = cl.row - 1; int col = cl.col - 1; // Update ShowConsole example for 9ab612f // {{ // QSharedPointer ptrCell = cl.cell; // cell pointer std::shared_ptr ptrCell = cl.cell; // cell pointer // value of cell // QVariant var = cl.cell.data()->value(); QVariant var = ptrCell->value(); // }} QString str = var.toString(); cellValues[row][col] = str; } QString strTableRecord; for (int rc = 0; rc < maxRow; rc++) { strTableRecord = strTableRecord + QString(""); for (int cc = 0; cc < maxCol; cc++) { QString strTemp = cellValues[rc][cc]; strTableRecord = strTableRecord + QString(""); } strTableRecord = strTableRecord + QString("\n"); } strHtml = strHtml + strTableRecord; strHtml = strHtml + QString("
"); strTableRecord = strTableRecord + strTemp; // UTF-8 strTableRecord = strTableRecord + QString("
\n"); sheetIndexNumber++; } return true; }