excel导出优化

This commit is contained in:
gityjf 2021-02-07 08:32:34 +08:00
parent 0d0794c52f
commit 969f7030cd
4 changed files with 60 additions and 58 deletions

View File

@ -102,15 +102,22 @@
if(sparam.length>0){sparam+=",";}
sparam+=key+"="+param[key];
}
var result=RunJavaMethodTrans("com.tenwa.officetempalte.action.CreateOfficeAction","createOfficeByTemplate",sparam);
if(result == "success"){
var attributeID = AsControl.RunJsp("/Tenwa/Lease/Flow/Rent/BatchIncome/GetLBDocAttributeID.jsp",
"FLOW_UNID="+tempParam["FLOW_UNID"]+"&OBJECTTYPE="+tempParam["OBJECTTYPE"]);
downloadFile(attributeID);
}else{
alert("µ¼³öʧ°Ü£¡");
}
//打开遮罩
openDWDialog("正在下载中...........");
$("#DWOverLayoutSubDiv").find('#sp_datawindow_overdiv_top').css('display','none');
setTimeout(function(){
var result=RunJavaMethodTrans("com.tenwa.officetempalte.action.CreateOfficeAction","createOfficeByTemplate",sparam);
//隐藏遮罩
$("#DWOverLayoutDiv").hide();
$("#DWOverLayoutSubDiv").hide();
if(result == "success"){
var attributeID = AsControl.RunJsp("/Tenwa/Lease/Flow/Rent/BatchIncome/GetLBDocAttributeID.jsp",
"FLOW_UNID="+tempParam["FLOW_UNID"]+"&OBJECTTYPE="+tempParam["OBJECTTYPE"]);
downloadFile(attributeID);
}else{
alert("导出失败!");
}
},200)
}

View File

