可以合并的哦。你这个表格比较复杂,做起来不是一下就弄完的啊,就提供一个思路吧。如下:
(这个需要apache 的 poi hssf jar包,先下下来)
实例代码如下哦:
HSSFWorkbook wb = new HSSFWorkbook();//创建excel文件
HSSFSheet sheet = wb.createSheet(“sheetName”) ;//创建sheet
sheet.addMergedRegion(new CellRangeAddress(4, 5, 0, 0));//合并单元格
不明白的再@我哦。
追问用了poi但是不弹出保存提示框
上面是jsp的代码,exportAllExcelin()方法是导出excel,返回一个HSSFWorkbook,但是现在不弹出保存框,大神,在线等解答
追答可以的哦 弹出保存提示框 代码如下哦:
File f = new File(outputName);
JFileChooser fileChooser = new JFileChooser(".");
// 初始化默认文件路径
fileChooser.setCurrentDirectory(new File("D://"));
// 设置文件夹选择框模式
fileChooser.setDialogType
(JFileChooser.SAVE_DIALOG | JFileChooser.DIRECTORIES_ONLY);
// 设置弹出框标题
fileChooser.setDialogTitle("导出绩效信息?");
fileChooser.setSelectedFile(f);
int ret = fileChooser.showDialog(null, "保存");
if (ret == JFileChooser.APPROVE_OPTION) {
// 文件夹路径
// System.out.println(fileChooser.getSelectedFile().getAbsolutePath());
outputPath = fileChooser.getSelectedFile().getAbsolutePath();
}
HttpServletRequest req = ServletActionContext.getRequest();
String path = req.getSession().getServletContext().getRealPath("/");
String outputfile = outputPath + ".xls";
FileOutputStream fileOut = new FileOutputStream(outputfile);
//.....
wb.write(fileOut);// 写入表格对象
fileOut.close();// 关闭文件流
return "exportSuccess";
追问最后一个问题,你有没有能上传或者打开模板,然后写入数据再导出的demo;就是不用自己设计excel,把模板上传 就行了,有这个工具类么?采纳你的答案了
追答没有,你可以自己做一个上传 然后把文件路径换掉就ok了吧。这样就不需要合并单元格了