mobile CCTV,mobile surveillance,police body worn cameras
标题:
写Excel文件后,电脑上必须手动插拔一次连接线才能看到文件变化,什么原因
[打印本页]
author:
cus6
time:
2023-10-19 20:27
标题:
写Excel文件后,电脑上必须手动插拔一次连接线才能看到文件变化,什么原因
代码如下,做了Flush之类的操作依然不行:
public static void exportEquipBindToExcel(List<EquipBind> equipBindList, String filePath,Context context) {
try (HSSFWorkbook workbook = new HSSFWorkbook ();
FileOutputStream fileOut = new FileOutputStream(filePath)) {
Sheet sheet = workbook.createSheet("设备数据");
String yearMonth=getCurrentYearMonth();
// 创建标题行
Row headerRow = sheet.createRow(0);
String[] headers = {"a", "b"};
for (int i = 0; i < headers.length; i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(headers[i]);
}
Map<Integer, String> equipTypeMap = new HashMap<>();
EquipTypeDao equipTypeDao=new EquipTypeDao(context);
equipTypeDao.open();
List<EquipType> equipTypeList=equipTypeDao.getEquipTypes("",new String[]{},"");
for (EquipType equipType : equipTypeList) {
long id = equipType.getId();
String equipTypeName = equipType.getEquipTypeName();
// 将 Id 和 EquipTypeName 存储到 Map 中
equipTypeMap.put((int)id, equipTypeName);
}
// 填充数据
for (int i = 0; i < equipBindList.size(); i++) {
EquipBind equipBind = equipBindList.get(i);
Row row = sheet.createRow(i + 1); // 创建新行,注意标题行已经占用了第一行
row.createCell(0).setCellValue(i+1);
row.createCell(1).setCellValue(equipBind.getSecondaryNumber());
}
equipTypeDao.close();
workbook.write(fileOut);
fileOut.flush();
fileOut.getFD().sync(); // 强制刷新文件系统缓存
fileOut.close();
workbook.close();
MediaScannerConnection.scanFile(context, new String[] { filePath}, null, null);
} catch (IOException e) {
e.printStackTrace();
}
}
copycode
欢迎光临 mobile CCTV,mobile surveillance,police body worn cameras (http://bbs.besovideo.com:8067/)
Powered by Discuz! X3.2