숫자포맷 수정, 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.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Date; import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.Consumer; import java.util.function.Consumer;
import java.util.function.Function; 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.BorderStyle;
import org.apache.poi.ss.usermodel.CellStyle; import org.apache.poi.ss.usermodel.CellStyle;
@ -438,7 +443,7 @@ public class XLSWriter extends XLS {
* @return ( , ) * @return ( , )
*/ */
public CellStyle n_nn0() { public CellStyle n_nn0() {
return cellStyle(new Styler().alignment(HorizontalAlignment.RIGHT).dataFormat("#,###")); return cellStyle(new Styler().alignment(HorizontalAlignment.RIGHT).dataFormat("#,##0"));
} }
/** ( , , 2 ) . /** ( , , 2 ) .
@ -469,6 +474,19 @@ public class XLSWriter extends XLS {
return cellStyle(new Styler().dataFormat("HH:mm:ss").merge(Styler.CENTER)); 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 } . /** . {@link #set(CellStyle) CellStyle } .
* @author mjkhan * @author mjkhan
*/ */
@ -791,4 +809,32 @@ public class XLSWriter extends XLS {
return this; 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