diff --git a/src/main/java/cokr/xit/base/docs/xls/CellDef.java b/src/main/java/cokr/xit/base/docs/xls/CellDef.java index 3955fc3..31c502f 100644 --- a/src/main/java/cokr/xit/base/docs/xls/CellDef.java +++ b/src/main/java/cokr/xit/base/docs/xls/CellDef.java @@ -134,6 +134,7 @@ public class CellDef { */ public CellDef setWidth(int width) { this.width = width; + setWidth(); return this; } @@ -150,6 +151,12 @@ public class CellDef { */ public CellDef setValue(Object value) { this.value = value; + setWidth(); return this; } + + private void setWidth() { + if (value instanceof Style style) + style.width(width); + } } \ No newline at end of file diff --git a/src/main/java/cokr/xit/base/docs/xls/Style.java b/src/main/java/cokr/xit/base/docs/xls/Style.java index ab4e740..c31d773 100644 --- a/src/main/java/cokr/xit/base/docs/xls/Style.java +++ b/src/main/java/cokr/xit/base/docs/xls/Style.java @@ -51,6 +51,10 @@ public class Style { private Font font; private String dataFormat; + public int width() { + return width != null ? width : 0; + } + /**열의 폭을 설정한다. * @param chars 열의 폭. 한번에 보여지는 문자수 * @return 현재 Style @@ -60,6 +64,10 @@ public class Style { return this; } + public short height() { + return height != null ? height : 0; + } + /**행의 높이를 설정한다. * @param height 행의 높이 * @return 현재 Style diff --git a/src/main/java/cokr/xit/base/docs/xls/XLSWriter.java b/src/main/java/cokr/xit/base/docs/xls/XLSWriter.java index b4f5016..c223b4f 100644 --- a/src/main/java/cokr/xit/base/docs/xls/XLSWriter.java +++ b/src/main/java/cokr/xit/base/docs/xls/XLSWriter.java @@ -5,6 +5,7 @@ import java.io.FileOutputStream; import java.io.OutputStream; import java.util.Collections; import java.util.Date; +import java.util.LinkedHashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -275,6 +276,16 @@ public class XLSWriter extends XLS { if (style.dataFormat() != null) { cellStyle.setDataFormat(workbook.createDataFormat().getFormat(style.dataFormat())); } + + int width = style.width(); + if (width > 0) { + int column = cell.getColumnIndex(); + worksheet.setColumnWidth(column, width * 256); + } + + short height = style.height(); + if (height > 0) + row.setHeight(height); } return cellStyle; } @@ -298,7 +309,7 @@ public class XLSWriter extends XLS { */ public XLSWriter trackWidth(int... cols) { if (!isEmpty(cols)) - worksheet.trackColumnsForAutoSizing(trackWidths = IntStream.of(cols).boxed().collect(Collectors.toSet())); + worksheet.trackColumnsForAutoSizing(trackWidths = IntStream.of(cols).boxed().collect(Collectors.toCollection(LinkedHashSet::new))); return this; } @@ -342,6 +353,8 @@ public class XLSWriter extends XLS { @Override protected void clear(boolean all) { + if (trackWidths != null) + worksheet.untrackColumnsForAutoSizing(trackWidths); super.clear(all); trackWidths = null; }