mirror of
https://github.com/QtExcel/QXlsx.git
synced 2025-01-16 04:42:53 +08:00
update copycat example
This commit is contained in:
parent
85e5bde6d8
commit
edf7078713
@ -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<br />"
|
||||
"<a href=\"https://github.com/j2doll/QXlsx\">https://github.com/j2doll/QXlsx</a><br />"
|
||||
"MIT License<br />" );
|
||||
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();
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -6,8 +6,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
<width>480</width>
|
||||
<height>320</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -19,7 +19,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<width>480</width>
|
||||
<height>21</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
@ -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<CellLocation> clList = wsheet->getFullCells();
|
||||
for (int ic = 0; ic < clList.size(); ++ic) {
|
||||
QVector<CellLocation> 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;
|
||||
}
|
||||
|
@ -12,5 +12,6 @@ int main(int argc, char *argv[])
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
return a.exec();
|
||||
int ret = a.exec();
|
||||
return ret;
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ public:
|
||||
|
||||
~Worksheet();
|
||||
|
||||
QVector<CellLocation> getFullCells();
|
||||
QVector<CellLocation> getFullCells(int* maxRow, int* maxCol);
|
||||
|
||||
private:
|
||||
|
||||
|
@ -2373,10 +2373,12 @@ SharedStrings *WorksheetPrivate::sharedStrings() const
|
||||
return workbook->sharedStrings();
|
||||
}
|
||||
|
||||
QVector<CellLocation> Worksheet::getFullCells()
|
||||
QVector<CellLocation> Worksheet::getFullCells(int* maxRow, int* maxCol)
|
||||
{
|
||||
Q_D(const Worksheet);
|
||||
|
||||
(*maxRow) = -1;
|
||||
(*maxCol) = -1;
|
||||
QVector<CellLocation> ret;
|
||||
|
||||
QMapIterator<int, QMap<int, QSharedPointer<Cell> > > _it(d->cellTable);
|
||||
@ -2394,8 +2396,15 @@ QVector<CellLocation> Worksheet::getFullCells()
|
||||
QSharedPointer<Cell> 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 );
|
||||
|
@ -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)
|
||||
|
||||
|
11
README.md
11
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)
|
||||
|
||||
|
BIN
markdown.data/copycat.png
Normal file
BIN
markdown.data/copycat.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
Loading…
x
Reference in New Issue
Block a user