Fix issue 6: row & column No. starts from 1 instead of 0 now
This commit is contained in:
@@ -181,32 +181,19 @@ int Document::unmergeCells(const CellRange &range)
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set properties for a row of cells.
|
||||
* \param row The worksheet row (zero indexed).
|
||||
* \param height The row height.
|
||||
* \param format Optional Format object.
|
||||
* \param hidden
|
||||
Sets row \a height and \a format. Row height measured in point size. If format
|
||||
equals 0 then format is ignored. \a row is 1-indexed.
|
||||
*/
|
||||
bool Document::setRow(int row, double height, Format *format, bool hidden)
|
||||
{
|
||||
return currentWorksheet()->setRow(row, height, format, hidden);
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
Sets row height and format. Row height measured in point size. If format
|
||||
equals 0 then format is ignored. \a row should be "1", "2", "3", ...
|
||||
*/
|
||||
bool Document::setRow(const QString &row, double height, Format *format, bool hidden)
|
||||
{
|
||||
return currentWorksheet()->setRow(row, height, format, hidden);
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets column width and format for all columns from colFirst to colLast. Column
|
||||
width measured as the number of characters of the maximum digit width of the
|
||||
numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. If format
|
||||
equals 0 then format is ignored. \a colFirst and \a colLast are all zero-indexed.
|
||||
equals 0 then format is ignored. \a colFirst and \a colLast are all 1-indexed.
|
||||
*/
|
||||
bool Document::setColumn(int colFirst, int colLast, double width, Format *format, bool hidden)
|
||||
{
|
||||
|
||||
@@ -63,7 +63,6 @@ public:
|
||||
int unmergeCells(const CellRange &range);
|
||||
int unmergeCells(const QString &range);
|
||||
bool setRow(int row, double height, Format* format=0, bool hidden=false);
|
||||
bool setRow(const QString &row, double height, Format* format=0, bool hidden=false);
|
||||
bool setColumn(int colFirst, int colLast, double width, Format* format=0, bool hidden=false);
|
||||
bool setColumn(const QString &colFirst, const QString &colLast, double width, Format* format=0, bool hidden=false);
|
||||
bool groupRows(int rowFirst, int rowLast, bool collapsed = true);
|
||||
|
||||
@@ -91,7 +91,7 @@ QDateTime datetimeFromNumber(double num, bool is1904)
|
||||
QPoint xl_cell_to_rowcol(const QString &cell_str)
|
||||
{
|
||||
if (cell_str.isEmpty())
|
||||
return QPoint(0, 0);
|
||||
return QPoint(-1, -1);
|
||||
QRegularExpression re(QStringLiteral("^([A-Z]{1,3})(\\d+)$"));
|
||||
QRegularExpressionMatch match = re.match(cell_str);
|
||||
if (match.hasMatch()) {
|
||||
@@ -104,8 +104,7 @@ QPoint xl_cell_to_rowcol(const QString &cell_str)
|
||||
expn++;
|
||||
}
|
||||
|
||||
col--;
|
||||
int row = row_str.toInt() - 1;
|
||||
int row = row_str.toInt();
|
||||
return QPoint(row, col);
|
||||
} else {
|
||||
return QPoint(-1, -1); //...
|
||||
@@ -114,7 +113,6 @@ QPoint xl_cell_to_rowcol(const QString &cell_str)
|
||||
|
||||
QString xl_col_to_name(int col_num)
|
||||
{
|
||||
col_num += 1; //Change to 1-index
|
||||
QString col_str;
|
||||
|
||||
int remainder;
|
||||
@@ -141,7 +139,6 @@ int xl_col_name_to_value(const QString &col_str)
|
||||
expn++;
|
||||
}
|
||||
|
||||
col--;
|
||||
return col;
|
||||
}
|
||||
return -1;
|
||||
@@ -149,7 +146,6 @@ int xl_col_name_to_value(const QString &col_str)
|
||||
|
||||
QString xl_rowcol_to_cell(int row, int col, bool row_abs, bool col_abs)
|
||||
{
|
||||
row += 1; //Change to 1-index
|
||||
QString cell_str;
|
||||
if (col_abs)
|
||||
cell_str.append(QLatin1Char('$'));
|
||||
@@ -170,7 +166,7 @@ QString xl_rowcol_to_cell_fast(int row, int col)
|
||||
col_str = xl_col_to_name(col);
|
||||
col_cache[col] = col_str;
|
||||
}
|
||||
return col_str + QString::number(row+1);
|
||||
return col_str + QString::number(row);
|
||||
}
|
||||
|
||||
} //namespace QXlsx
|
||||
|
||||
+20
-30
@@ -122,7 +122,7 @@ void WorksheetPrivate::calculateSpans()
|
||||
}
|
||||
}
|
||||
|
||||
if ((row_num + 1)%16 == 0 || row_num == dimension.lastRow()) {
|
||||
if ((row_num)%16 == 0 || row_num == dimension.lastRow()) {
|
||||
int span_index = row_num / 16;
|
||||
if (span_max != INT32_MIN) {
|
||||
span_min += 1;
|
||||
@@ -426,6 +426,10 @@ QList<QPair<QString, QString> > Worksheet::drawingLinks() const
|
||||
return d->drawingLinks;
|
||||
}
|
||||
|
||||
/*!
|
||||
* Write \a value to cell (\a row, \a column) with the \a format.
|
||||
* Both \a row and \a column are all 1-indexed value.
|
||||
*/
|
||||
int Worksheet::write(int row, int column, const QVariant &value, Format *format)
|
||||
{
|
||||
Q_D(Worksheet);
|
||||
@@ -850,9 +854,10 @@ void Worksheet::saveToXmlFile(QIODevice *device)
|
||||
it.next();
|
||||
QSharedPointer<XlsxColumnInfo> col_info = it.value();
|
||||
writer.writeStartElement(QStringLiteral("col"));
|
||||
writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->firstColumn + 1));
|
||||
writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->lastColumn + 1));
|
||||
writer.writeAttribute(QStringLiteral("width"), QString::number(col_info->width, 'g', 15));
|
||||
writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->firstColumn));
|
||||
writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->lastColumn));
|
||||
if (col_info->width)
|
||||
writer.writeAttribute(QStringLiteral("width"), QString::number(col_info->width, 'g', 15));
|
||||
if (col_info->format)
|
||||
writer.writeAttribute(QStringLiteral("style"), QString::number(col_info->format->xfIndex()));
|
||||
if (col_info->hidden)
|
||||
@@ -891,14 +896,14 @@ void WorksheetPrivate::writeSheetData(XmlStreamWriter &writer)
|
||||
continue;
|
||||
}
|
||||
|
||||
int span_index = row_num / 16;
|
||||
int span_index = (row_num-1) / 16;
|
||||
QString span;
|
||||
if (row_spans.contains(span_index))
|
||||
span = row_spans[span_index];
|
||||
|
||||
if (cellTable.contains(row_num)) {
|
||||
writer.writeStartElement(QStringLiteral("row"));
|
||||
writer.writeAttribute(QStringLiteral("r"), QString::number(row_num + 1));
|
||||
writer.writeAttribute(QStringLiteral("r"), QString::number(row_num));
|
||||
|
||||
if (!span.isEmpty())
|
||||
writer.writeAttribute(QStringLiteral("spans"), span);
|
||||
@@ -938,10 +943,10 @@ void WorksheetPrivate::writeSheetData(XmlStreamWriter &writer)
|
||||
void WorksheetPrivate::writeCellData(XmlStreamWriter &writer, int row, int col, QSharedPointer<Cell> cell)
|
||||
{
|
||||
//This is the innermost loop so efficiency is important.
|
||||
QString cell_range = xl_rowcol_to_cell_fast(row, col);
|
||||
QString cell_pos = xl_rowcol_to_cell_fast(row, col);
|
||||
|
||||
writer.writeStartElement(QStringLiteral("c"));
|
||||
writer.writeAttribute(QStringLiteral("r"), cell_range);
|
||||
writer.writeAttribute(QStringLiteral("r"), cell_pos);
|
||||
|
||||
//Style used by the cell, row or col
|
||||
if (cell->format())
|
||||
@@ -1127,8 +1132,8 @@ void WorksheetPrivate::writeDrawings(XmlStreamWriter &writer)
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets row height and format. Row height measured in point size. If format
|
||||
equals 0 then format is ignored. \a row is zero-indexed.
|
||||
Sets row \a height and \a format. Row height measured in point size. If format
|
||||
equals 0 then format is ignored. \a row is 1-indexed.
|
||||
*/
|
||||
bool Worksheet::setRow(int row, double height, Format *format, bool hidden)
|
||||
{
|
||||
@@ -1143,21 +1148,6 @@ bool Worksheet::setRow(int row, double height, Format *format, bool hidden)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
\overload
|
||||
Sets row height and format. Row height measured in point size. If format
|
||||
equals 0 then format is ignored. \a row should be "1", "2", "3", ...
|
||||
*/
|
||||
bool Worksheet::setRow(const QString &row, double height, Format *format, bool hidden)
|
||||
{
|
||||
bool ok=true;
|
||||
int r = row.toInt(&ok);
|
||||
if (ok)
|
||||
return setRow(r-1, height, format, hidden);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void WorksheetPrivate::splitColsInfo(int colFirst, int colLast)
|
||||
{
|
||||
// Split current columnInfo, for example, if "A:H" has been set,
|
||||
@@ -1201,10 +1191,10 @@ void WorksheetPrivate::splitColsInfo(int colFirst, int colLast)
|
||||
}
|
||||
|
||||
/*!
|
||||
Sets column width and format for all columns from colFirst to colLast. Column
|
||||
Sets column \a width and \a format for all columns from \a colFirst to \a colLast. Column
|
||||
width measured as the number of characters of the maximum digit width of the
|
||||
numbers 0, 1, 2, ..., 9 as rendered in the normal style's font. If format
|
||||
equals 0 then format is ignored.
|
||||
equals 0 then format is ignored. Both \a colFirst and \a colLast are all 1-indexed.
|
||||
*/
|
||||
bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *format, bool hidden)
|
||||
{
|
||||
@@ -1625,7 +1615,7 @@ void WorksheetPrivate::readSheetData(XmlStreamReader &reader)
|
||||
|
||||
//"r" is optional too.
|
||||
if (attributes.hasAttribute(QLatin1String("r"))) {
|
||||
int row = attributes.value(QLatin1String("r")).toInt()-1;
|
||||
int row = attributes.value(QLatin1String("r")).toInt();
|
||||
rowsInfo[row] = info;
|
||||
}
|
||||
}
|
||||
@@ -1731,8 +1721,8 @@ void WorksheetPrivate::readColumnsInfo(XmlStreamReader &reader)
|
||||
QXmlStreamAttributes colAttrs = reader.attributes();
|
||||
int min = colAttrs.value(QLatin1String("min")).toInt();
|
||||
int max = colAttrs.value(QLatin1String("max")).toInt();
|
||||
info->firstColumn = min - 1;
|
||||
info->lastColumn = max - 1;
|
||||
info->firstColumn = min;
|
||||
info->lastColumn = max;
|
||||
|
||||
//!Todo, customWidth support.
|
||||
//Note, node may have "width" without "customWidth"
|
||||
|
||||
Reference in New Issue
Block a user