Add overload function for setRow and setColumn
This commit is contained in:
@@ -170,18 +170,37 @@ bool Document::setRow(int row, double height, Format *format, bool hidden)
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Set properties for columns of cells.
|
||||
* \param First column (zero-indexed).
|
||||
* \param Last column (zero-indexed).
|
||||
* \param width The width of the column(s).
|
||||
* \param format Optional Format object.
|
||||
* \param 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.
|
||||
*/
|
||||
bool Document::setColumn(int colFirst, int colLast, double width, Format *format, bool hidden)
|
||||
{
|
||||
return currentWorksheet()->setColumn(colFirst, colLast, width, 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 should be "A", "B", "C", ...
|
||||
*/
|
||||
bool Document::setColumn(const QString &colFirst, const QString &colLast, double width, Format *format, bool hidden)
|
||||
{
|
||||
return currentWorksheet()->setColumn(colFirst, colLast, width, format, hidden);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Add a data validation rule for current worksheet
|
||||
* \param validation
|
||||
|
||||
@@ -61,7 +61,9 @@ public:
|
||||
int mergeCells(const QString &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 addDataValidation(const DataValidation &validation);
|
||||
|
||||
Cell *cellAt(const QString &cell) const;
|
||||
|
||||
@@ -129,6 +129,24 @@ QString xl_col_to_name(int col_num)
|
||||
return col_str;
|
||||
}
|
||||
|
||||
int xl_col_name_to_value(const QString &col_str)
|
||||
{
|
||||
QRegularExpression re(QStringLiteral("^([A-Z]{1,3})$"));
|
||||
QRegularExpressionMatch match = re.match(col_str);
|
||||
if (match.hasMatch()) {
|
||||
int col = 0;
|
||||
int expn = 0;
|
||||
for (int i=col_str.size()-1; i>-1; --i) {
|
||||
col += (col_str[i].unicode() - 'A' + 1) * intPow(26, expn);
|
||||
expn++;
|
||||
}
|
||||
|
||||
col--;
|
||||
return col;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
QString xl_rowcol_to_cell(int row, int col, bool row_abs, bool col_abs)
|
||||
{
|
||||
row += 1; //Change to 1-index
|
||||
|
||||
@@ -42,6 +42,7 @@ XLSX_AUTOTEST_EXPORT QDateTime datetimeFromNumber(double num, bool is1904=false)
|
||||
|
||||
XLSX_AUTOTEST_EXPORT QPoint xl_cell_to_rowcol(const QString &cell_str);
|
||||
XLSX_AUTOTEST_EXPORT QString xl_col_to_name(int col_num);
|
||||
XLSX_AUTOTEST_EXPORT int xl_col_name_to_value(const QString &col_str);
|
||||
XLSX_AUTOTEST_EXPORT QString xl_rowcol_to_cell(int row, int col, bool row_abs=false, bool col_abs=false);
|
||||
XLSX_AUTOTEST_EXPORT QString xl_rowcol_to_cell_fast(int row, int col);
|
||||
|
||||
|
||||
+42
-10
@@ -804,8 +804,8 @@ void Worksheet::saveToXmlFile(QIODevice *device)
|
||||
for (int i=0; i<d->colsInfo.size(); ++i) {
|
||||
QSharedPointer<XlsxColumnInfo> col_info = d->colsInfo[i];
|
||||
writer.writeStartElement(QStringLiteral("col"));
|
||||
writer.writeAttribute(QStringLiteral("min"), QString::number(col_info->column_min + 1));
|
||||
writer.writeAttribute(QStringLiteral("max"), QString::number(col_info->column_max));
|
||||
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));
|
||||
if (col_info->format)
|
||||
writer.writeAttribute(QStringLiteral("style"), QString::number(col_info->format->xfIndex()));
|
||||
@@ -1072,9 +1072,9 @@ void WorksheetPrivate::writeDrawings(XmlStreamWriter &writer)
|
||||
writer.writeAttribute(QStringLiteral("r:id"), QStringLiteral("rId%1").arg(index));
|
||||
}
|
||||
|
||||
/*
|
||||
/*!
|
||||
Sets row height and format. Row height measured in point size. If format
|
||||
equals 0 then format is ignored.
|
||||
equals 0 then format is ignored. \a row is zero-indexed.
|
||||
*/
|
||||
bool Worksheet::setRow(int row, double height, Format *format, bool hidden)
|
||||
{
|
||||
@@ -1089,7 +1089,22 @@ 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, height, format, hidden);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/*!
|
||||
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
|
||||
@@ -1101,7 +1116,7 @@ bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *forma
|
||||
bool ignore_row = true;
|
||||
bool ignore_col = (format || (width && hidden)) ? false : true;
|
||||
|
||||
if (colFirst >= colLast)
|
||||
if (colFirst > colLast)
|
||||
return false;
|
||||
|
||||
if (d->checkDimensions(0, colLast, ignore_row, ignore_col))
|
||||
@@ -1112,7 +1127,7 @@ bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *forma
|
||||
QSharedPointer<XlsxColumnInfo> info(new XlsxColumnInfo(colFirst, colLast, width, format, hidden));
|
||||
d->colsInfo.append(info);
|
||||
|
||||
for (int col=colFirst; col<colLast; ++col)
|
||||
for (int col=colFirst; col<=colLast; ++col)
|
||||
d->colsInfoHelper[col] = info;
|
||||
|
||||
d->workbook->styles()->addFormat(format);
|
||||
@@ -1120,6 +1135,23 @@ bool Worksheet::setColumn(int colFirst, int colLast, double width, Format *forma
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
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 should be "A", "B", "C", ...
|
||||
*/
|
||||
bool Worksheet::setColumn(const QString &colFirst, const QString &colLast, double width, Format *format, bool hidden)
|
||||
{
|
||||
int col1 = xl_col_name_to_value(colFirst);
|
||||
int col2 = xl_col_name_to_value(colLast);
|
||||
|
||||
if (col1 == -1 || col2 == -1)
|
||||
return false;
|
||||
|
||||
return setColumn(col1, col2, width, format, hidden);
|
||||
}
|
||||
|
||||
/*!
|
||||
Return the range that contains cell data.
|
||||
*/
|
||||
@@ -1489,8 +1521,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->column_min = min - 1;
|
||||
info->column_max = max;
|
||||
info->firstColumn = min - 1;
|
||||
info->lastColumn = max - 1;
|
||||
|
||||
if (colAttrs.hasAttribute(QLatin1String("customWidth"))) {
|
||||
double width = colAttrs.value(QLatin1String("width")).toDouble();
|
||||
@@ -1506,7 +1538,7 @@ void WorksheetPrivate::readColumnsInfo(XmlStreamReader &reader)
|
||||
}
|
||||
|
||||
colsInfo.append(info);
|
||||
for (int col=min; col<max; ++col)
|
||||
for (int col=min; col<=max; ++col)
|
||||
colsInfoHelper[col] = info;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,9 @@ public:
|
||||
int unmergeCells(const CellRange &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);
|
||||
CellRange dimension() const;
|
||||
|
||||
bool isWindowProtected() const;
|
||||
|
||||
@@ -135,13 +135,13 @@ struct XlsxRowInfo
|
||||
|
||||
struct XlsxColumnInfo
|
||||
{
|
||||
XlsxColumnInfo(int column_min=0, int column_max=1, double width=0, Format *format=0, bool hidden=false) :
|
||||
column_min(column_min), column_max(column_max), width(width), format(format), hidden(hidden)
|
||||
XlsxColumnInfo(int firstColumn=0, int lastColumn=1, double width=0, Format *format=0, bool hidden=false) :
|
||||
firstColumn(firstColumn), lastColumn(lastColumn), width(width), format(format), hidden(hidden)
|
||||
{
|
||||
|
||||
}
|
||||
int column_min;
|
||||
int column_max;
|
||||
int firstColumn;
|
||||
int lastColumn;
|
||||
double width;
|
||||
Format *format;
|
||||
bool hidden;
|
||||
|
||||
Reference in New Issue
Block a user