You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "pjfanning (via GitHub)" <gi...@apache.org> on 2024/07/07 17:25:38 UTC
[PR] SXSSF: support setting an arbitrary extra width value for column widths [poi]
pjfanning opened a new pull request, #657:
URL: https://github.com/apache/poi/pull/657
see #541
It's hard to calculate a default width for SXSSF columns. The current calculated widths might be too small. This setting lets users add an arbitrary extra width to the generated column widths. It is one value for all columns.
There might be an argument to allow this setting to be set for individual columns.
* The value must be set before you start adding rows the sheet for it to be properly applied.
* Negative values are allowed but not encouraged
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] SXSSF: support setting an arbitrary extra width value for column widths [poi]
Posted by "jkmcl (via GitHub)" <gi...@apache.org>.
jkmcl commented on PR #657:
URL: https://github.com/apache/poi/pull/657#issuecomment-2585676416
@pjfanning Yes, my test code created a file with a wider column when `setArbitraryExtraWidth` was called using https://github.com/apache/poi/commit/9eda2463986e817d8c4ebbc6f51d33c06311a86c
Thanks!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] SXSSF: support setting an arbitrary extra width value for column widths [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #657:
URL: https://github.com/apache/poi/pull/657#issuecomment-2585290696
@jkmcl It looks like the 5.4.0 arbitrary extra width code doesn't work. I reimplemented it in https://github.com/apache/poi/commit/9eda2463986e817d8c4ebbc6f51d33c06311a86c
Would you be able to try that change?
The original 5.4.0 change was never really completed or reviewed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] SXSSF: support setting an arbitrary extra width value for column widths [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #657:
URL: https://github.com/apache/poi/pull/657#issuecomment-2301835846
merged with https://github.com/apache/poi/commit/41453f3916fefd469cfa554dcb5ca069d221b331
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] SXSSF: support setting an arbitrary extra width value for column widths [poi]
Posted by "jkmcl (via GitHub)" <gi...@apache.org>.
jkmcl commented on PR #657:
URL: https://github.com/apache/poi/pull/657#issuecomment-2583546863
@pjfanning May I ask why using the new method `setArbitraryExtraWidth` introduced by this PR makes no difference in the code below?
```java
private static void createFile(Path path, boolean extraWidth) throws IOException {
try (var workbook = new SXSSFWorkbook()) {
var sheet = workbook.createSheet();
if (extraWidth) {
// *** Call the new method here ***
sheet.setArbitraryExtraWidth(SheetUtil.getDefaultCharWidthAsFloat(workbook) * 2);
}
sheet.trackColumnForAutoSizing(0);
var row = sheet.createRow(0);
row.createCell(0).setCellValue("This is a very long text that will exceed default column width for sure.");
sheet.autoSizeColumn(0);
try (var stream = Files.newOutputStream(path)) {
workbook.write(stream);
}
}
}
@Test
void mainTest() throws IOException {
var outDir = Path.of("target/test-output");
Files.createDirectories(outDir);
createFile(outDir.resolve("no_extra_width.xlsx"), false);
createFile(outDir.resolve("extra_width.xlsx"), true);
}
```
The above `@Test` method creates two files with almost the same code path except that `setArbitraryExtraWidth` is not called when creating `no_extra_width.xlsx`. I was expecting the width of the first column in this file to be shorter but it turned out to be the same in both files:

Does some condition need to be met for the extra width to be honored?
FYI, I ran the code on a Windows 10 machine with Eclipse Temurin JDK 17.0.13. The complete Maven project containing the code can be found here: https://github.com/jkmcl/poi-sample
Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
Re: [PR] SXSSF: support setting an arbitrary extra width value for column widths [poi]
Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning closed pull request #657: SXSSF: support setting an arbitrary extra width value for column widths
URL: https://github.com/apache/poi/pull/657
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org