From 0993fd0dc2bf385511d52f5aa31d5591f5a6c539 Mon Sep 17 00:00:00 2001 From: "jakub.kowalczyk" Date: Tue, 19 Dec 2023 11:40:55 +0100 Subject: [PATCH 1/2] Fixed auto column width adjustment --- .../src/main/java/org/dhatim/fastexcel/Worksheet.java | 3 ++- .../test/java/org/dhatim/fastexcel/CorrectnessTest.java | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java index 32519d3c..b5799d31 100644 --- a/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java +++ b/fastexcel-writer/src/main/java/org/dhatim/fastexcel/Worksheet.java @@ -785,8 +785,9 @@ private void writeCols(Writer w, int maxCol) throws IOException { } boolean isHidden = hiddenColumns.contains(c); boolean hasStyle = colStyles.containsKey(c); + boolean widthChanged = colWidths.containsKey(c) || maxWidth > DEFAULT_COL_WIDTH; int groupLevel = groupColums.get(c); - if (colWidths.containsKey(c) || isHidden || groupLevel!=0 || hasStyle) { + if (widthChanged || isHidden || groupLevel != 0 || hasStyle) { if (!started) { w.append(""); started = true; diff --git a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java index afcb49d8..0d385051 100644 --- a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java +++ b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java @@ -19,6 +19,8 @@ import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.math.BigDecimal; import java.time.*; @@ -699,6 +701,7 @@ void testColumnStyle() throws Exception { worksheet.style(1).bold().set(); worksheet.style(1).fillColor(Color.BLACK).set(); worksheet.style(1, 1).fillColor(Color.BLUE_GRAY).set(); + worksheet.value(1, 1, "test"); worksheet.style(2).format("dd/MM/yyyy").set(); @@ -706,6 +709,7 @@ void testColumnStyle() throws Exception { .style().horizontalAlignment("left").fontColor(Color.ALMOND) .set(); worksheet.style(3).horizontalAlignment("center").set(); + worksheet.value(3, 3, "long test, long test, long test"); worksheet.style(4) .borderColor(BorderSide.RIGHT, BLACK) @@ -748,7 +752,11 @@ void testColumnStyle() throws Exception { worksheet.style(12) .fillColor(Color.YELLOW) .set(new ConditionalFormattingExpressionRule("L1>1", false)); + + worksheet.value(4, 13, "not long"); + worksheet.value(4, 14, "not long long long long long"); }); } + } From 481ba3dd9b1d097c10362b4a978108ee64da808d Mon Sep 17 00:00:00 2001 From: "jakub.kowalczyk" Date: Tue, 19 Dec 2023 11:41:09 +0100 Subject: [PATCH 2/2] Fixed auto column width adjustment --- .../src/test/java/org/dhatim/fastexcel/CorrectnessTest.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java index 0d385051..aa92fff3 100644 --- a/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java +++ b/fastexcel-writer/src/test/java/org/dhatim/fastexcel/CorrectnessTest.java @@ -19,8 +19,6 @@ import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.math.BigDecimal; import java.time.*;