Browse Source

Use save() function to save the package instead of close

master
Debao Zhang 11 years ago
parent
commit
98611399fd
  1. 13
      examples/hello/main.cpp
  2. 3
      src/xlsxpackage.cpp
  3. 2
      src/xlsxpackage_p.h
  4. 25
      src/xlsxworkbook.cpp
  5. 9
      src/xlsxworkbook.h

13
examples/hello/main.cpp

@ -2,15 +2,18 @@
#include "xlsxworkbook.h"
#include "xlsxworksheet.h"
int main(int argc, char* argv[])
{
#ifdef Q_OS_MAC
QXlsx::Workbook workbook("../../../Test.xlsx");
# define DATA_PATH "../../../"
#else
QXlsx::Workbook workbook("Test.xlsx");
# define DATA_PATH "./"
#endif
int main()
{
QXlsx::Workbook workbook;
QXlsx::Worksheet *sheet = workbook.addWorksheet();
sheet->write("A1", "Hello Qt!");
workbook.close();
workbook.save(DATA_PATH"Test.xlsx");
workbook.save(DATA_PATH"Test.zip");
return 0;
}

3
src/xlsxpackage.cpp

@ -87,8 +87,7 @@ Package::Package(Workbook *workbook) :
bool Package::createPackage(const QString &packageName)
{
QString fileName = packageName.isEmpty() ? m_workbook->fileName() : packageName;
ZipWriter zipWriter(fileName);
ZipWriter zipWriter(packageName);
writeWorksheetFiles(zipWriter);
// writeChartsheetFiles(zipWriter);

2
src/xlsxpackage_p.h

@ -37,7 +37,7 @@ class Package
public:
Package(Workbook *workbook);
bool createPackage(const QString &packageName=QString());
bool createPackage(const QString &packageName);
private:
void writeWorksheetFiles(ZipWriter &zipWriter);

25
src/xlsxworkbook.cpp

@ -32,8 +32,8 @@
namespace QXlsx {
Workbook::Workbook(const QString &name, QObject *parent) :
QObject(parent), m_fileName(name)
Workbook::Workbook(QObject *parent) :
QObject(parent)
{
m_sharedStrings = new SharedStrings(this);
m_styles = new Styles(this);
@ -49,24 +49,13 @@ Workbook::Workbook(const QString &name, QObject *parent) :
m_activesheet = 0;
m_firstsheet = 0;
m_table_count = 0;
m_closed = false;
}
Workbook::~Workbook()
{
close();
}
void Workbook::close()
{
if (m_closed)
return;
m_closed = true;
saveWorkbook();
}
void Workbook::saveWorkbook()
void Workbook::save(const QString &name)
{
//Add a default worksheet if non have been added.
if (m_worksheets.size() == 0)
@ -84,15 +73,9 @@ void Workbook::saveWorkbook()
sheet->setActived(true);
}
//Create the package based on current workbook
Package package(this);
package.createPackage();
}
QString Workbook::fileName() const
{
return m_fileName;
package.createPackage(name);
}
/*!

9
src/xlsxworkbook.h

@ -41,7 +41,7 @@ class Workbook : public QObject
{
Q_OBJECT
public:
Workbook(const QString &name, QObject *parent=0);
Workbook(QObject *parent=0);
~Workbook();
Worksheet *addWorksheet(const QString &name = QString());
@ -51,7 +51,7 @@ public:
void setOptimizationEnabled(bool enable=true);
void setStringsToNumbersEnabled(bool enable=true);
void close();
void save(const QString &name);
private:
friend class Package;
@ -60,14 +60,9 @@ private:
QList<Worksheet *> worksheets() const;
SharedStrings *sharedStrings();
Styles *styles();
QString fileName() const;
bool isOptimizationEnabled() const;
bool isStringsToNumbersEnabled() const;
void saveToXmlFile(QIODevice *device);
void saveWorkbook();
QString m_fileName;
bool m_closed;
SharedStrings *m_sharedStrings;
QList<Worksheet *> m_worksheets;

Loading…
Cancel
Save