0
我有一個資產POJO的Apache POI的Excel打印小計:在一個特定的順序
public class Asset implements Serializable {
//serialVersionUID
private String quarter;
private String assetType;
private BigDecimal assetAttributes;
// more assetAttributes like price, etc, getters and setters
}
,然後我有這樣的方法,它這個POJO和Apache的POI表的列表,並將列表內容寫入片材:
public void addContent (List<Asset> listOfAsset, Sheet sheet) {
//make a row counter and a cell counter
SortedSet<String> quarters = new TreeSet<String>();
for (Asset asset : listOfAsset) {
quarters.add(asset.getQuarter());
//write content to sheet
row.createCell().setCellValue();
}
addSubtotals();
}
然後我有addSubtotals方法,它必要的信息,並做了SUMIF式:
private void addSubtotals (//params) {
for (String s : quarters) {
Row row = sheet.createRow(rowCounter++);
row.createCell(0).setCellValue(// quarter);
for (int i = 2; i < cellCounter; i++) {
row.createCell(i).setCellFormula(
"SUMIF(// if the printed quarter equals the one in the quarters set,
then add all the attributes for all asset types)");
}
}
}
,這一切都工作正常,除了小計都在列表的底部。我如何在每季度完成小計?我不知道會有多少個季度,或者每個季度會有多少種資產類型。
我考慮將小計方法放入for循環來添加內容,但我無法執行SUMIF,因爲宿舍數量和資產類型未知。我可能會做一個TreeMap,但我不確定細節。