1
0
mirror of https://github.com/QtExcel/QXlsx.git synced 2025-01-30 05:02:52 +08:00

testing copycat

This commit is contained in:
Jay Two 2018-09-27 17:41:21 +09:00
parent ed8dce1114
commit 4373eb0ba1
8 changed files with 326 additions and 0 deletions

54
Copycat/Copycat.pro Normal file
View File

@ -0,0 +1,54 @@
#-------------------------------------------------
#
# Copycat.pro
#
#-------------------------------------------------
# QXlsx
# MIT License
# https://github.com/j2doll/QXlsx
#-------------------------------------------------
# QtXlsx
# https://github.com/dbzhang800/QtXlsxWriter
# http://qtxlsx.debao.me/
# MIT License
#-------------------------------------------------
TARGET = Copycat
TEMPLATE = app
QT += core
QT += gui
QT += widgets
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
# The following define makes your compiler emit warnings if you use
# any feature of Qt which has been marked as deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if you use deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
# NOTE: You can fix value of QXlsx path of source code.
# QXLSX_PARENTPATH=./
# QXLSX_HEADERPATH=./header/
# QXLSX_SOURCEPATH=./source/
include(../QXlsx/QXlsx.pri)
HEADERS += \
MainWindow.h \
XlsxTab.h \
xlsx.h
SOURCES += \
main.cpp \
MainWindow.cpp \
XlsxTab.cpp
FORMS += \
MainWindow.ui

85
Copycat/MainWindow.cpp Normal file
View File

@ -0,0 +1,85 @@
#include <QtGlobal>
#include <QString>
#include <QFileDialog>
#include <QMessageBox>
#include "MainWindow.h"
#include "ui_MainWindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
xlsxDoc = NULL;
tabWidget = NULL;
ui->setupUi(this);
tabWidget = new QTabWidget(this);
}
MainWindow::~MainWindow()
{
// tabWidget->close();
delete ui;
if ( NULL != xlsxDoc )
{
delete xlsxDoc;
}
}
void MainWindow::on_action_Quit_triggered()
{
this->close();
}
void MainWindow::on_action_Open_triggered()
{
// open dialog
QString fileName = QFileDialog::getOpenFileName(this,
tr("Open Excel"), ".", tr("Excel Files (*.xlsx)"));
// tried to load xlsx
QXlsx::Document xlsxTmp(fileName);
if (!xlsxTmp.isLoadPackage())
{
QMessageBox msgBox;
QString alertMsg = QString("Failed to load file.\n %1").arg(fileName);
msgBox.setText(alertMsg);
msgBox.exec();
return;
}
xlsxTmp.deleteLater();
// clear xlsxDoc
if ( NULL != xlsxDoc )
{
delete xlsxDoc;
xlsxDoc = NULL;
}
// load new xlsx
xlsxDoc = new QXlsx::Document(fileName);
xlsxDoc->isLoadPackage();
//for ( int ic = 0 ; ic < tabWidget->count() ; ic++ ) {
// tabWidget->removeTab( ic );
//}
// quint32 sheetCount = xlsxDoc->sheetNames().count();
foreach( QString curretnSheetName, xlsxDoc->sheetNames() ) {
QXlsx::AbstractSheet* currentSheet = xlsxDoc->sheet( curretnSheetName );
//
// new XlsxTab( this, currentSheet )
}
}

34
Copycat/MainWindow.h Normal file
View File

@ -0,0 +1,34 @@
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGlobal>
#include <QMainWindow>
#include <QTabWidget>
#include "xlsx.h"
#include "XlsxTab.h"
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_action_Quit_triggered();
void on_action_Open_triggered();
private:
Ui::MainWindow *ui;
QXlsx::Document* xlsxDoc;
QTabWidget *tabWidget;
};
#endif // MAINWINDOW_H

71
Copycat/MainWindow.ui Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menu_File">
<property name="title">
<string>&amp;File</string>
</property>
<addaction name="action_New"/>
<addaction name="action_Open"/>
<addaction name="action_Save"/>
<addaction name="separator"/>
<addaction name="action_Quit"/>
</widget>
<addaction name="menu_File"/>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="action_New">
<property name="text">
<string>&amp;New</string>
</property>
</action>
<action name="action_Open">
<property name="text">
<string>&amp;Open</string>
</property>
</action>
<action name="action_Save">
<property name="text">
<string>&amp;Save</string>
</property>
</action>
<action name="action_Quit">
<property name="text">
<string>&amp;Quit</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>

24
Copycat/XlsxTab.cpp Normal file
View File

@ -0,0 +1,24 @@
// XlsxTab.cpp
#include "XlsxTab.h"
XlsxTab::XlsxTab(QWidget* parent, QXlsx::AbstractSheet* ptrSheet)
: QWidget(parent)
{
table = NULL;
if ( NULL != ptrSheet ) {
// set sheet data
}
}
XlsxTab::~XlsxTab()
{
if ( NULL != table )
{
table->deleteLater();
}
}

28
Copycat/XlsxTab.h Normal file
View File

@ -0,0 +1,28 @@
// XlsxTab.h
#ifndef XLSXTAB_H
#define XLSXTAB_H
#include <QtGlobal>
#include <QWidget>
#include <QTableWidget>
#include "xlsx.h"
class XlsxTab : public QWidget
{
Q_OBJECT
public:
explicit XlsxTab(QWidget* parent = nullptr, QXlsx::AbstractSheet* ptrSheet = nullptr);
virtual ~XlsxTab();
signals:
public slots:
protected:
QTableWidget* table;
};
#endif // XLSXTAB_H

16
Copycat/main.cpp Normal file
View File

@ -0,0 +1,16 @@
// main.cpp
#include <QtGlobal>
#include "MainWindow.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}

14
Copycat/xlsx.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef XLSX_H
#define XLSX_H
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
#include "xlsxcellrange.h"
#include "xlsxchart.h"
#include "xlsxrichstring.h"
#include "xlsxworkbook.h"
#include "xlsxabstractsheet.h"
using namespace QXlsx;
#endif // XLSX_H