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

setting chart title

This commit is contained in:
Jay Two 2018-12-27 12:05:23 +09:00
parent d961dc8556
commit b4ba663b17
7 changed files with 99 additions and 59 deletions

View File

@ -1,11 +1,21 @@
# QXlsx Examples
## HelloWorld
- Hello world example
```cpp
// main.cpp
#include <QtGlobal>
#include <QCoreApplication>
#include <QtCore>
#include <QVariant>
#include <QDebug>
#include <iostream>
using namespace std;
// [0] include QXlsx headers
#include "xlsxdocument.h"
#include "xlsxchartsheet.h"
@ -42,23 +52,27 @@ int main(int argc, char *argv[])
```
## TestExcel
- :zap: Basic examples based on QtXlsx examples
## HelloAndroid : Android Example
- See 'HelloAndroid' example using QML and native C++.
- Qt 5.11.1 / QtCreator 4.6.2 / gcc 4.9 / Android x86 (using Emulator [Android Oreo]) / Android Studio 3.1.3 (Android NDK 17.1)
![](markdown.data/android.jpg)
## Copycat : Windows Widget Example
- Load xlsx file and display on Qt widgets.
- Print xlsx to papaer. (TODO: save xlsx)
- Print xlsx to papaer.
- TODO: save xlsx.
![](markdown.data/copycat.png)
## WebServer : WebServer Example
- Load xlsx file and display on Web.
- C++ 14 is required.
- Connect to `http://127.0.0.1:3001`
- C++ 14 is required. Old compilers is not supported.
![](markdown.data/webserver.png)

View File

@ -81,6 +81,7 @@ public:
void setChartType(ChartType type);
void setChartStyle(int id);
void setAxisTitle(Chart::ChartAxisPos pos, QString axisTitle);
void setChartTitle(QString strchartTitle);
void saveToXmlFile(QIODevice *device) const;
bool loadFromXmlFile(QIODevice *device);

View File

@ -118,6 +118,7 @@ public:
bool loadXmlAxis(QXmlStreamReader &reader);
void saveXmlChart(QXmlStreamWriter &writer) const;
void saveXmlChartTitle(QXmlStreamWriter &writer) const;
void saveXmlPieChart(QXmlStreamWriter &writer) const;
void saveXmlBarChart(QXmlStreamWriter &writer) const;
void saveXmlLineChart(QXmlStreamWriter &writer) const;
@ -127,6 +128,7 @@ public:
void saveXmlSer(QXmlStreamWriter &writer, XlsxSeries *ser, int id) const;
void saveXmlAxes(QXmlStreamWriter &writer) const;
public:
Chart::ChartType chartType;
QList< QSharedPointer<XlsxSeries> > seriesList;
@ -134,6 +136,8 @@ public:
QMap< XlsxAxis::AxisPos, QString > axisNames; // dev22
QString chartTitle;
AbstractSheet *sheet;
};

View File

