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

View File

@@ -507,7 +507,7 @@ public class MaterialService {
List<String[]> objects = new ArrayList<>();
if (null != dataList) {
for (MaterialVo4Unit m : dataList) {
String[] objs = new String[100];
String[] objs = new String[names.length];
objs[0] = m.getName();
objs[1] = m.getStandard();
objs[2] = m.getModel();
@@ -544,7 +544,7 @@ public class MaterialService {
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);
}

View File

@@ -582,7 +582,7 @@ public class SupplierService {
List<String[]> objects = new ArrayList<String[]>();
if (null != dataList) {
for (Supplier s : dataList) {
String[] objs = new String[10];
String[] objs = new String[names.length];
objs[0] = s.getSupplier();
objs[1] = s.getContacts();
objs[2] = s.getTelephone();
@@ -594,7 +594,7 @@ public class SupplierService {
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[]>();
if (null != dataList) {
for (Supplier s : dataList) {
String[] objs = new String[20];
String[] objs = new String[names.length];
objs[0] = s.getSupplier();
objs[1] = s.getContacts();
objs[2] = s.getTelephone();
@@ -634,7 +634,7 @@ public class SupplierService {
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) {
for (Object object: arr) {
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++) {
if(null != list.get(i)) {
objs[i] = list.get(i).toString();
@@ -513,7 +513,7 @@ public class SystemConfigService {
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);
}
}

View File

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