js代码
步骤一,上传图片
$("object").each(function(index) { if(this.hasRendered()) { this.exportChart({ exportFormat: "JPEG", exportAction: "save", exportFileName: this.id, exportHandler: "bulletin-image" }); chartParams.push("chartIds=" + this.id); if (index % 2 == 0) { $("html,body").animate({ scrollTop: $(this).offset().top }, 100).delay(5500); } } else { alert("图表还未渲染完成,请稍后再试。"); chartHasRendered = false; return false; } });
步骤二,保存图片
ExportBean exportBean = FusionChartsExportHelper.parseExportRequestStream(request);BufferedImage image = ImageGenerator.getChartImage( exportBean.getStream(), exportBean.getMetadata()); String imageFileName = exportBean .getExportParameterValue("exportfilename") + ".jpg"; File imageFile = new File(Dirs.BULLETIN_DIR + imageFileName); if (!imageFile.exists()) { imageFile.mkdirs(); ImageIO.write(image, "jpeg", imageFile); }
步骤三,执行word导出,图片已经保存在服务器了,word生成只需要获得正确的图片流就可以完成
@Result(name = "success", type = "stream", params = { "contentType", "application/msword", "inputName", "bulletinDoc", "contentDisposition", "attachment;filename=${fileName}", "bufferSize", "8192" }) })