@ -10,6 +10,7 @@ import java.util.List;
import java.util.Map;
import java.util.UUID;
import com.amarsoft.app.accounting.trans.script.invoice.output.CalcTaxAmountExecutor;
import jbo.sys.CODE_LIBRARY;
import org.apache.poi.ss.usermodel.Workbook;
@ -110,15 +111,7 @@ public class BaseExcelCallBackServiceImpl extends CreateOfficeCallBackService{
throw new BusinessException("¼ÓÔØexcelʱ³ö´í"+e.getMessage());
}
try {
ReadExcel ReadExcel=null;
try {
ReadExcel = new ReadExcel(tempfile);
} catch (Exception e) {
// TODO Auto-generated catch block
throw new BusinessException("加载ReadExcel时出");
}
ReadExcel ReadExcel= new ReadExcel(wb);
Map<String,Object> operMap=new HashMap<String, Object>();
operMap.put("default", excelSer);
@ -127,9 +120,6 @@ public class BaseExcelCallBackServiceImpl extends CreateOfficeCallBackService{
for(BizObject config:exportConfig){
configData=lableSer.getLableDataByConfig(config, model);
Class<?> oper=null;
Method replaceString=null;
Method replaceList=null;
Method replaceTable=null;
String operator_class=config.getAttribute("operatorclass").getString();
if(operator_class.length()==0||operator_class.equals("excel_default_class")){
oper=operMap.get("default").getClass();
@ -141,37 +131,24 @@ public class BaseExcelCallBackServiceImpl extends CreateOfficeCallBackService{
oper=Class.forName(code.getAttribute("itemattribute").getString());
operMap.put(operator_class, oper);
}
replaceString=oper.getMethod("replaceStringLable",Workbook.class,ReadExcel.class,BizObject.class,Map.class);
replaceList=oper.getMethod("replaceListLable",Workbook.class,ReadExcel.class,BizObject.class,Map.class);
replaceTable=oper.getMethod("replaceTableLable",Workbook.class,ReadExcel.class,BizObject.class,Map.class);
if(config.getAttribute("tagtype").getString().equals("tag_type1")){//字符串
try {
replaceString.invoke(oper.newInstance(),wb,ReadExcel,config,configData);
} catch (Exception e) {
e.printStackTrace();
InvocationTargetException targetEx = (InvocationTargetException) e;
Throwable t = targetEx.getTargetException();
throw new BusinessException(t.getMessage());
}
}else if(config.getAttribute("tagtype").getString().equals("tag_type2")){//数组
try {
replaceList.invoke(oper.newInstance(),wb,ReadExcel,config,configData);
} catch (Exception e) {
e.printStackTrace();
InvocationTargetException targetEx = (InvocationTargetException) e;
Throwable t = targetEx.getTargetException();
throw new BusinessException(t.getMessage());
}
}else if(config.getAttribute("tagtype").getString().equals("tag_type3")){//表格
try {
replaceTable.invoke(oper.newInstance(),wb,ReadExcel,config,configData);
} catch (Exception e) {
e.printStackTrace();
InvocationTargetException targetEx = (InvocationTargetException) e;
Throwable t = targetEx.getTargetException();
throw new BusinessException(t.getMessage());
}
}
try {
if(config.getAttribute("tagtype").getString().equals("tag_type1")){//×Ö·û´®
Method replaceString=oper.getMethod("replaceStringLable",Workbook.class,ReadExcel.class,BizObject.class,Map.class);
replaceString.invoke(oper.newInstance(),wb,ReadExcel,config,configData);
}else if(config.getAttribute("tagtype").getString().equals("tag_type2")){//Êý×é
Method replaceList =oper.getMethod("replaceListLable",Workbook.class,ReadExcel.class,BizObject.class,Map.class);
replaceList.invoke(oper.newInstance(),wb,ReadExcel,config,configData);
}else if(config.getAttribute("tagtype").getString().equals("tag_type3")){//±í¸ñ
Method replaceTable=oper.getMethod("replaceTableLable",Workbook.class,ReadExcel.class,BizObject.class,Map.class);
replaceTable.invoke(oper.newInstance(),wb,ReadExcel,config,configData);
}
} catch (Exception e){
InvocationTargetException targetEx = (InvocationTargetException) e;
Throwable t = targetEx.getTargetException();
throw new BusinessException(t.getMessage());
}
}
OutputStream osServer = new FileOutputStream(targetFile);
wb.write(osServer);

View File

@ -1,6 +1,7 @@
package com.tenwa.officetempalte.serviceImp;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@ -88,6 +89,18 @@ public class BaseExcelLableReplaceServiceImp implements BaseExcelLableReplaceSer
int row_index = ReadExcel.getCellRowNum(tagName);
List<List> lableData = new ArrayList<List>();
lableData = FileOperatorUtil.getJsonToList((JSONObject) model.get(tagName), valueField, isshowindex);
List<BizObject> bos = JBOFactory.getBizObjectManager(CODE_LIBRARY.CLASS_NAME).createQuery("codeno='SetNumberType' and bankno=:bankno")
.setParameter("bankno", tagName).getResultList(false);
HashSet<Integer> sets = new HashSet<>();
for (int i = 0; i < bos.size() ; i++) {
BizObject bizObject = bos.get(i);
if(bizObject.getAttribute("itemdescribe").isNull()){
continue;
}
sets.add(bizObject.getAttribute("itemdescribe").getInt());
}
if (col_index >= 0 && row_index >= 0) {
List columnIndex = new ArrayList();
columnIndex = PoiExcelUtil.getMergedRegionIndex(templateSheet,row_index - 1);
@ -102,16 +115,13 @@ public class BaseExcelLableReplaceServiceImp implements BaseExcelLableReplaceSer
for (int j = 0; j < tempvalue.size(); j++) {
cell = PoiExcelUtil.getCell(templateRow,Integer.valueOf(columnIndex.get(col_index + j).toString()));
//查询标签中是否有需要转为数字类型的列
BizObject cl = JBOFactory.getBizObjectManager(CODE_LIBRARY.CLASS_NAME).createQuery(
"codeno='SetNumberType' and bankno=:bankno and itemdescribe=:itemdescribe ").setParameter("bankno", tagName).setParameter("itemdescribe", j).getSingleResult(false);
if (cl != null) {
if(sets.size()>0 && sets.contains(j)){
String amount = tempvalue.get(j).toString().replace(",", "");
Double b = Double.parseDouble(amount);
cell.setCellValue(b);
} else {
cell.setCellValue(tempvalue.get(j).toString());
}
}
}
}

View File

@ -42,8 +42,16 @@ public class ReadExcel {
this.bookNames=bookName;
this.bookSheet=bookSheets;
}
public void bookNamesMove(int startRow, int endRow, int num,String sheetName) {
public ReadExcel(Workbook book) {
this.book = book;
for (int i = 0; i < book.getNumberOfNames(); i++) {
bookNames.put(book.getNameAt(i).getNameName(), book.getNameAt(i).getRefersToFormula());
bookSheet.put(book.getNameAt(i).getNameName(),book.getNameAt(i).getSheetName());
}
}
public void bookNamesMove(int startRow, int endRow, int num, String sheetName) {
//System.out.println(bookNames);
if (bookNames.size() > 0) {
for (String title_name : bookNames.keySet()) {