QXlsx
QXlsx copied to clipboard
how to set column width when create a new worksheet
Hi, I am using this project to handle XLSX file, it is working perfect. but I met an issue. I want to set the column width after I create a new xlsx document object, but I get the 0 value calling Worksheet::columnWidth(),after I called WorksheetsetColumnWidth() to set a width value. I am reading those code about this part, my question is:
why no calling columnInfo->isSetwidth =true after calling columnInfo->width = width when call the method Worksheet::setColumnWidth();
It makes that the method "Worksheet::columnWidth()" will return the default value (default value is 0), when columnInfo->isSetwidth is not true and I call it.
Thanks for your working.
Dear @turbin
Thank you for reporting.
I created a repo for testing. https://github.com/JayTwoLab/qxlsx-issues-152
Can you make a pull request for testing?
Seems I have same issue. I would like to set column width if after autosizeColumnWidth it is less than my minWidth.
if (!doc.autosizeColumnWidth(1, maxColumn))
return;
for (auto i=1; i <=maxColumn; i++) {
const auto width = doc.columnWidth(i);
if (width < minWidth)
doc.setColumnWidth(i, minWidth);
else if (width > maxWidth)
doc.setColumnWidth(i, maxWidth);
qDebug() << i << width << doc.columnWidth(i);
}
But in console I see that all doc.columWidth return 0 How can I improve my code?
Can you test the new code? https://github.com/QtExcel/QXlsx/commit/00380c3ffad1fad1fb63b1a244aa2864db1d3b8d
Its only sets predefined value of column width. My goal is to
- optimize column width (doc.autosizeColumnWidth)
- set column width to some minimum value if column width is smaller
- set column width to some maximum value if column width is larger For that I need actual column width, not default value.
Okay i will keep this issue. Thanks for reporting.
As workaround I get QXlsx code to my app and refactor doc.autosizeColumnWidth to achieving my goals.