Browse Source

Improve the documentation of the examples

master
Debao Zhang 12 years ago
parent
commit
81abb19c8c
  1. BIN
      examples/xlsx/hello/doc/images/hello.png
  2. 13
      examples/xlsx/hello/doc/src/hello.qdoc
  3. 3
      examples/xlsx/hello/hello.pro
  4. 37
      examples/xlsx/hello/main.cpp
  5. BIN
      examples/xlsx/readwrite/doc/images/readwrite.png
  6. 10
      examples/xlsx/readwrite/doc/src/readwrite.qdoc
  7. 8
      examples/xlsx/readwrite/main.cpp

BIN
examples/xlsx/hello/doc/images/hello.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

13
examples/xlsx/hello/doc/src/hello.qdoc

@ -1,11 +1,20 @@
/*! /*!
\title Qt Xlsx Examples - Hello World
\example hello \example hello
\title Xlsx Hello Example \title Xlsx Hello Example
\brief This is a simplest xlsx examples. \brief This is a simplest xlsx examples.
\ingroup qtxlsx \ingroup qtxlsx
This example demonstrates how to generate a This example demonstrates how to generate a
simplest .xlsx file with Qt Xlsx Library. simplest .xlsx file with Qt Xlsx Library.
\image hello.png
Create an object of the class QXlsx::Document.
\snippet hello/main.cpp 0
Set the cells of worksheet.
\snippet hello/main.cpp 1
Save it.
\snippet hello/main.cpp 2
*/ */

3
examples/xlsx/hello/hello.pro

@ -3,4 +3,7 @@ TARGET = hello
#include(../../../src/xlsx/qtxlsx.pri) #include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp SOURCES += main.cpp

37
examples/xlsx/hello/main.cpp

@ -1,38 +1,23 @@
#include <QtCore> #include <QtCore>
#include "xlsxdocument.h" #include "xlsxdocument.h"
#ifdef Q_OS_MAC
# define DATA_PATH "../../../"
#else
# define DATA_PATH "./"
#endif
int main() int main()
{ {
//![0]
QXlsx::Document xlsx; QXlsx::Document xlsx;
//![0]
//Write to first worksheet. //![1]
xlsx.write("A1", "Hello Qt!"); xlsx.write("A1", "Hello Qt!");
xlsx.write("B3", 12345); xlsx.write("A2", 12345);
xlsx.write("C5", "=44+33"); xlsx.write("A3", "=44+33");
xlsx.write("D7", true); xlsx.write("A4", true);
xlsx.write("E1", "http://qt-project.org"); xlsx.write("A5", "http://qt-project.org");
//![1]
//Create another worksheet. //![2]
xlsx.addWorksheet(); xlsx.save();
//Rows and columns are zero indexed. //![2]
//The first cell in a worksheet, "A1", is (0, 0).
xlsx.write(0, 0, "First");
xlsx.write(1, 0, "Second");
xlsx.write(2, 0, "Third");
xlsx.write(3, 0, "Fourth");
xlsx.write(4, 0, "Total");
xlsx.write(0, 1, 100);
xlsx.write(1, 1, 200);
xlsx.write(2, 1, 300);
xlsx.write(3, 1, 400);
// xlsx.write(4, 1, "=SUM(B1:B4)");
xlsx.saveAs(DATA_PATH"Test.xlsx");
return 0; return 0;
} }

BIN
examples/xlsx/readwrite/doc/images/readwrite.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

10
examples/xlsx/readwrite/doc/src/readwrite.qdoc

@ -2,9 +2,17 @@
\title Xlsx Readwrite Example \title Xlsx Readwrite Example
\example readwrite \example readwrite
\brief Open an existing xlsx file, modify and save it. \brief Open an existing xlsx file, modify and save it.
\ingroup qtxlsx \ingroup qtxlsx
This example demonstrates how to modify an existing This example demonstrates how to modify an existing
.xlsx file with Qt Xlsx Library. .xlsx file with Qt Xlsx Library.
\image readwrite.png
At first, we create an empty xlsx file, set the properties of the document,
write some content to the worksheet, then save it.
\snippet readwrite/main.cpp 0
Then we open the exists xlsx file, add some data to it.
\snippet readwrite/main.cpp 1
*/ */

8
examples/xlsx/readwrite/main.cpp

@ -3,17 +3,25 @@
int main() int main()
{ {
//Generate a simple xlsx file at first. //Generate a simple xlsx file at first.
//![0]
QXlsx::Document xlsx; QXlsx::Document xlsx;
xlsx.setDocumentProperty("title", "This is an example spreadsheet");
xlsx.setDocumentProperty("creator", "Qt Xlsx Library");
xlsx.setSheetName("First Sheet"); xlsx.setSheetName("First Sheet");
xlsx.write("A1", "Hello Qt!"); xlsx.write("A1", "Hello Qt!");
xlsx.write("A2", 500); xlsx.write("A2", 500);
xlsx.saveAs("first.xlsx"); xlsx.saveAs("first.xlsx");
//![0]
//Read, edit, save //Read, edit, save
//![1]
QXlsx::Document xlsx2("first.xlsx"); QXlsx::Document xlsx2("first.xlsx");
xlsx2.write("A3", "Hello Qt again!");
xlsx2.addWorksheet("Second Sheet"); xlsx2.addWorksheet("Second Sheet");
xlsx2.write("A1", "Hello Qt again!"); xlsx2.write("A1", "Hello Qt again!");
xlsx2.setCurrentWorksheet(0);
xlsx2.saveAs("second.xlsx"); xlsx2.saveAs("second.xlsx");
//![1]
return 0; return 0;
} }

Loading…
Cancel
Save