diff --git a/Copycat/MainWindow.cpp b/Copycat/MainWindow.cpp index 0a99503..dfcc213 100644 --- a/Copycat/MainWindow.cpp +++ b/Copycat/MainWindow.cpp @@ -20,23 +20,22 @@ MainWindow::MainWindow(QWidget *parent) : tabWidget = new QTabWidget(this); setCentralWidget(tabWidget); + this->setWindowTitle(QString("Copycat")); } MainWindow::~MainWindow() { - // tabWidget->close(); - delete ui; if ( NULL != xlsxDoc ) { delete xlsxDoc; } - } void MainWindow::on_action_Quit_triggered() { + // quit this->close(); } @@ -65,7 +64,7 @@ bool MainWindow::loadXlsx(QString fileName) QXlsx::Document xlsxTmp(fileName); if (!xlsxTmp.isLoadPackage()) { - return false; + return false; // failed to load } // clear xlsxDoc @@ -84,13 +83,10 @@ bool MainWindow::loadXlsx(QString fileName) // Removes all the pages, but does not delete them. // Calling this function is equivalent to calling removeTab() // until the tab widget is empty. - // - // for ( int ic = 0 ; ic < tabWidget->count() ; ic++ ) { - // tabWidget->removeTab( ic ); - // } // clear sub-items of every tab - foreach ( XlsxTab* ptrTab, xlsxTabList ) { + foreach ( XlsxTab* ptrTab, xlsxTabList ) + { if ( NULL == ptrTab ) continue; delete ptrTab; @@ -118,6 +114,23 @@ bool MainWindow::loadXlsx(QString fileName) void MainWindow::on_action_About_triggered() { QMessageBox msgBox; - msgBox.setText(QString("Copycat\nhttps://github.com/j2doll/QXlsx")); + msgBox.setText( "QXlsx
" + "https://github.com/j2doll/QXlsx
" + "MIT License
" ); msgBox.exec(); } + +void MainWindow::on_action_New_triggered() +{ + QMessageBox msgBox; + msgBox.setText( "New" ); + msgBox.exec(); +} + +void MainWindow::on_action_Save_triggered() +{ + QMessageBox msgBox; + msgBox.setText( "Save" ); + msgBox.exec(); +} + diff --git a/Copycat/MainWindow.h b/Copycat/MainWindow.h index 34a11da..696c05c 100644 --- a/Copycat/MainWindow.h +++ b/Copycat/MainWindow.h @@ -31,6 +31,10 @@ private slots: void on_action_About_triggered(); + void on_action_New_triggered(); + + void on_action_Save_triggered(); + private: Ui::MainWindow *ui; QXlsx::Document* xlsxDoc; diff --git a/Copycat/MainWindow.ui b/Copycat/MainWindow.ui index ec710c4..f746eb4 100644 --- a/Copycat/MainWindow.ui +++ b/Copycat/MainWindow.ui @@ -6,8 +6,8 @@ 0 0 - 400 - 300 + 480 + 320 @@ -19,7 +19,7 @@ 0 0 - 400 + 480 21 diff --git a/Copycat/XlsxTab.cpp b/Copycat/XlsxTab.cpp index 2529cc1..7b9a70f 100644 --- a/Copycat/XlsxTab.cpp +++ b/Copycat/XlsxTab.cpp @@ -27,7 +27,10 @@ XlsxTab::XlsxTab(QWidget* parent, sheet = ptrSheet; // set sheet data sheetIndex = SheetIndex; // set shett index - setSheet(); + if ( ! setSheet() ) + { + + } } } @@ -48,40 +51,36 @@ bool XlsxTab::setSheet() if ( NULL == table ) return false; + // set active sheet sheet->workbook()->setActiveSheet( sheetIndex ); Worksheet* wsheet = (Worksheet*) sheet->workbook()->activeSheet(); if ( NULL == wsheet ) return false; - qDebug() << wsheet->sheetName() << "----------"; - - // TODO: get max row count and column count of sheet - table->setRowCount(100); - table->setColumnCount(100); - + // get full cells of sheet int maxRow = -1; int maxCol = -1; - QVector clList = wsheet->getFullCells(); - for (int ic = 0; ic < clList.size(); ++ic) { + QVector clList = wsheet->getFullCells( &maxRow, &maxCol ); + + // set max count of row,col + table->setRowCount( maxRow ); + table->setColumnCount( maxCol ); + + for ( int ic = 0; ic < clList.size(); ++ic ) + { CellLocation cl = clList.at(ic); + // First cell of tableWidget is 0. + // But first cell of Qxlsx document is 1. int row = cl.row - 1; - if ( row > maxRow ) maxRow = row; - int col = cl.col - 1; - if ( col > maxCol ) maxCol = col; QVariant var = cl.cell.data()->value(); QString str = var.toString(); - qDebug() << " row:" << row << " col:" << col << " val:"<< str; - QTableWidgetItem *newItem = new QTableWidgetItem(str); table->setItem(row, col, newItem); } - table->setRowCount(maxRow + 1); - table->setColumnCount(maxCol + 1); - return true; } diff --git a/Copycat/main.cpp b/Copycat/main.cpp index 00fbfc1..00bdc55 100644 --- a/Copycat/main.cpp +++ b/Copycat/main.cpp @@ -12,5 +12,6 @@ int main(int argc, char *argv[]) MainWindow w; w.show(); - return a.exec(); + int ret = a.exec(); + return ret; } diff --git a/QXlsx/header/xlsxworksheet.h b/QXlsx/header/xlsxworksheet.h index 697f61d..4148ee1 100644 --- a/QXlsx/header/xlsxworksheet.h +++ b/QXlsx/header/xlsxworksheet.h @@ -138,7 +138,7 @@ public: ~Worksheet(); - QVector getFullCells(); + QVector getFullCells(int* maxRow, int* maxCol); private: diff --git a/QXlsx/source/xlsxworksheet.cpp b/QXlsx/source/xlsxworksheet.cpp index 509745a..f27904e 100644 --- a/QXlsx/source/xlsxworksheet.cpp +++ b/QXlsx/source/xlsxworksheet.cpp @@ -2373,10 +2373,12 @@ SharedStrings *WorksheetPrivate::sharedStrings() const return workbook->sharedStrings(); } -QVector Worksheet::getFullCells() +QVector Worksheet::getFullCells(int* maxRow, int* maxCol) { Q_D(const Worksheet); + (*maxRow) = -1; + (*maxCol) = -1; QVector ret; QMapIterator > > _it(d->cellTable); @@ -2394,8 +2396,15 @@ QVector Worksheet::getFullCells() QSharedPointer ptrCell = _iit.value(); // value CellLocation cl; + cl.row = keyI; + if ( keyI > (*maxRow) ) + (*maxRow) = keyI; + cl.col = keyII; + if ( keyII > (*maxCol) ) + (*maxCol) = keyII; + cl.cell = ptrCell; ret.push_back( cl ); diff --git a/README.ko.md b/README.ko.md index 3508005..58e2a93 100644 --- a/README.ko.md +++ b/README.ko.md @@ -14,9 +14,10 @@ ## 활용하는 방법 - 예제를 보세요. - TestExcel : 기본 예제 (QtXlsx 예제 기반) - - HelloAndroid : 안드로이드에서 xlsx 파일 열기 + - HelloAndroid : QML을 사용한 안드로이드에서 xlsx 파일 열기 + ![](markdown.data/android.jpg) - Copycat : xlsx 파일을 읽어 위젯으로 표시 (할일: xlsx 파일로 저장) - - SpreadsheetExample : 간단한 예제 + ![](markdown.data/copycat.png) ## 활용 예제 (Hello excel) diff --git a/README.md b/README.md index 3f4f446..9caf071 100644 --- a/README.md +++ b/README.md @@ -12,13 +12,14 @@ - You don't need to use static library or dynamic shared object using QXlsx. ## How to use -- See samples +- See examples - TestExcel : basic samples based on QtXlsx samples - - HelloAndroid : read xlsx on Android + - HelloAndroid : read xlsx on Android using QML + ![](markdown.data/android.jpg) - Copycat : load xlsx file and display on widget (TODO: save xlsx) - - SpreadsheetExample : simple sample - -## Sample (Hello excel) + ![](markdown.data/copycat.png) + +## Example (Hello excel) ### :one: Writing excel file(*.xlsx) diff --git a/markdown.data/copycat.png b/markdown.data/copycat.png new file mode 100644 index 0000000..fea79ea Binary files /dev/null and b/markdown.data/copycat.png differ