完善excel导出接口的逻辑

This commit is contained in:
jishenghua
2024-03-30 14:48:33 +08:00
parent 6aa51ffdc4
commit 44e34c78ce
5 changed files with 21 additions and 23 deletions

View File

@@ -1311,7 +1311,7 @@ public class DepotHeadService {
billListCacheVo.setOrganName(dh.getOrganName()); billListCacheVo.setOrganName(dh.getOrganName());
billListCacheVo.setOperTimeStr(getCenternTime(dh.getOperTime())); billListCacheVo.setOperTimeStr(getCenternTime(dh.getOperTime()));
billListCacheVoMap.put(dh.getId(), billListCacheVo); billListCacheVoMap.put(dh.getId(), billListCacheVo);
String[] objs = new String[100]; String[] objs = new String[sheetOneArr.length];
objs[0] = dh.getOrganName(); objs[0] = dh.getOrganName();
objs[1] = dh.getNumber(); objs[1] = dh.getNumber();
objs[2] = dh.getLinkNumber(); objs[2] = dh.getLinkNumber();
@@ -1328,7 +1328,7 @@ public class DepotHeadService {
objs[10] = dh.getRemark(); objs[10] = dh.getRemark();
billList.add(objs); billList.add(objs);
} }
ExcelUtils.exportObjectsWithTitle(wtwb, oneTip, sheetOneArr, "单据列表", 0, billList); ExcelUtils.exportObjectsManySheet(wtwb, oneTip, sheetOneArr, "单据列表", 0, billList);
//导出明细数据 //导出明细数据
if(idList.size()>0) { if(idList.size()>0) {
List<DepotItemVo4WithInfoEx> dataList = depotItemMapperEx.getBillDetailListByIds(idList); List<DepotItemVo4WithInfoEx> dataList = depotItemMapperEx.getBillDetailListByIds(idList);
@@ -1349,7 +1349,7 @@ public class DepotHeadService {
String[] sheetTwoArr = StringUtil.listToStringArray(sheetTwoList); String[] sheetTwoArr = StringUtil.listToStringArray(sheetTwoList);
List<String[]> billDetail = new ArrayList<>(); List<String[]> billDetail = new ArrayList<>();
for (DepotItemVo4WithInfoEx diEx : dataList) { for (DepotItemVo4WithInfoEx diEx : dataList) {
String[] objs = new String[100]; String[] objs = new String[sheetTwoArr.length];
BillListCacheVo billListCacheVo = billListCacheVoMap.get(diEx.getHeaderId()); BillListCacheVo billListCacheVo = billListCacheVoMap.get(diEx.getHeaderId());
objs[0] = billListCacheVo != null ? billListCacheVo.getOrganName() : ""; objs[0] = billListCacheVo != null ? billListCacheVo.getOrganName() : "";
objs[1] = billListCacheVo != null ? billListCacheVo.getNumber() : ""; objs[1] = billListCacheVo != null ? billListCacheVo.getNumber() : "";
@@ -1377,7 +1377,7 @@ public class DepotHeadService {
objs[22] = diEx.getRemark(); objs[22] = diEx.getRemark();
billDetail.add(objs); billDetail.add(objs);
} }
ExcelUtils.exportObjectsWithTitle(wtwb, twoTip, sheetTwoArr, "单据明细", 1, billDetail); ExcelUtils.exportObjectsManySheet(wtwb, twoTip, sheetTwoArr, "单据明细", 1, billDetail);
} }
wtwb.write(); wtwb.write();
wtwb.close(); wtwb.close();

View File

@@ -507,7 +507,7 @@ public class MaterialService {
List<String[]> objects = new ArrayList<>(); List<String[]> objects = new ArrayList<>();
if (null != dataList) { if (null != dataList) {
for (MaterialVo4Unit m : dataList) { for (MaterialVo4Unit m : dataList) {
String[] objs = new String[100]; String[] objs = new String[names.length];
objs[0] = m.getName(); objs[0] = m.getName();
objs[1] = m.getStandard(); objs[1] = m.getStandard();
objs[2] = m.getModel(); objs[2] = m.getModel();
@@ -544,7 +544,7 @@ public class MaterialService {
objects.add(objs); objects.add(objs);
} }
} }
File file = ExcelUtils.exportObjectsWithoutTitle(title, "*导入时本行内容请勿删除,切记!", names, title, objects); File file = ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
ExcelUtils.downloadExcel(file, file.getName(), response); ExcelUtils.downloadExcel(file, file.getName(), response);
} }

View File

@@ -582,7 +582,7 @@ public class SupplierService {
List<String[]> objects = new ArrayList<String[]>(); List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) { if (null != dataList) {
for (Supplier s : dataList) { for (Supplier s : dataList) {
String[] objs = new String[10]; String[] objs = new String[names.length];
objs[0] = s.getSupplier(); objs[0] = s.getSupplier();
objs[1] = s.getContacts(); objs[1] = s.getContacts();
objs[2] = s.getTelephone(); objs[2] = s.getTelephone();
@@ -594,7 +594,7 @@ public class SupplierService {
objects.add(objs); objects.add(objs);
} }
} }
return ExcelUtils.exportObjectsWithoutTitle(title, "*导入时本行内容请勿删除,切记!", names, title, objects); return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
} }
} }
@@ -611,7 +611,7 @@ public class SupplierService {
List<String[]> objects = new ArrayList<String[]>(); List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) { if (null != dataList) {
for (Supplier s : dataList) { for (Supplier s : dataList) {
String[] objs = new String[20]; String[] objs = new String[names.length];
objs[0] = s.getSupplier(); objs[0] = s.getSupplier();
objs[1] = s.getContacts(); objs[1] = s.getContacts();
objs[2] = s.getTelephone(); objs[2] = s.getTelephone();
@@ -634,7 +634,7 @@ public class SupplierService {
objects.add(objs); objects.add(objs);
} }
} }
return ExcelUtils.exportObjectsWithoutTitle(title, "*导入时本行内容请勿删除,切记!", names, title, objects); return ExcelUtils.exportObjectsOneSheet(title, "*导入时本行内容请勿删除,切记!", names, title, objects);
} }
/** /**

View File

@@ -504,7 +504,7 @@ public class SystemConfigService {
if (null != arr) { if (null != arr) {
for (Object object: arr) { for (Object object: arr) {
List<Object> list = (List<Object>) object; List<Object> list = (List<Object>) object;
String[] objs = new String[100]; String[] objs = new String[names.length];
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
if(null != list.get(i)) { if(null != list.get(i)) {
objs[i] = list.get(i).toString(); objs[i] = list.get(i).toString();
@@ -513,7 +513,7 @@ public class SystemConfigService {
objects.add(objs); objects.add(objs);
} }
} }
File file = ExcelUtils.exportObjectsWithoutTitle(title, tip, names, title, objects); File file = ExcelUtils.exportObjectsOneSheet(title, tip, names, title, objects);
ExcelUtils.downloadExcel(file, file.getName(), response); ExcelUtils.downloadExcel(file, file.getName(), response);
} }
} }

View File

@@ -45,9 +45,8 @@ public class ExcelUtils {
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static void exportObjectsWithTitle(WritableWorkbook wtwb, String tip, public static void exportObjectsManySheet(WritableWorkbook wtwb, String tip,
String[] names, String title, int index, List<String[]> objects) String[] names, String title, int index, List<String[]> objects) throws Exception {
throws Exception {
WritableSheet sheet = wtwb.createSheet(title, index); WritableSheet sheet = wtwb.createSheet(title, index);
sheet.getSettings().setDefaultColumnWidth(12); sheet.getSettings().setDefaultColumnWidth(12);
@@ -72,6 +71,7 @@ public class ExcelUtils {
WritableCellFormat format = new WritableCellFormat(wfont); WritableCellFormat format = new WritableCellFormat(wfont);
format.setAlignment(Alignment.LEFT); format.setAlignment(Alignment.LEFT);
format.setVerticalAlignment(VerticalAlignment.TOP); format.setVerticalAlignment(VerticalAlignment.TOP);
format.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
// 第一行写入提示 // 第一行写入提示
if(com.jsh.erp.utils.StringUtil.isNotEmpty(tip) && tip.contains("*")) { if(com.jsh.erp.utils.StringUtil.isNotEmpty(tip) && tip.contains("*")) {
@@ -101,7 +101,7 @@ public class ExcelUtils {
} }
/** /**
* 导出excel不需要第一行的title * 导出excel带单个sheet
* *
* @param fileName * @param fileName
* @param names * @param names
@@ -110,9 +110,8 @@ public class ExcelUtils {
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static File exportObjectsWithoutTitle(String fileName, String tip, public static File exportObjectsOneSheet(String fileName, String tip,
String[] names, String title, List<String[]> objects) String[] names, String title, List<String[]> objects) throws Exception {
throws Exception {
File excelFile = new File("/opt/"+ fileName); File excelFile = new File("/opt/"+ fileName);
WritableWorkbook wtwb = Workbook.createWorkbook(excelFile); WritableWorkbook wtwb = Workbook.createWorkbook(excelFile);
WritableSheet sheet = wtwb.createSheet(title, 0); WritableSheet sheet = wtwb.createSheet(title, 0);
@@ -120,16 +119,14 @@ public class ExcelUtils {
// 标题的格式-红色 // 标题的格式-红色
WritableFont redWF = new WritableFont(WritableFont.ARIAL, 12, WritableFont redWF = new WritableFont(WritableFont.ARIAL, 12,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.RED);
Colour.RED);
WritableCellFormat redWFFC = new WritableCellFormat(redWF); WritableCellFormat redWFFC = new WritableCellFormat(redWF);
redWFFC.setVerticalAlignment(VerticalAlignment.CENTRE); redWFFC.setVerticalAlignment(VerticalAlignment.CENTRE);
redWFFC.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN); redWFFC.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
// 标题的格式-黑色 // 标题的格式-黑色
WritableFont blackWF = new WritableFont(WritableFont.ARIAL, 12, WritableFont blackWF = new WritableFont(WritableFont.ARIAL, 12,
WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
Colour.BLACK);
WritableCellFormat blackWFFC = new WritableCellFormat(blackWF); WritableCellFormat blackWFFC = new WritableCellFormat(blackWF);
blackWFFC.setVerticalAlignment(VerticalAlignment.CENTRE); blackWFFC.setVerticalAlignment(VerticalAlignment.CENTRE);
blackWFFC.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN); blackWFFC.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
@@ -139,6 +136,7 @@ public class ExcelUtils {
WritableCellFormat format = new WritableCellFormat(wfont); WritableCellFormat format = new WritableCellFormat(wfont);
format.setAlignment(Alignment.LEFT); format.setAlignment(Alignment.LEFT);
format.setVerticalAlignment(VerticalAlignment.TOP); format.setVerticalAlignment(VerticalAlignment.TOP);
format.setBorder(jxl.format.Border.ALL,jxl.format.BorderLineStyle.THIN);
// 第一行写入提示 // 第一行写入提示
if(StringUtil.isNotEmpty(tip) && tip.contains("*")) { if(StringUtil.isNotEmpty(tip) && tip.contains("*")) {