Debao Zhang
11 years ago
18 changed files with 278 additions and 78 deletions
After Width: | Height: | Size: 23 KiB |
@ -0,0 +1,11 @@ |
|||||
|
/*! |
||||
|
\example richtext |
||||
|
\title Rich Text Example |
||||
|
\brief This is a simplest Qt Xlsx example. |
||||
|
\ingroup qtxlsx-examples |
||||
|
|
||||
|
This example demonstrates how to create a new |
||||
|
.xlsx file containing some basic data and calculations |
||||
|
with Qt Xlsx Library. So lets see how this is achieved. |
||||
|
\image richtext.png |
||||
|
*/ |
@ -0,0 +1,35 @@ |
|||||
|
#include <QtCore> |
||||
|
#include "xlsxdocument.h" |
||||
|
#include "xlsxrichstring.h" |
||||
|
#include "xlsxformat.h" |
||||
|
int main() |
||||
|
{ |
||||
|
//![0]
|
||||
|
QXlsx::Document xlsx; |
||||
|
//![0]
|
||||
|
|
||||
|
//![1]
|
||||
|
QXlsx::Format blue; |
||||
|
blue.setFontColor(Qt::blue); |
||||
|
QXlsx::Format red; |
||||
|
red.setFontColor(Qt::red); |
||||
|
red.setFontSize(15); |
||||
|
QXlsx::Format bold; |
||||
|
bold.setFontBold(true); |
||||
|
|
||||
|
QXlsx::RichString rich; |
||||
|
rich.addFragment("Hello ", blue); |
||||
|
rich.addFragment("Qt ", red); |
||||
|
rich.addFragment("Xlsx", bold); |
||||
|
xlsx.write("B2", rich); |
||||
|
//![1]
|
||||
|
|
||||
|
//![2]
|
||||
|
xlsx.saveAs("Test1.xlsx"); |
||||
|
//![2]
|
||||
|
|
||||
|
QXlsx::Document("Test1.xlsx"); |
||||
|
xlsx.saveAs("Test2.xlsx"); |
||||
|
|
||||
|
return 0; |
||||
|
} |
@ -0,0 +1,9 @@ |
|||||
|
TARGET = hello |
||||
|
|
||||
|
#include(../../../src/xlsx/qtxlsx.pri) |
||||
|
QT+=xlsx |
||||
|
|
||||
|
CONFIG += console |
||||
|
CONFIG -= app_bundle |
||||
|
|
||||
|
SOURCES += main.cpp |
@ -0,0 +1,81 @@ |
|||||
|
/****************************************************************************
|
||||
|
** Copyright (c) 2013 Debao Zhang <hello@debao.me> |
||||
|
** All right reserved. |
||||
|
** |
||||
|
** Permission is hereby granted, free of charge, to any person obtaining |
||||
|
** a copy of this software and associated documentation files (the |
||||
|
** "Software"), to deal in the Software without restriction, including |
||||
|
** without limitation the rights to use, copy, modify, merge, publish, |
||||
|
** distribute, sublicense, and/or sell copies of the Software, and to |
||||
|
** permit persons to whom the Software is furnished to do so, subject to |
||||
|
** the following conditions: |
||||
|
** |
||||
|
** The above copyright notice and this permission notice shall be |
||||
|
** included in all copies or substantial portions of the Software. |
||||
|
** |
||||
|
** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
||||
|
** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
||||
|
** MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
||||
|
** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
||||
|
** LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
||||
|
** OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
||||
|
** WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
|
** |
||||
|
****************************************************************************/ |
||||
|
#ifndef XLSXRICHSTRING_H |
||||
|
#define XLSXRICHSTRING_H |
||||
|
|
||||
|
#include "xlsxglobal.h" |
||||
|
#include "xlsxformat.h" |
||||
|
#include <QVariant> |
||||
|
#include <QStringList> |
||||
|
#include <QSharedDataPointer> |
||||
|
|
||||
|
QT_BEGIN_NAMESPACE_XLSX |
||||
|
class RichStringPrivate; |
||||
|
class RichString; |
||||
|
// qHash is a friend, but we can't use default arguments for friends (§8.3.6.4)
|
||||
|
Q_XLSX_EXPORT uint qHash(const RichString &rs, uint seed = 0) Q_DECL_NOTHROW; |
||||
|
|
||||
|
class Q_XLSX_EXPORT RichString |
||||
|
{ |
||||
|
public: |
||||
|
RichString(); |
||||
|
explicit RichString(const QString text); |
||||
|
RichString(const RichString &other); |
||||
|
~RichString(); |
||||
|
|
||||
|
bool isRichString() const; |
||||
|
bool isEmtpy() const; |
||||
|
QString toPlainString() const; |
||||
|
|
||||
|
int fragmentCount() const; |
||||
|
void addFragment(const QString &text, const Format &format); |
||||
|
QString fragmentText(int index) const; |
||||
|
Format fragmentFormat(int index) const; |
||||
|
|
||||
|
operator QVariant() const; |
||||
|
|
||||
|
RichString &operator=(const RichString &other); |
||||
|
private: |
||||
|
friend Q_XLSX_EXPORT uint qHash(const RichString &rs, uint seed) Q_DECL_NOTHROW; |
||||
|
friend Q_XLSX_EXPORT bool operator==(const RichString &rs1, const RichString &rs2); |
||||
|
friend Q_XLSX_EXPORT bool operator!=(const RichString &rs1, const RichString &rs2); |
||||
|
friend Q_XLSX_EXPORT bool operator<(const RichString &rs1, const RichString &rs2); |
||||
|
|
||||
|
QSharedDataPointer<RichStringPrivate> d; |
||||
|
}; |
||||
|
|
||||
|
Q_XLSX_EXPORT bool operator==(const RichString &rs1, const RichString &rs2); |
||||
|
Q_XLSX_EXPORT bool operator!=(const RichString &rs1, const RichString &rs2); |
||||
|
Q_XLSX_EXPORT bool operator<(const RichString &rs1, const RichString &rs2); |
||||
|
Q_XLSX_EXPORT bool operator==(const RichString &rs1, const QString &rs2); |
||||
|
Q_XLSX_EXPORT bool operator==(const QString &rs1, const RichString &rs2); |
||||
|
Q_XLSX_EXPORT bool operator!=(const RichString &rs1, const QString &rs2); |
||||
|
Q_XLSX_EXPORT bool operator!=(const QString &rs1, const RichString &rs2); |
||||
|
|
||||
|
QT_END_NAMESPACE_XLSX |
||||
|
|
||||
|
Q_DECLARE_METATYPE(QXlsx::RichString) |
||||
|
|
||||
|
#endif // XLSXRICHSTRING_H
|
Loading…
Reference in new issue