Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ QXlsx/debug/*
QXlsx/release/*
*.-1
*.pro.user
build-*/
build*/
/build-*/*

# visual studio
Expand Down
3 changes: 3 additions & 0 deletions QXlsx/header/xlsxabstractsheet_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class AbstractSheetPrivate : public AbstractOOXmlFilePrivate
int id;
AbstractSheet::SheetState sheetState;
AbstractSheet::SheetType type;

int frozen_rows{};
int frozen_cols{};
};

QT_END_NAMESPACE_XLSX
Expand Down
2 changes: 2 additions & 0 deletions QXlsx/header/xlsxworksheet.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class QXLSX_EXPORT Worksheet : public AbstractSheet
bool isWhiteSpaceVisible() const;
void setWhiteSpaceVisible(bool visible);
bool setStartPage(int spagen); // add by liufeijin20181028
void setFrozenRows(int rows);
void setFrozenColumns(int cols);

QVector<CellLocation> getFullCells(int *maxRow, int *maxCol);

Expand Down
25 changes: 25 additions & 0 deletions QXlsx/source/xlsxworksheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@

for (int row_num = dimension.firstRow(); row_num <= dimension.lastRow(); row_num++) {
auto it = cellTable.constFind(row_num);
if (it != cellTable.constEnd()) {

Check warning on line 80 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "it" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkl&open=AZ0zam5TU7rlc86S1kkl&pullRequest=352
for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn();
col_num++) {
if (it->contains(col_num)) {

Check failure on line 83 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkm&open=AZ0zam5TU7rlc86S1kkm&pullRequest=352
if (span_max == -1) {
span_min = col_num;
span_max = col_num;
Expand Down Expand Up @@ -185,16 +185,16 @@
Worksheet *Worksheet::copy(const QString &distName, int distId) const
{
Q_D(const Worksheet);
Worksheet *sheet = new Worksheet(distName, distId, d->workbook, F_NewFromScratch);

Check failure on line 188 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kko&open=AZ0zam5TU7rlc86S1kko&pullRequest=352

Check warning on line 188 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkn&open=AZ0zam5TU7rlc86S1kkn&pullRequest=352
WorksheetPrivate *sheet_d = sheet->d_func();

sheet_d->dimension = d->dimension;

QMapIterator<int, QMap<int, std::shared_ptr<Cell>>> it(d->cellTable);

Check warning on line 193 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkp&open=AZ0zam5TU7rlc86S1kkp&pullRequest=352
while (it.hasNext()) {
it.next();
int row = it.key();
QMapIterator<int, std::shared_ptr<Cell>> it2(it.value());

Check warning on line 197 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkq&open=AZ0zam5TU7rlc86S1kkq&pullRequest=352
while (it2.hasNext()) {
it2.next();
int col = it2.key();
Expand Down Expand Up @@ -508,7 +508,7 @@
{
Q_D(const Worksheet);

Cell *cell = cellAt(row, column);

Check warning on line 511 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Make the type of this variable a pointer-to-const. The current type of "cell" is "class QXlsx::Cell *".

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkr&open=AZ0zam5TU7rlc86S1kkr&pullRequest=352
if (!cell)
return QVariant();

Expand Down Expand Up @@ -1084,8 +1084,8 @@
d->drawing = std::make_shared<Drawing>(this, F_NewFromScratch);
}

DrawingOneCellAnchor *anchor =

Check warning on line 1087 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kks&open=AZ0zam5TU7rlc86S1kks&pullRequest=352
new DrawingOneCellAnchor(d->drawing.get(), DrawingAnchor::Picture);

Check failure on line 1088 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkt&open=AZ0zam5TU7rlc86S1kkt&pullRequest=352

/*
The size are expressed as English Metric Units (EMUs).
Expand Down Expand Up @@ -1118,7 +1118,7 @@
int realImageIndex = imageIndex - 1; // minus one

DrawingAnchor *danchor = d->drawing->anchors.at(realImageIndex);
// QSharedPointer<Drawing> // for multithread

Check warning on line 1121 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Remove the commented out code.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk9&open=AZ0zam5TU7rlc86S1kk9&pullRequest=352
if (danchor == nullptr) {
return false;
}
Expand Down Expand Up @@ -1174,8 +1174,8 @@
if (!d->drawing)
d->drawing = std::make_shared<Drawing>(this, F_NewFromScratch);

DrawingOneCellAnchor *anchor =

Check warning on line 1177 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kku&open=AZ0zam5TU7rlc86S1kku&pullRequest=352
new DrawingOneCellAnchor(d->drawing.get(), DrawingAnchor::Picture);

Check failure on line 1178 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the use of "new" with an operation that automatically manages the memory.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkw&open=AZ0zam5TU7rlc86S1kkw&pullRequest=352

/*
The size are expressed as English Metric Units (EMUs). There are
Expand All @@ -1185,7 +1185,7 @@
anchor->from = XlsxMarker(row, column, 0, 0);
anchor->ext = size * 9525;

QSharedPointer<Chart> chart = QSharedPointer<Chart>(new Chart(this, F_NewFromScratch));

Check warning on line 1188 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Replace the redundant type with "auto".

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkv&open=AZ0zam5TU7rlc86S1kkv&pullRequest=352
anchor->setObjectGraphicFrame(chart);

return chart.data();
Expand Down Expand Up @@ -1316,6 +1316,17 @@
if (!d->showWhiteSpace)
writer.writeAttribute(QStringLiteral("showWhiteSpace"), QStringLiteral("0"));
writer.writeAttribute(QStringLiteral("workbookViewId"), QStringLiteral("0"));
if ((d->frozen_cols > 0) || (d->frozen_rows > 0)) {
writer.writeStartElement(QStringLiteral("pane"));
if (d->frozen_cols > 0)
writer.writeAttribute(QStringLiteral("xSplit"), QString::number(d->frozen_cols)); // set count of fixed col
if (d->frozen_rows > 0)
writer.writeAttribute(QStringLiteral("ySplit"), QString::number(d->frozen_rows)); // set count of fixed row
writer.writeAttribute(QStringLiteral("topLeftCell"), CellReference(d->frozen_rows + 1, d->frozen_cols + 1).toString()); //set next after fixed area cell
writer.writeAttribute(QStringLiteral("activePane"), QStringLiteral("bottomRight"));
writer.writeAttribute(QStringLiteral("state"), QStringLiteral("frozenSplit"));
writer.writeEndElement(); // pane
}
writer.writeEndElement(); // sheetView
writer.writeEndElement(); // sheetViews

Expand All @@ -1335,7 +1346,7 @@

if (!d->colsInfo.isEmpty()) {
writer.writeStartElement(QStringLiteral("cols"));
QMapIterator<int, QSharedPointer<XlsxColumnInfo>> it(d->colsInfo);

Check warning on line 1349 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkx&open=AZ0zam5TU7rlc86S1kkx&pullRequest=352
while (it.hasNext()) {
it.next();
QSharedPointer<XlsxColumnInfo> col_info = it.value();
Expand Down Expand Up @@ -1474,6 +1485,20 @@
}
//}}

void Worksheet::setFrozenRows(int rows)
{
Q_D(Worksheet);

d->frozen_rows=rows;
}

void Worksheet::setFrozenColumns(int cols)
{
Q_D(Worksheet);

d->frozen_cols=cols;
}

void WorksheetPrivate::saveXmlSheetData(QXmlStreamWriter &writer) const
{
calculateSpans();
Expand Down Expand Up @@ -1528,7 +1553,7 @@
if (ctIt != cellTable.constEnd()) {
for (int col_num = dimension.firstColumn(); col_num <= dimension.lastColumn();
col_num++) {
if (ctIt->contains(col_num)) {

Check failure on line 1556 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kky&open=AZ0zam5TU7rlc86S1kky&pullRequest=352
saveXmlCellData(writer, row_num, col_num, (*ctIt)[col_num]);
}
}
Expand Down Expand Up @@ -1643,9 +1668,9 @@

double num = cell->value().toDouble();
bool is1904 = q->workbook()->isDate1904();
if (!is1904 && num > 60) // for mac os excel

Check warning on line 1671 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use the init-statement to declare "is1904" inside the if statement.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kkz&open=AZ0zam5TU7rlc86S1kkz&pullRequest=352
{
num = num - 1;

Check warning on line 1673 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Value stored to 'num' is never read

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk8&open=AZ0zam5TU7rlc86S1kk8&pullRequest=352
}

// number type. see for 18.18.11 ST_CellType (Cell Type) more information.
Expand Down Expand Up @@ -1711,12 +1736,12 @@
return;

writer.writeStartElement(QStringLiteral("hyperlinks"));
QMapIterator<int, QMap<int, QSharedPointer<XlsxHyperlinkData>>> it(urlTable);

Check warning on line 1739 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk0&open=AZ0zam5TU7rlc86S1kk0&pullRequest=352

while (it.hasNext()) {
it.next();
int row = it.key();
QMapIterator<int, QSharedPointer<XlsxHyperlinkData>> it2(it.value());

Check warning on line 1744 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk1&open=AZ0zam5TU7rlc86S1kk1&pullRequest=352

while (it2.hasNext()) {
it2.next();
Expand Down Expand Up @@ -1779,7 +1804,7 @@
// we are trying to set "B:D", there should be "A", "B:D", "E:H".
// This will be more complex if we try to set "C:F" after "B:D".
{
QMapIterator<int, QSharedPointer<XlsxColumnInfo>> it(colsInfo);

Check warning on line 1807 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk2&open=AZ0zam5TU7rlc86S1kk2&pullRequest=352
while (it.hasNext()) {
it.next();
QSharedPointer<XlsxColumnInfo> info = it.value();
Expand All @@ -1797,7 +1822,7 @@
}
}
{
QMapIterator<int, QSharedPointer<XlsxColumnInfo>> it(colsInfo);

Check warning on line 1825 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk3&open=AZ0zam5TU7rlc86S1kk3&pullRequest=352
while (it.hasNext()) {
it.next();
QSharedPointer<XlsxColumnInfo> info = it.value();
Expand Down Expand Up @@ -1955,7 +1980,7 @@
QList<QSharedPointer<XlsxColumnInfo>> columnInfoList = d->getColumnInfoList(column, column);

// [dev54]
if (columnInfoList.size() == 0) {

Check warning on line 1983 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Use "isEmpty()" to check whether the container is empty or not.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk4&open=AZ0zam5TU7rlc86S1kk4&pullRequest=352
// column information is not found
// qDebug() << "[debug]" << __FUNCTION__ << "column (info) is not found. " << column;
}
Expand Down Expand Up @@ -2321,7 +2346,7 @@
QXmlStreamAttributes attributes = reader.attributes();
QString r = attributes.value(QLatin1String("r")).toString();
CellReference pos(r);
if (r.isEmpty())

Check failure on line 2349 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Refactor this code to not nest more than 3 if|for|do|while|switch statements.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk5&open=AZ0zam5TU7rlc86S1kk5&pullRequest=352
{
pos.setRow(row_num);
pos.setColumn(++col_num);
Expand Down Expand Up @@ -2875,13 +2900,13 @@
return ret;
}

QMapIterator<int, QMap<int, std::shared_ptr<Cell>>> _it(d->cellTable);

Check warning on line 2903 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk6&open=AZ0zam5TU7rlc86S1kk6&pullRequest=352

while (_it.hasNext()) {
_it.next();

int keyI = _it.key(); // key (cell row)
QMapIterator<int, std::shared_ptr<Cell>> _iit(_it.value()); // value

Check warning on line 2909 in QXlsx/source/xlsxworksheet.cpp

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Avoid explicitly specifying the template arguments by relying on the class template argument deduction.

See more on https://sonarcloud.io/project/issues?id=QtExcel_QXlsx&issues=AZ0zam5TU7rlc86S1kk7&open=AZ0zam5TU7rlc86S1kk7&pullRequest=352

while (_iit.hasNext()) {
_iit.next();
Expand Down