숫자포맷 수정, CellDef 추가

master
mjkhan21 11 months ago
parent 73835fc552
commit b1a60f4651

@ -5,9 +5,14 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle;
@ -438,7 +443,7 @@ public class XLSWriter extends XLS {
* @return ( , )
*/
public CellStyle n_nn0() {
return cellStyle(new Styler().alignment(HorizontalAlignment.RIGHT).dataFormat("#,###"));
return cellStyle(new Styler().alignment(HorizontalAlignment.RIGHT).dataFormat("#,##0"));
}
/** ( , , 2 ) .
@ -469,10 +474,23 @@ public class XLSWriter extends XLS {
return cellStyle(new Styler().dataFormat("HH:mm:ss").merge(Styler.CENTER));
}
public List<Object> header(Iterable<CellDef> defs, Supplier<Styler> factory) {
ArrayList<Object> result = new ArrayList<>();
for (CellDef def: defs) {
result.add(def.label);
Styler styler = factory.get();
styler.width(def.width);
result.add(styler);
}
return result;
}
/** . {@link #set(CellStyle) CellStyle } .
* @author mjkhan
*/
public static class Styler {
public static class Styler {
/** 빈 스타일 */
public static final Styler NONE = new Styler().seal();
/** 좌측 정렬 */
@ -791,4 +809,32 @@ public class XLSWriter extends XLS {
return this;
}
}
/**
* @author mjkhan
*/
public static class CellDef {
public static final Map<String, CellDef> toMap(CellDef... defs) {
return Stream.of(defs).collect(Collectors.toMap(
def -> def.label,
def -> def,
(k1, k2) -> k1,
LinkedHashMap::new
));
}
private String label;
private int width;
private Object value;
public CellDef(String label, int width, Object value) {
this.label = label;
this.width = width;
this.value = value;
}
public Object getValue() {
return value;
}
}
}
Loading…
Cancel
Save