/**
* 计算驻留时长返回的记录
* col to rows
* 2011-11-4
* @param list
* @param mulColF 需要转换的列
* @param groupKeyF 分组的字段
* @param calcValueF需计算结果的字段
* @return 返回最终需要展示的结果集
* List<HashMap<String,Object>>
* Yang,Hualong
*/
public static List<HashMap<String,Object>> calcZzbbZl(List<HashMap<String,Object>> list,String mulColF,String[] groupKeyF,String[] calcValueF){
LinkedHashMap<String,HashMap<String,Object>> tempMap = new LinkedHashMap(100);
LinkedHashSet<String> prefixKeys = new LinkedHashSet<String>();
LinkedHashSet<String> suffixKeys = new LinkedHashSet<String>();
String suffix = "H";
for(int i = 0 ;i < list.size();i++){
HashMap<String,Object> record = list.get(i);
String key = record.get(mulColF).toString();
String others = "";
for(int j = 0 ;j < groupKeyF.length;j++){
others+= record.get(groupKeyF[j]).toString()+suffix;
//System.out.println(others);
}
prefixKeys.add(others);//sid Key
suffixKeys.add(key);//statykey
tempMap.put(others+key, record);//
}
List<HashMap<String,Object>> retrunList = new ArrayList<HashMap<String,Object>>();
// System.out.println("otherKeys:"+otherKeys);//sidKey
// System.out.println("mainKeys:"+mainKeys);//hourKey
// System.out.println("map:"+map);
for(String row:prefixKeys){//sid
Double sumtotal=0d;//获取每个小区下面的合计值
HashMap<String,Object> newRecord = new HashMap<String,Object>(100);
HashMap<String,Object> containValueRecord = new HashMap<String,Object>(100);
for(String col: suffixKeys){//stathours
String key = (row+col);
HashMap<String,Object> temp = tempMap.get(key);
if(temp==null){
continue;
}
for(int i = 0 ;i < groupKeyF.length;i++){//sid
newRecord.put(groupKeyF[i], temp.get(groupKeyF[i]));
}
for(int i = 0 ;i < calcValueF.length;i++){//total
for (int j = 1; j < MAX_STATHOURS; j++) {
if(j==new Integer(col)){//如果当前
//System.out.println(col+suffix+":"+temp.get(calcValueF[i]));
containValueRecord.put(col+suffix,temp.get(calcValueF[i]));
sumtotal+=(Double)temp.get(calcValueF[i]);
}else{
newRecord.put(j+suffix,0);
//System.out.println(j+suffix+":"+0);
}
}
}
}
System.out.println("newRecord2:"+containValueRecord);
System.out.println("size:"+newRecord.size());
newRecord.putAll(containValueRecord);
newRecord.put("stotal", sumtotal);//合计值
retrunList.add(newRecord);
}
return retrunList;
}
分享到:
相关推荐
row < image.rows; row++) { for (int col = 0; col ; col++) { // 访问像素 cv::Vec3b pixel = image.at(row, col); int blue = pixel.val[0]; int green = pixel.val[1]; int red = pixel.val[2]; // ...
INSERT (Pk_Col, Col1, Col2, Col3) VALUES (a.Pk_Col, a.Col1, a.Col2, a.Col3) WHEN MATCHED THEN UPDATE SET b.Col1 = a.Col1, b.Col2 = a.Col2, b.Col3 = a.Col3; ``` 这个`MERGE`语句会检查Tab1中的记录...
WHEN NOT MATCHED THEN INSERT (Pk_Col, Col1, Col2, Col3) VALUES (a.Pk_Col, a.Col1, a.Col2, a.Col3); ``` 这个语句根据 `Tab1` 中的记录更新或插入 `Tab` 表。 以上就是对“oracle之sqlFAQ”中涉及的SQL知识...
dataTable.Rows.Add(dataRow); } // 绑定到DataGrid dataGridView1.DataSource = dataTable; } ``` 4. **处理异常**:在实际操作中,务必考虑错误处理,比如文件不存在、权限问题、数据格式不匹配等。 5. **...
dataTable.Rows.Add(range.Cells[row, col].Value); } } dataGridView1.DataSource = dataTable; ``` 2. **使用EPPlus读取Excel**: - EPPlus是一个强大的库,它可以解析xlsx格式的Excel文件。同样,我们可以...
newWorksheet.Cells[row + 2, col + 1] = dataGridView.Rows[row].Cells[col].Value.ToString(); } ``` 3. **保存和关闭Excel**:最后,保存工作簿并关闭Excel应用程序。 ```csharp newWorkbook.SaveAs(...
For col = 1 To row If col = 1 Or col = row Then Cells(row, col).Value = 1 Else Cells(row, col).Value = Cells(row - 1, col - 1).Value + Cells(row - 1, col).Value End If Next col Next row End ...
FileInfo fileInfo = new FileInfo("path_to_your_excel_file.xlsx"); ExcelPackage.LicenseContext = LicenseContext.NonCommercial; // 如果你在非商业项目中使用EPPlus using (ExcelPackage excelPackage = new ...
dt.Rows[row - 1][col - 1] = worksheet.Cells[row, col].Value; } } // 关闭Excel对象并释放资源 workbook.Close(false); excelApp.Quit(); // 将DataTable绑定到DataGridView dataGridView1.DataSource ...
worksheet.Cells[row + 1, col + 1] = dataGridView.Rows[row].Cells[col].Value.ToString(); } } workbook.SaveAs("output.xlsx"); excelApp.Quit(); ``` - 使用Open XML SDK的示例会涉及更多的XML操作,如...
worksheet.Cells[row + 2, col + 1].Value = dataTable.Rows[row][col]; } } // 保存更改 excelPackage.Save(); } ``` 这段代码创建了一个新的Excel文件,添加了一个名为"Sheet1"的工作表,并将DataTable中的...
dataRow[col - 1] = dataRange.Cells[row, col].Value2; } dataTable.Rows.Add(dataRow); } // 关闭并释放Excel资源 workbook.Close(false); excelApp.Quit(); System.Runtime.InteropServices.Marshal....
worksheet.Cells[row + 2, col + 1] = dt.Rows[row][col].ToString(); } } ``` 3. 保存并关闭Excel: ```csharp workbook.SaveAs("output.xlsx"); workbook.Close(false); excelApp.Quit(); Marshal....
newRow[col - 1] = worksheet.Cells[row, col].Value; } dt.Rows.Add(newRow); } // 关闭Excel资源 workbook.Close(false); excelApp.Quit(); ``` 2. 使用EPPlus,代码更为简洁: ```csharp using OfficeOpenXml...
For i = 0 To FlexGrid1.Rows - 1 If (i Mod 2) = 0 Then FlexGrid1.CellBackColor(i, 0) = vbWhite ' 偶数行白色背景 Else FlexGrid1.CellBackColor(i, 0) = vbLightGray ' 奇数行灰色背景 End If Next i ``` ...
For row As Integer = 0 To FlexGrid.Rows - 2 ' 跳过合计行 If IsNumeric(FlexGrid.TextMatrix(row, col)) Then total += CDbl(FlexGrid.TextMatrix(row, col)) End If Next FlexGrid.TextMatrix(FlexGrid....
row <= range.Rows.Count; row++) { for (int col = 1; col ; col++) { object cellValue = range.Cells[row, col].Value2; Console.WriteLine($"Row: {row}, Col: {col}, Value: {cellValue}"); } } ``` 请...
worksheet.Cells[row + 2, col + 1].Value = dt.Rows[row][col]; package.Save(); } } ``` 通过上述方法,您可以根据具体需求选择适合的方式将DataTable导出为Excel文件。提供的源码可能包含了这两种或其中一...
For col1 = 0 To col2 - 1 yval = shujuji.Tables(0).Rows(col1).Item("值") xval = shujuji.Tables(0).Rows(col1).Item("坐标") Chart1.Series(0).Points.AddXY(xval, yval) ' 添加数据点 Next col1 End If ``...
newRow[col - 1] = dataRange.Cells[row, col].Value2; } dataTable.Rows.Add(newRow); } // 设置数据源 dataGridView.DataSource = dataTable; ``` 5. **错误处理与资源释放** 在读取过程中,需要注意错误...