@ -159,7 +159,7 @@ void Chart::setChartStyle(int id)
void Chart::setAxisTitle(Chart::ChartAxisPos pos, QString axisTitle)
{
Q_D(Chart);
Q_D(Chart);
if ( axisTitle.isEmpty() )
return;
@ -176,6 +176,14 @@ void Chart::setAxisTitle(Chart::ChartAxisPos pos, QString axisTitle)
}
// dev25
void Chart::setChartTitle(QString strchartTitle)
{
Q_D(Chart);
d->chartTitle = strchartTitle;
}
/*!
* \internal
@ -359,8 +367,18 @@ QString ChartPrivate::loadXmlNumRef(QXmlStreamReader &reader)
void ChartPrivate::saveXmlChart(QXmlStreamWriter &writer) const
{
//----------------------------------------------------
// c:chart
writer.writeStartElement(QStringLiteral("c:chart"));
//----------------------------------------------------
// c:title
saveXmlChartTitle(writer); // wrtie 'chart title'
//----------------------------------------------------
// c:plotArea
writer.writeStartElement(QStringLiteral("c:plotArea"));
switch (chartType)
@ -388,6 +406,7 @@ void ChartPrivate::saveXmlChart(QXmlStreamWriter &writer) const
saveXmlDoughnutChart(writer);
break;
default:
// ??
break;
}
@ -398,6 +417,57 @@ void ChartPrivate::saveXmlChart(QXmlStreamWriter &writer) const
writer.writeEndElement(); // c:chart
}
// dev25 {{ // wrtie 'chart title'
void ChartPrivate::saveXmlChartTitle(QXmlStreamWriter &writer) const
{
if ( chartTitle.isEmpty() )
return;
writer.writeStartElement(QStringLiteral("c:title"));
writer.writeStartElement(QStringLiteral("c:tx"));
writer.writeStartElement(QStringLiteral("c:rich"));
writer.writeEmptyElement(QStringLiteral("a:bodyPr")); // <a:bodyPr/>
writer.writeEmptyElement(QStringLiteral("a:lstStyle")); // <a:lstStyle/>
writer.writeStartElement(QStringLiteral("a:p"));
// <a:pPr lvl="0">
writer.writeStartElement(QStringLiteral("a:pPr"));
writer.writeAttribute(QStringLiteral("lvl"), QStringLiteral("0"));
// <a:defRPr b="0"/>
writer.writeStartElement(QStringLiteral("a:defRPr"));
writer.writeAttribute(QStringLiteral("b"), QStringLiteral("0"));
writer.writeEndElement(); // a:defRPr
writer.writeEndElement(); // a:pPr
writer.writeStartElement(QStringLiteral("a:r"));
// <a:t>chart name</a:t>
writer.writeTextElement(QStringLiteral("a:t"), chartTitle);
writer.writeEndElement(); // a:r
writer.writeEndElement(); // a:p
writer.writeEndElement(); // c:rich
writer.writeEndElement(); // c:tx
// <c:overlay val="0"/>
writer.writeStartElement(QStringLiteral("c:overlay"));
writer.writeAttribute(QStringLiteral("val"), QStringLiteral("0"));
writer.writeEndElement(); // c:overlay
writer.writeEndElement(); // c:title
}
// }}
void ChartPrivate::saveXmlPieChart(QXmlStreamWriter &writer) const
{
QString name = chartType==Chart::CT_Pie ? QStringLiteral("c:pieChart") : QStringLiteral("c:pie3DChart");

View File

@ -12,35 +12,10 @@
## 사용하는 방법
- [예제](Example.md)를 보세요
- HelloWorld : 헬로우 월드 예제 (가장 기본적인 구조)
- TestExcel : 기본 예제 (QtXlsx 예제 기반)
- TestExcel : QtXlsx 예제에 기반한 기본 예제
- HelloAndroid : 안드로이드에서 xlsx 파일 열기
- Copycat : xlsx 파일을 읽어 위젯으로 표시. xlsx 파일 인쇄. (할일: xlsx 파일로 저장)
- WebServer : xlsx 파일을 읽어 웹으로 표시 (`http://127.0.0.1:3001`)
### 활용 예제 (Hello excel)
#### :one: 엑셀(xlsx) 파일 쓰기
```cpp
QXlsx::Document xlsx;
xlsx.write("A1", "Hello Qt!"); // 셀(A,1)에 'Hello Qt!'값을 설정. 공유 문자열 타입으로 설정됨.
xlsx.saveAs("Test.xlsx"); // 'Test.xlsx'라는 이름으로 엑셀 파일을 저장.
```
#### :two: 엑셀(xlsx) 파일 읽기
```cpp
Document xlsx("Test.xlsx"); // 엑셀 파일 읽기
if (!xlsx.isLoadPackage()) {
return; // 엑셀 파일 읽기 실패
}
int row = 1; int col = 2;
Cell* cell = xlsx.cellAt(row, col); // Cell의 pointer를 얻음 (행(row)는 1번째, 열(column)은 2번째)
if ( cell == NULL )
continue; // 해당 행렬의 cell값이 설정되어 있지 않음
QVariant var = cell->readValue(); // 셀값을 읽음 (숫자(double), 날자(QDateTime), 문자열(QString) ...)
qDebug() << var; // 표시
```
- Copycat : xlsx 파일을 읽어 위젯으로 표시. xlsx 파일 인쇄.
- WebServer : xlsx 파일을 읽어 웹으로 표시
## 설정하는 방법 (설치)

View File

@ -11,36 +11,11 @@
## How to use
- See [examples](Example.md)
- HelloWorld : Hello world example (The most basic structure)
- HelloWorld : Hello world example (the most basic structure)
- TestExcel : basic samples based on QtXlsx samples
- HelloAndroid : read xlsx on Android
- Copycat : load xlsx file and display on widget. print xlsx file. (TODO: save xlsx)
- WebServer : load xlsx and display to web (`http://127.0.0.1:3001`)
### Example (Hello excel)
#### :one: Writing excel file(*.xlsx)
```cpp
QXlsx::Document xlsx;
xlsx.write("A1", "Hello Qt!"); // write "Hello Qt!" to cell(A,1). it's shared string.
xlsx.saveAs("Test.xlsx"); // save the document as 'Test.xlsx'
```
#### :two: Reading excel file(*.xlsx)
```cpp
Document xlsx("Test.xlsx"); // load excel file
if (!xlsx.isLoadPackage()) {
return; // failed to load excel
}
int row = 1; int col = 2;
Cell* cell = xlsx.cellAt(row, col); // get cell pointer. (row is 1. column is 2.)
if ( cell == NULL )
continue; // cell vaule is not set
QVariant var = cell->readValue(); // read cell value (number(double), QDateTime, QString ...)
qDebug() << var; // display value
```
- Copycat : load xlsx file and display on widget. print xlsx file.
- WebServer : load xlsx and display to web
## How to set up (Installation)

View File

@ -149,6 +149,7 @@ void sat_calc::generate_report()
Crom->addSeries( CellRange(chrom_data_array) );
Crom->setAxisTitle( Chart::Left, QString("left title") ); // dev24
Crom->setAxisTitle( Chart::Bottom, QString("bottom title") ); // dev24
Crom->setChartTitle( QString("hello chart") ); // dev25
qDebug() << "[debug] chrom_data_array : " << chrom_data_array;