在Excel POI上制定具体的path
我想制作一个保存在数据库中的path。
这是我的代码。
@RequestMapping("import_excel") @ResponseBody public Map<String, ? extends Object> import_excel() { modelMap.clear(); try { HttpSession session = req.getSession(); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet("Export"); Row row1 = sheet.createRow((short) 3); row1.createCell(0).setCellValue("Asset Number"); row1.createCell(1).setCellValue("Asset Barcode"); row1.createCell(2).setCellValue("Asset Name"); short i = 4; Row row2 = sheet.createRow(i++); row2.createCell(0).setCellValue(as.getCdas()); row2.createCell(1).setCellValue(as.getBcd()); row2.createCell(2).setCellValue(as.getNm()); FileOutputStream fileOut = new FileOutputStream(src + "/Export.xls"); wb.write(fileOut); fileOut.close(); modelMap.put("success", true); modelMap.put("rows", obj); modelMap.put("count", count); } catch (IOException ex) { modelMap.put("success", false); modelMap.put("msg", ex.getMessage()); } return modelMap; }
我想让FileOutputStream fileOut = new FileOutputStream(src +“/Export.xls”);
与我保存在数据库中的path。 所以如果我想改变path,我只是在数据库中更改。
我试过上面的代码,但似乎不工作。
请帮帮我。 谢谢 :)
我会build议以编程方式使用它…
使用
String PathTillProject = System.getProperty("user.dir");
这会给你的系统path一级到src
即直到你的项目(我假设你的src
只是在你的项目目录中)。 例如,如果您的项目名称是TestProject
则位置或src
是TestProject/src
。 现在你可以像这样使用它:
String PathTillProject = System.getProperty("user.dir"); FileOutputStream fileOut = new FileOutputStream(PathTillProject + "/src/Export.xls");
- 什么样的头部签名是0x7473657571655220?
- 如何使用Apache POI打印(通过打印机)Excel表格
- 如何在Java上的JTable中填充一些Excel的行?
- 读取XLSB文件的exceptionApache POI java.io.CharConversionException
- apache POI MS Office Excel无法打开字体颜色设置Excel文件
- 如何知道在Java中的Excel文件版本?
- 如何将Excel工作表的内容embedded到javamail中的电子邮件中?
- Java的Apache POI打开文件?
- Apache poi HSSFWorkbook将覆盖XLS模板中的样式