highcharts 批量下载;批量导出图片到Excel
-
jar---------------------------------------------------------
所需要jar包batik-all-1.7.jar xml-apis-ext-1.3.04.jar
链接: https://pan.baidu.com/s/1FkLvC7dnXdLla5FASpjEKw 提取码: 71aq 复制这段内容后打开百度网盘手机App,操作更方便哦
如果这个下载不下来就选择网址里的包,下面这个==! 用啥引入啥,会有一些依赖包自动下载(Maven Repository: batik)。
<!-- <dependency> -->
<!-- <groupId>org.apache.batik</groupId> -->
<!-- <artifactId>batik-svg-dom</artifactId> -->
<!-- <version>1.7</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.batik</groupId> -->
<!-- <artifactId>batik-dom</artifactId> -->
<!-- <version>1.7</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.batik</groupId> -->
<!-- <artifactId>batik-transcoder</artifactId> -->
<!-- <version>1.7</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.batik</groupId> -->
<!-- <artifactId>batik-util</artifactId> -->
<!-- <version>1.7</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.batik</groupId> -->
<!-- <artifactId>batik-bridge</artifactId> -->
<!-- <version>1.7</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.batik</groupId> -->
<!-- <artifactId>batik-css</artifactId> -->
<!-- <version>1.7</version> -->
<!-- </dependency> -->
<!-- <dependency> -->
<!-- <groupId>org.apache.batik</groupId> -->
<!-- <artifactId>batik-gvt</artifactId> -->
<!-- <version>1.7</version> -->
<!-- </dependency> -->
- -----------------------JavaScript-------------------------------
var charArray = new Array();
function inHighcharts(id,chars,fig,figType){
charObj=Highcharts.chart(id, {
……});
charArray[charArray.length] = charObj;
}
//批量下载图片
$scope.allLoad=function(){
for(var i =0;i<charArray.length;i++){
for(var key in charArray[i]){
(function(i) {
setTimeout(function(){
charArray[i].exportChart({
type: 'image/png',//application/pdf
filename: 'my-pdf'+i
})
}, (i + 1) * 1000);
})(i)
break;
}
}
}
// 批量导出excel
function(){
……
avgs[i] = charArray[i].getSVG();//获取Highcharts 图形参数传后台
……
//Ajax调用后台,传值 avgs
}
- ----------------------java后台---------------------------------------
package com.qhky.query.bo;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;
import org.apache.batik.transcoder.TranscoderException;
import org.apache.batik.transcoder.TranscoderInput;
import org.apache.batik.transcoder.TranscoderOutput;
import org.apache.batik.transcoder.image.PNGTranscoder;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.ClientAnchor;
import org.apache.poi.ss.usermodel.Drawing;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Picture;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFClientAnchor;
import org.apache.poi.xssf.usermodel.XSSFFont;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
……
/***
* 多值导出EXCEL Author:zhouyf Date:2017/9/12
*/
public class QQ0101E03BO extends BaseBo<QQ0101E03InDto, DownloadFileOutDto> {
@Override
protected CheckParamResult checkParam(QQ0101E03InDto arg0, LServerEnv arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
protected DownloadFileOutDto execute(QQ0101E03InDto inDto, LServerEnv arg1) {
// TODO Auto-generated method stub
DownloadFileOutDto out = new DownloadFileOutDto();
XSSFWorkbook workbook = null;
try {
workbook = new XSSFWorkbook();
if (workbook != null) {
Sheet sheet = workbook.createSheet("多值查询");
int index = 0;
int rowNum = 0;
CellStyle style = getStyle(workbook);
CellStyle style1 = getStyle1(workbook);
CellStyle styleQuota=getStyleQuotaName(workbook);
CellStyle styleTitle=getTitleStyle(workbook);
for (QQ0101E03Dto m : inDto.getExportData()) {
Row row = sheet.createRow(rowNum);
Cell cell = row.createCell(0, Cell.CELL_TYPE_STRING);
cell.setCellStyle(styleQuota);
cell.setCellValue(m.getQuotaName() == null ? "无" : m.getQuotaName());
/*Cell cell0 = row.createCell(1, Cell.CELL_TYPE_STRING);
cell0.setCellStyle(style);
cell0.setCellValue(m.getQuotaName() == null ? "无" : m.getQuotaName());*/
rowNum = rowNum + 1;
if (m.getParams() != null) {
for (String key : m.getParams().keySet()) {
Row row1 = sheet.createRow(rowNum);
Cell cell1 = row1.createCell(0, Cell.CELL_TYPE_STRING);
cell1.setCellStyle(style);
cell1.setCellValue(key + ":"+(m.getParams().get(key