【发布时间】:2018-01-08 12:11:24
【问题描述】:
我有记录集,其中包含列产品和状态。
例如:
Product Status
salt good
sugar bad
salt bad
sugar good
sugar good
稍后在报告中我需要根据状态进行总结,像这样
summary good
product_code sum
sugar 2
salt 1
summary bad
product_code sum
sugar 1
salt 1
我正在用excel做报告,根据我读到的内容,我可以确定使用多少盐好或坏
Collections.frequency(collection, key)
来自here
所以我想我必须区分好坏列表,然后计算存在多少盐、糖和任何其他产品。这就是我现在的进度
rs = impl.showOnlyColumn(query);;
ResultSetMetaData metaData = rs.getMetaData();
int colProduct = 0;
int colStatus = 0;
String dataProd="";
String dataStat="";
Map<String, String[]> mapinData= new HashMap<String, String[]>();
//making column name on excel
int columnCount = metaData.getColumnCount();
for (int column = 1; column <= columnCount; column++) {
label = new Label(column - 1, 2, metaData.getColumnName(column));
excelSheet.addCell(label);
// check if column is product or status
String columnName = metaData.getColumnName(column).toLowerCase();
if (columnName.contains("produ")) {
colProduct = column;
} else if (columnName.contains("status")) {
colStatus = column;
}
}
//render the data
int r = 3;
while (rs.next()) {
for (int column = 0; column <= columnCount - 1; column++) {
String cellValue = (rs.getString(column + 1) == null ? "" : rs.getString(column + 1));
label = new Label(column, r, cellValue);
excelSheet.addCell(label);
if (column == colProduct) {
dataProd = cellValue;
}else if (column==colStatus) {
dataStat = cellValue;
}
}
mapinData.put(dataStat,dataProd);
r++;
}
myFirstWbook.write();
问题是我不知道如何根据状态名称创建一个数组
mapinData.put(dataStat,how to make array here?);
然后我将获取数组,用于计算具有该状态的产品的总和
如果有什么我描述不好的地方请告诉我,非常感谢你的帮助。
【问题讨论】:
-
改用
Map<String, List<String>>。