Improve the documentation of the examples

This commit is contained in:
Debao Zhang
2013-10-19 15:00:54 +08:00
parent f8ca19f14b
commit 81abb19c8c
7 changed files with 42 additions and 29 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

+11 -2
View File
@@ -1,11 +1,20 @@
/*!
\title Qt Xlsx Examples - Hello World
\example hello
\title Xlsx Hello Example
\brief This is a simplest xlsx examples.
\ingroup qtxlsx
This example demonstrates how to generate a
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
View File
@@ -3,4 +3,7 @@ TARGET = hello
#include(../../../src/xlsx/qtxlsx.pri)
QT+=xlsx
CONFIG += console
CONFIG -= app_bundle
SOURCES += main.cpp
+11 -26
View File
@@ -1,38 +1,23 @@
#include <QtCore>
#include "xlsxdocument.h"
#ifdef Q_OS_MAC
# define DATA_PATH "../../../"
#else
# define DATA_PATH "./"
#endif
int main()
{
//![0]
QXlsx::Document xlsx;
//![0]
//Write to first worksheet.
//![1]
xlsx.write("A1", "Hello Qt!");
xlsx.write("B3", 12345);
xlsx.write("C5", "=44+33");
xlsx.write("D7", true);
xlsx.write("E1", "http://qt-project.org");
xlsx.write("A2", 12345);
xlsx.write("A3", "=44+33");
xlsx.write("A4", true);
xlsx.write("A5", "http://qt-project.org");
//![1]
//Create another worksheet.
xlsx.addWorksheet();
//Rows and columns are zero indexed.
//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)");
//![2]
xlsx.save();
//![2]
xlsx.saveAs(DATA_PATH"Test.xlsx");
return 0;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

@@ -2,9 +2,17 @@
\title Xlsx Readwrite Example
\example readwrite
\brief Open an existing xlsx file, modify and save it.
\ingroup qtxlsx
This example demonstrates how to modify an existing
.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
View File
@@ -3,17 +3,25 @@
int main()
{
//Generate a simple xlsx file at first.
//![0]
QXlsx::Document xlsx;
xlsx.setDocumentProperty("title", "This is an example spreadsheet");
xlsx.setDocumentProperty("creator", "Qt Xlsx Library");
xlsx.setSheetName("First Sheet");
xlsx.write("A1", "Hello Qt!");
xlsx.write("A2", 500);
xlsx.saveAs("first.xlsx");
//![0]
//Read, edit, save
//![1]
QXlsx::Document xlsx2("first.xlsx");
xlsx2.write("A3", "Hello Qt again!");
xlsx2.addWorksheet("Second Sheet");
xlsx2.write("A1", "Hello Qt again!");
xlsx2.setCurrentWorksheet(0);
xlsx2.saveAs("second.xlsx");
//![1]
return 0;
}