1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > POI跨列合并单元格兼容性问题

POI跨列合并单元格兼容性问题

时间:2019-07-05 12:32:40

相关推荐

POI跨列合并单元格兼容性问题

wps的对poi合并的单元生成的word无效,

解决方法:

在服务器中生成word文件然后使用jacob插件重新保存一下在下载就可以解决

file = new File(filePath + fileName); //在服务器中保存的文件

// 重新保存文件

Object doc;

Variant f;

ActiveXComponent app = new ActiveXComponent("Word.Application");

try {

app.setProperty("Visible", new Variant(false));

Dispatch docs = app.getProperty("Documents").toDispatch();

doc = Dispatch.invoke(docs, "Open", 1, new Object[] { filePath + fileName, new Variant(false), new Variant(true) }, new int[3]).toDispatch();

Dispatch.call(app.getProperty("Selection").toDispatch(), "EndKey", new Object[] { new Variant(6) });

file = new File(filePath + "new\\");

if (file.mkdirs()) {

file.mkdirs();

}

Dispatch.invoke((Dispatch) doc, "SaveAs", 1, new Object[] { filePath + "new\\" + fileName, new Variant(1) }, new int[3]);

f = new Variant(false);

} catch (Exception e) {

throw new RuntimeException("重新保存失败:" + e);

} finally {

app.invoke("Quit", new Variant[0]);

}

file.delete();

try {

file = new File(filePath + "new\\" + fileName);//保存后的文件

InputStream fis = new FileInputStream(file);

byte[] buffer = new byte[fis.available()];

fis.read(buffer);

fis.close();

// 清空response

response.reset();

fileName = "文件名称.docx";

// 1.设置文件ContentType类型,这样设置,会自动判断下载文件类型

// response.setContentType("multipart/form-data");

// response.setContentType("application/x-ppt;charset=GBK");

// 2.设置文件头:最后一个参数是设置下载文件名(假如我们叫a.pdf)

response.setHeader("Content-Disposition", "attachment;fileName=" + Encodes.urlEncode(fileName));

response.setHeader("Content-type", "application-download");

response.setCharacterEncoding("utf-8");

OutputStream toClient = new BufferedOutputStream(response.getOutputStream());

// 下载ppt文件

toClient.write(buffer);

toClient.flush();

toClient.close();

file.delete();

} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。