2 个解决方案
#2
刚做了这个,我用的echarts报表首先把jsp页面的报表生成图片保存在本地
setTimeout(exportImage, 3000);
function exportImage(){
var data = "a="+encodeURIComponent(myChart.getDataURL("png"));
var name="办学类型统计信息(按学段)";
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST",main.config.wordUrl,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
};
xmlhttp.send(data+"&name="+name);
}
然后后台,解析图片,这里的,main.config.wordUrl指向后台action
public String getPictures(){
String a = request.getParameter("a");
String filename =request.getParameter("name");
String fileResult="";
if(!filename.isEmpty()){
filename+=".png";
}
try {
String[] url = a.split(",");
String u = url[1];
// Base64解码
byte[] b = new BASE64Decoder().decodeBuffer(u);
// String realPath = request.getSession().getServletContext().getRealPath("/");
String fileStr = saveFile();
// 生成图片
OutputStream out = new FileOutputStream(new File(fileStr+File.separator+filename));
fileResult=fileStr+File.separator+filename;
out.write(b);
out.flush();
out.close();
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
然后在导出的word中插入这张图片,我这里用的是jacob,最后生成word可以转换成html或者pdf格式
setTimeout(exportImage, 3000);
function exportImage(){
var data = "a="+encodeURIComponent(myChart.getDataURL("png"));
var name="办学类型统计信息(按学段)";
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST",main.config.wordUrl,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
};
xmlhttp.send(data+"&name="+name);
}
然后后台,解析图片,这里的,main.config.wordUrl指向后台action
public String getPictures(){
String a = request.getParameter("a");
String filename =request.getParameter("name");
String fileResult="";
if(!filename.isEmpty()){
filename+=".png";
}
try {
String[] url = a.split(",");
String u = url[1];
// Base64解码
byte[] b = new BASE64Decoder().decodeBuffer(u);
// String realPath = request.getSession().getServletContext().getRealPath("/");
String fileStr = saveFile();
// 生成图片
OutputStream out = new FileOutputStream(new File(fileStr+File.separator+filename));
fileResult=fileStr+File.separator+filename;
out.write(b);
out.flush();
out.close();
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
然后在导出的word中插入这张图片,我这里用的是jacob,最后生成word可以转换成html或者pdf格式
#1
楼主可以实现 PDF格式,
点击
#2
刚做了这个,我用的echarts报表首先把jsp页面的报表生成图片保存在本地
setTimeout(exportImage, 3000);
function exportImage(){
var data = "a="+encodeURIComponent(myChart.getDataURL("png"));
var name="办学类型统计信息(按学段)";
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST",main.config.wordUrl,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
};
xmlhttp.send(data+"&name="+name);
}
然后后台,解析图片,这里的,main.config.wordUrl指向后台action
public String getPictures(){
String a = request.getParameter("a");
String filename =request.getParameter("name");
String fileResult="";
if(!filename.isEmpty()){
filename+=".png";
}
try {
String[] url = a.split(",");
String u = url[1];
// Base64解码
byte[] b = new BASE64Decoder().decodeBuffer(u);
// String realPath = request.getSession().getServletContext().getRealPath("/");
String fileStr = saveFile();
// 生成图片
OutputStream out = new FileOutputStream(new File(fileStr+File.separator+filename));
fileResult=fileStr+File.separator+filename;
out.write(b);
out.flush();
out.close();
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
然后在导出的word中插入这张图片,我这里用的是jacob,最后生成word可以转换成html或者pdf格式
setTimeout(exportImage, 3000);
function exportImage(){
var data = "a="+encodeURIComponent(myChart.getDataURL("png"));
var name="办学类型统计信息(按学段)";
var xmlhttp;
if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else { // code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("POST",main.config.wordUrl,true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function() {
};
xmlhttp.send(data+"&name="+name);
}
然后后台,解析图片,这里的,main.config.wordUrl指向后台action
public String getPictures(){
String a = request.getParameter("a");
String filename =request.getParameter("name");
String fileResult="";
if(!filename.isEmpty()){
filename+=".png";
}
try {
String[] url = a.split(",");
String u = url[1];
// Base64解码
byte[] b = new BASE64Decoder().decodeBuffer(u);
// String realPath = request.getSession().getServletContext().getRealPath("/");
String fileStr = saveFile();
// 生成图片
OutputStream out = new FileOutputStream(new File(fileStr+File.separator+filename));
fileResult=fileStr+File.separator+filename;
out.write(b);
out.flush();
out.close();
} catch (Exception e) {
// TODO: handle exception
}
return null;
}
然后在导出的word中插入这张图片,我这里用的是jacob,最后生成word可以转换成html或者pdf格式