// xlsxworksheet.cpp
#include <QtGlobal>
#include <QVariant>
#include <QDateTime>
#include <QDate>
#include <QTime>
#include <QPoint>
#include <QFile>
#include <QUrl>
#include <QDebug>
#include <QBuffer>
#include <QXmlStreamWriter>
#include <QXmlStreamReader>
#include <QTextDocument>
#include <QDir>
#include <QMapIterator>
#include <QMap>
#include <cmath>
#include "xlsxrichstring.h"
#include "xlsxcellreference.h"
#include "xlsxworksheet.h"
#include "xlsxworksheet_p.h"
#include "xlsxworkbook.h"
#include "xlsxformat.h"
#include "xlsxformat_p.h"
#include "xlsxutility_p.h"
#include "xlsxsharedstrings_p.h"
#include "xlsxdrawing_p.h"
#include "xlsxstyles_p.h"
#include "xlsxcell.h"
#include "xlsxcell_p.h"
#include "xlsxcellrange.h"
#include "xlsxconditionalformatting_p.h"
#include "xlsxdrawinganchor_p.h"
#include "xlsxchart.h"
#include "xlsxcellformula.h"
#include "xlsxcellformula_p.h"
#include "xlsxcelllocation.h"
QT_BEGIN_NAMESPACE_XLSX
WorksheetPrivate::WorksheetPrivate(Worksheet *p, Worksheet::CreateFlag flag)
: AbstractSheetPrivate(p, flag),
windowProtection(false),
showFormulas(false),
showGridLines(true),
showRowColHeaders(true),
showZeros(true),
rightToLeft(false),
tabSelected(false),
showRuler(false),
showOutlineSymbols(true),
showWhiteSpace(true),
urlPattern(QStringLiteral("^([fh]tt?ps?://)|(mailto:)|(file://)"))
{
previous_row = 0;
outline_row_level = 0;
outline_col_level = 0;
default_row_height = 15;
default_row_zeroed = false;
}
WorksheetPrivate::~WorksheetPrivate()
{
}
/*
Calculate the "spans" attribute of the <row> tag. This is an
XLSX optimisation and isn't strictly required. However, it
makes comparing files easier. The span is the same for each
block of 16 rows.
*/
void WorksheetPrivate::calculateSpans() const
{
row_spans.clear();
int span_min = XLSX_COLUMN_MAX+1;
int span_max = -1;
for (int row_num = dimension.firstRow(); row_num <= dimension.lastRow(); row_num++) {
auto it = cellTable.constFind(row_num);
if (it != cellTable.constEnd()) {
for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn(); col_num++) {
if (it->contains(col_num)) {
if (span_max == -1) {
span_min = col_num;
span_max = col_num;
} else {
if (col_num < span_min)
span_min = col_num;
else if (col_num > span_max)
span_max = col_num;
}
}
}
}
auto cIt = comments.constFind(row_num);
if (cIt != comments.constEnd()) {
for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn(); col_num++) {
if (cIt->contains(col_num)) {
if (span_max == -1) {
span_min = col_num;
span_max = col_num;
} else {
if (col_num < span_min)
span_min = col_num;
else if (col_num > span_max)
span_max = col_num;
}
}
}
}
if (row_num%16 == 0 || row_num == dimension.lastRow()) {
if (span_max != -1) {
row_spans[row_num / 16] = QStringLiteral("%1:%2").arg(span_min).arg(span_max);
span_min = XLSX_COLUMN_MAX+1;
span_max = -1;
}
}
}
}
QString WorksheetPrivate::generateDimensionString() const
{
if (!dimension.isValid())
return QStringLiteral("A1");
else
return dimension.toString();
}
/*
Check that row and col are valid and store the max and min
values for use in other methods/elements. The ignore_row /
ignore_col flags is used to indicate that we wish to perform
the dimension check without storing the value. The ignore
flags are use by setRow() and dataValidate.
*/
int WorksheetPrivate::checkDimensions(int row, int col, bool ignore_row, bool ignore_col)
{
Q_ASSERT_X(row!=0, "checkDimensions", "row should start from 1 instead of 0");
Q_ASSERT_X(col!=0, "checkDimensions", "column should start from 1 instead of 0");
if (row > XLSX_ROW_MAX || row < 1 || col > XLSX_COLUMN_MAX || col < 1)
return -1;
if (!ignore_row) {
if (row < dimension.firstRow() || dimension.firstRow() == -1) dimension.setFirstRow(row);
if (row > dimension.lastRow()) dimension.setLastRow(row);
}
if (!ignore_col) {
if (col < dimension.firstColumn() || dimension.firstColumn() == -1) dimension.setFirstColumn(col);
if (col > dimension.lastColumn()) dimension.setLastColumn(col);
}
return 0;
}
/*!
\class Worksheet
\inmodule QtXlsx
\brief Represent one worksheet in the workbook.
*/
/*!
* \internal
*/
Worksheet::Worksheet(const QString &name, int id, Workbook *workbook, CreateFlag flag)
:AbstractSheet(name, id, workbook, new WorksheetPrivate(this, flag))
{
if (!workbook) //For unit test propose only. Ignore the memery leak.
d_func()->workbook = new Workbook(flag);
}
/*!
* \internal
*
* Make a copy of this sheet.
*/
Worksheet *Worksheet::copy(const QString &distName, int distId) const
{
Q_D(const Worksheet);
Worksheet *sheet = new Worksheet(distName, distId, d->workbook, F_NewFromScratch);
WorksheetPrivate *sheet_d = sheet->d_func();
sheet_d->dimension = d->dimension;
QMapIterator<int, QMap<int, QSharedPointer<Cell> > > it(d->cellTable);
while (it.hasNext())
{
it.next();
int row = it.key();
QMapIterator<int, QSharedPointer<Cell> > it2(it.value());
while (it2.hasNext())
{
it2.next();
int col = it2.key();
QSharedPointer<Cell> cell(new Cell(it2.value().data()));
cell->d_ptr->parent = sheet;
if (cell->cellType() == Cell::SharedStringType)
d->workbook->sharedStrings()->addSharedString(cell->d_ptr->richString);
sheet_d->cellTable[row][col] = cell;
}
}
sheet_d->merges = d->merges;
// sheet_d->rowsInfo = d->rowsInfo;
// sheet_d->colsInfo = d->colsInfo;
// sheet_d->colsInfoHelper = d->colsInfoHelper;
// sheet_d->dataValidationsList = d->dataValidationsList;
// sheet_d->conditionalFormattingList = d->conditionalFormattingList;
return sheet;
}
/*!
* Destroys this workssheet.
*/
Worksheet::~Worksheet()
{
}
/*!
* Returns whether sheet is protected.
*/
bool Worksheet::isWindowProtected() const
{
Q_D(const Worksheet);
return d->windowProtection;
}
/*!
* Protects/unprotects the sheet based on \a protect.
*/
void Worksheet::setWindowProtected(bool protect)
{
Q_D(Worksheet);
d->windowProtection = protect;
}
/*!
* Return whether formulas instead of their calculated results shown in cells
*/
bool Worksheet::isFormulasVisible() const
{
Q_D(const Worksheet);
return d->showFormulas;
}
/*!
* Show formulas in cells instead of their calculated results when \a visible is true.
*/
void Worksheet::setFormulasVisible(bool visible)
{
Q_D(Worksheet);
d->showFormulas = visible;
}
/*!
* Return whether gridlines is shown or not.
*/
bool Worksheet::isGridLinesVisible() const
{
Q_D(const Worksheet);
return d->showGridLines;
}
/*!
* Show or hide the gridline based on \a visible
*/
void Worksheet::setGridLinesVisible(bool visible)
{
Q_D(Worksheet);
d->showGridLines = visible;
}
/*!
* Return whether is row and column headers is vislbe.
*/
bool Worksheet::isRowColumnHeadersVisible() const
{
Q_D(const Worksheet);
return d->showRowColHeaders;
}
/*!
* Show or hide the row column headers based on \a visible
*/
void Worksheet::setRowColumnHeadersVisible(bool visible)
{
Q_D(Worksheet);
d->showRowColHeaders = visible;
}
/*!
* Return whether the sheet is shown right-to-left or not.
*/
bool Worksheet::isRightToLeft() const
{
Q_D(const Worksheet);
return d->rightToLeft;
}
/*!
* Enable or disable the right-to-left based on \a enable.
*/
void Worksheet::setRightToLeft(bool enable)
{
Q_D(Worksheet);
d->rightToLeft = enable;
}
/*!
* Return whether is cells that have zero value show a zero.
没有合适的资源?快使用搜索试试~ 我知道了~
QT处理Excel数据到Table Widget的四种方法
共88个文件
h:48个
cpp:35个
pro:2个
需积分: 0 99 下载量 126 浏览量
2022-07-01
14:23:50
上传
评论 3
收藏 155KB ZIP 举报
温馨提示
QT处理Excel数据到Table Widget的四种方法
资源详情
资源评论
资源推荐
收起资源包目录
ReadExcel.zip (88个子文件)
ReadExcel
QXlsx.pro 1KB
main.cpp 183B
mainwindow.ui 12KB
mainwindow.cpp 6KB
ReadExcel.pro 1KB
mainwindow.h 549B
QXlsx.pri 6KB
header
xlsxconditionalformatting_p.h 2KB
xlsxformat_p.h 3KB
xlsxabstractooxmlfile.h 1021B
xlsxmediafile_p.h 1006B
xlsxconditionalformatting.h 4KB
xlsxworksheet_p.h 7KB
xlsxdocpropsapp_p.h 922B
xlsxdocpropscore_p.h 721B
xlsxzipwriter_p.h 638B
xlsxdocument.h 5KB
xlsxnumformatparser_p.h 2KB
xlsxstyles_p.h 5KB
xlsxrichstring.h 3KB
xlsxtheme_p.h 544B
xlsxcellreference.h 1KB
xlsxabstractsheet_p.h 776B
xlsxchartsheet.h 826B
xlsxsimpleooxmlfile_p.h 2KB
xlsxcellformula_p.h 730B
xlsxchart.h 2KB
xlsxutility_p.h 1KB
xlsxzipreader_p.h 762B
xlsxrichstring_p.h 2KB
xlsxworksheet.h 7KB
xlsxdrawinganchor_p.h 5KB
xlsxworkbook.h 3KB
xlsxworkbook_p.h 2KB
xlsxsharedstrings_p.h 3KB
xlsxcelllocation.h 463B
xlsxformat.h 7KB
xlsxdatetype.h 984B
xlsxglobal.h 921B
xlsxabstractsheet.h 1KB
xlsxcell_p.h 722B
xlsxcellrange.h 2KB
xlsxcellformula.h 1KB
xlsxabstractooxmlfile_p.h 681B
xlsxcell.h 2KB
xlsxcolor_p.h 1KB
xlsxrelationships_p.h 3KB
xlsxdrawing_p.h 756B
xlsxchart_p.h 5KB
xlsxdatavalidation.h 3KB
xlsxcontenttypes_p.h 1KB
xlsxchartsheet_p.h 499B
xlsxdatavalidation_p.h 1KB
xlsxdocument_p.h 989B
ReadExcel.pro.user 102KB
source
xlsxcolor.cpp 6KB
xlsxutility.cpp 9KB
xlsxformat.cpp 31KB
xlsxrelationships.cpp 5KB
xlsxsimpleooxmlfile.cpp 659B
xlsxcelllocation.cpp 348B
xlsxrichstring.cpp 7KB
xlsxdatavalidation.cpp 16KB
xlsxstyles.cpp 64KB
xlsxdocpropscore.cpp 7KB
xlsxdocument.cpp 42KB
xlsxtheme.cpp 10KB
xlsxcellreference.cpp 4KB
xlsxzipwriter.cpp 964B
xlsxcell.cpp 8KB
xlsxchart.cpp 80KB
xlsxmediafile.cpp 1KB
xlsxchartsheet.cpp 4KB
xlsxdrawinganchor.cpp 48KB
xlsxconditionalformatting.cpp 30KB
xlsxcellformula.cpp 13KB
xlsxdatetype.cpp 1KB
xlsxsharedstrings.cpp 14KB
xlsxcontenttypes.cpp 6KB
xlsxdocpropsapp.cpp 5KB
xlsxworksheet.cpp 92KB
xlsxdrawing.cpp 2KB
xlsxworkbook.cpp 24KB
xlsxabstractsheet.cpp 3KB
xlsxcellrange.cpp 3KB
xlsxabstractooxmlfile.cpp 2KB
xlsxzipreader.cpp 898B
xlsxnumformatparser.cpp 2KB
共 88 条
- 1
1594231563
- 粉丝: 38
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0