日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

导出execl

發布時間:2024/8/1 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 导出execl 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Controller

/*** 導出參考價設置** @return* @throws IOException* @throws InvalidFormatException* @throws NoSuchMethodException* @throws InvocationTargetException* @throws IllegalAccessException*///用post原因,輸入的查詢參數太長了@RequestMapping(value = "/exportPrice", method = {RequestMethod.POST})@ResponseBody@ApiOperation(value = "導出參考價設置", notes = "導出參考價設置", response = String.class)public void exportinsurance(HttpServletResponse response,@ApiParam(value = "發貨機構") @RequestParam(required = false) List<Long> deliveryOrgIds,@ApiParam(value = "到貨機構") @RequestParam(required = false) List<Long> receiveOrgIds,@ApiParam(value = "狀態:1有效、2無效") @RequestParam(required = true) Integer validStatus)throws IOException, InvalidFormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {List<LinkedHashMap> result = new LinkedList<>();List<ConfigReferencePriceDto> exportList = configReferencePriceService.findExportList(deliveryOrgIds, receiveOrgIds, validStatus);String[] cols = {"deliveryOrgId", "receiveOrgId", "unitVolumePrice", "unitWeightPrice", "thresholdVolume", "thresholdVolumePrice", "thresholdWeight", "thresholdWeightPrice", "singlePiecePrice","abnormityCoefficient", "equipmentCoefficient", "status", "updateTime"};List<Organization> organizationList = organizationService.findByNamedParamList(null);List<String> columns = new ArrayList<>();for (String s : cols) {columns.add(s);}for (ConfigReferencePriceDto priceDto : exportList) {LinkedHashMap<String, String> data = new LinkedHashMap<>();for (String column : columns) {String value = "";if (column.equals("deliveryOrgId")) {//收貨機構if (priceDto.getDeliveryOrgId() != null) {for (Organization organ : organizationList) {if (organ.getId().equals(priceDto.getDeliveryOrgId())) {value = organ.getName();}}}} else if (column.equals("receiveOrgId")) {//收貨機構if (priceDto.getReceiveOrgId() != null) {for (Organization organ : organizationList) {if (organ.getId().equals(priceDto.getReceiveOrgId())) {value = organ.getName();}}}} else if (column.equals("unitVolumePrice")) {//標準體積參考價value = String.valueOf(priceDto.getUnitVolumePrice());} else if (column.equals("unitWeightPrice")) {//標準重量參考價value = String.valueOf(priceDto.getUnitWeightPrice());} else if (column.equals("thresholdVolume")) {//體積閾值value = String.valueOf(priceDto.getThresholdVolume());} else if (column.equals("thresholdVolumePrice")) {//超體積閾值價格value = String.valueOf(priceDto.getThresholdVolumePrice());} else if (column.equals("thresholdWeight")) {//重量閾值value = String.valueOf(priceDto.getThresholdWeight());} else if (column.equals("thresholdWeightPrice")) {//超重量閾值價格value = String.valueOf(priceDto.getThresholdWeightPrice());} else if (column.equals("singlePiecePrice")) {//單價參考價value = String.valueOf(priceDto.getSinglePiecePrice());} else if (column.equals("abnormityCoefficient")) {//異形件系數value = String.valueOf(priceDto.getAbnormityCoefficient());} else if (column.equals("equipmentCoefficient")) {//設備系數value = String.valueOf(priceDto.getEquipmentCoefficient());} else if (column.equals("status")) {switch (priceDto.getStatus()) {case 1:value = "有效";break;case 2:value = "無效";break;default:value = "";}} else if (column.equals("updateTime")) {value = DateUtils.getStrDate(priceDto.getUpdateTime(), "yyyy-MM-dd HH:mm:ss");}data.put(column, value);}result.add(data);}exporterFactory.process(response, result, new ExporterHead("參考價設置"), ReferencePriceExporterTemplate.class, columns);}

ExporterConfig類

exporterTemplate.put(ReferencePriceExporterTemplate.class, getReferencePriceExporterTemplate());@Beanpublic ReferencePriceExporterTemplate getReferencePriceExporterTemplate() {ReferencePriceExporterTemplate referencePriceExporterTemplate = new ReferencePriceExporterTemplate();referencePriceExporterTemplate.setDefaultFileName("參考價設置");referencePriceExporterTemplate.setStartRowNumber(3);return referencePriceExporterTemplate;}

ReferencePriceExporterTemplate類

package com.opensesame.platform.web.exporter.template;import com.opensesame.core.lang.Tuple; import com.opensesame.core.util.DateUtils; import com.opensesame.platform.web.exporter.head.ExporterHead; import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.poi.ss.usermodel.*; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.RegionUtil; import org.apache.poi.xssf.usermodel.XSSFCellStyle;import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map;@SuppressWarnings("unchecked") public class ReferencePriceExporterTemplate extends AbstractExporterTemplate {private static final Map<String, Tuple<String, Integer>> METADATA = new HashMap<String, Tuple<String, Integer>>();static {METADATA.put("deliveryOrgId", new Tuple<String, Integer>("收貨機構", 20 * 256));METADATA.put("receiveOrgId", new Tuple<String, Integer>("到貨機構", 20 * 256));METADATA.put("unitVolumePrice", new Tuple<String, Integer>("標準體積參考價(元 /m3)", 25 * 256));METADATA.put("unitWeightPrice", new Tuple<String, Integer>("標準重量參考價(元 /kg)", 25 * 256));METADATA.put("thresholdVolume", new Tuple<String, Integer>("體積閾值(m3)", 20 * 256));METADATA.put("thresholdVolumePrice", new Tuple<String, Integer>("超體積閾值價格(元/m3)", 25 * 256));METADATA.put("thresholdWeight", new Tuple<String, Integer>("重量閾值(kg)", 20 * 256));METADATA.put("thresholdWeightPrice", new Tuple<String, Integer>("超重量閾值價格(元/kg)", 25 * 256));METADATA.put("singlePiecePrice", new Tuple<String, Integer>("單件參考價", 15 * 256));METADATA.put("abnormityCoefficient", new Tuple<String, Integer>("異形件系數", 15 * 256));METADATA.put("equipmentCoefficient", new Tuple<String, Integer>("設備系數", 15 * 256));METADATA.put("status", new Tuple<String, Integer>("狀態", 15 * 256));METADATA.put("updateTime", new Tuple<String, Integer>("時間", 25 * 256));}@Overridepublic void drawHead(Workbook workBook, Sheet sheet, ExporterHead exporterHead, CellStyle cellStyle, Object... args) {List<String> columns = (List<String>) args[0];// 設置標題CellRangeAddress head = new CellRangeAddress(0, 0, 0, columns.size());sheet.addMergedRegion(head);Cell headCell = sheet.createRow(0).createCell(0);headCell.setCellValue(exporterHead.getTitle());headCell.setCellStyle(getHeadCellStyle(workBook));RegionUtil.setBorderBottom(XSSFCellStyle.BORDER_THIN, head, sheet, workBook);RegionUtil.setBorderLeft(XSSFCellStyle.BORDER_THIN, head, sheet, workBook);RegionUtil.setBorderRight(XSSFCellStyle.BORDER_THIN, head, sheet, workBook);RegionUtil.setBorderTop(XSSFCellStyle.BORDER_THIN, head, sheet, workBook);// 設置時間CellRangeAddress date = new CellRangeAddress(1, 1, 0, columns.size());sheet.addMergedRegion(date);Cell dateCell = sheet.createRow(1).createCell(0);dateCell.setCellValue("導出時間:" + DateFormatUtils.format(new Date(), DateUtils.DATE_TIME_FORMAT));dateCell.setCellStyle(getDateCellStyle(workBook));RegionUtil.setBorderBottom(XSSFCellStyle.BORDER_THIN, date, sheet, workBook);RegionUtil.setBorderLeft(XSSFCellStyle.BORDER_THIN, date, sheet, workBook);RegionUtil.setBorderRight(XSSFCellStyle.BORDER_THIN, date, sheet, workBook);RegionUtil.setBorderTop(XSSFCellStyle.BORDER_THIN, date, sheet, workBook);Row row = sheet.createRow(2);int columnNum = 0;CellStyle titleCellStyle = getTitleCellStyle(workBook);for (String column : columns) {Cell cell = row.createCell(columnNum++);cell.setCellStyle(titleCellStyle);cell.setCellValue(METADATA.get(column).getA());}//將字段改為數字格式List<LinkedHashMap> data = (List<LinkedHashMap>) args[1];int startRow = 3;for (LinkedHashMap<String, Object> temp : data) {Row dataRow = sheet.createRow(startRow++);int rowNum = 0;for (Map.Entry<String, Object> value : temp.entrySet()) {Cell cell = dataRow.createCell(rowNum++);if (value.getKey().equals("capacity") || value.getKey().equals("netWeight")) {CellStyle cellStyleNumber = getCellStyle(workBook);cell.setCellStyle(cellStyleNumber);cell.setCellType(XSSFCell.CELL_TYPE_NUMERIC);cell.setCellValue(Double.parseDouble(value.getValue().toString()));} else {cell.setCellStyle(cellStyle);cell.setCellValue(value.getValue().toString());}}}}@Overridepublic void windup(Workbook workBook, Sheet sheet, ExporterHead exporterHead, CellStyle cellStyle, Object... args) {List<String> columns = (List<String>) args[0];int columnNum = 0;//去掉列自適應寬度 // sheet.autoSizeColumn(columnNum++, true);for (String column : columns) {sheet.setColumnWidth(columnNum++, METADATA.get(column).getB());}}/*** 獲取單元格樣式** @param workBook* @return*/public static CellStyle getHeadCellStyle(Workbook workBook) {CellStyle style = workBook.createCellStyle();style.setAlignment(CellStyle.ALIGN_CENTER);Font font = workBook.createFont();font.setFontName("Calibri");font.setBoldweight(Font.BOLDWEIGHT_BOLD);font.setFontHeightInPoints((short) 20);style.setFont(font);return style;}/*** 獲取單元格樣式** @param workBook* @return*/public static CellStyle getDateCellStyle(Workbook workBook) {CellStyle style = workBook.createCellStyle();style.setAlignment(CellStyle.ALIGN_CENTER);Font font = workBook.createFont();font.setFontName("Calibri");font.setFontHeightInPoints((short) 12);style.setFont(font);return style;}/*** 獲取單元格樣式** @param workBook* @return*/public static CellStyle getTitleCellStyle(Workbook workBook) {CellStyle style = workBook.createCellStyle();style.setAlignment(CellStyle.ALIGN_CENTER);style.setBorderBottom(XSSFCellStyle.BORDER_THIN);style.setBorderTop(XSSFCellStyle.BORDER_THIN);style.setBorderRight(XSSFCellStyle.BORDER_THIN);style.setBorderLeft(XSSFCellStyle.BORDER_THIN);Font font = workBook.createFont();font.setFontName("Calibri");font.setFontHeightInPoints((short) 12);style.setFont(font);return style;}}

總結

以上是生活随笔為你收集整理的导出execl的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 国产成人97精品免费看片 | 91精品一区二区三 | 一级看片 | 精品丰满人妻无套内射 | 久久婷婷亚洲 | 麻豆一二三区 | 黄色一区二区三区 | 69影院少妇在线观看 | 亚洲丝袜av| 色草在线 | 国产黄色大片视频 | 色88久久久久高潮综合影院 | 夜夜爽妓女8888视频免费观看 | 久久黄色免费网站 | 国产激情一区二区三区 | 涩涩综合| 日本黄色短片 | 综合天堂av久久久久久久 | 色激情网| 国产成人av在线播放 | 国产精久久久 | 国产精品无码专区av免费播放 | 精品在线一区 | 中日韩在线观看 | 韩国av电影在线观看 | 国产精品日日摸天天碰 | 91精品999| 91九色偷拍 | 欧美激情婷婷 | 日韩欧美在线观看免费 | 福利视频第一页 | 国产视频不卡一区 | 精品一区二区三区免费视频 | 五月婷婷综合在线观看 | 亚洲视频高清 | 欧美日韩在线一区二区 | 熟女高潮一区二区三区 | 卡通动漫亚洲综合 | 色婷婷a| 午夜影院入口 | 国产色爽| 99国产精品视频免费观看一公开 | 欧美一级性视频 | 久久人妻少妇嫩草av无码专区 | 精品亚洲一区二区三区四区五区高 | 狠狠爱夜夜操 | 4虎最新网址 | av免费在线观看网站 | 亚洲免费在线 | 性久久久久久久 | 亚洲美免无码中文字幕在线 | 窝窝在线视频 | 国产欧美一区二区三区精华液好吗 | 午夜精品在线视频 | 成人激情久久 | 97超碰人人看 | 久久免费视频网 | 精品综合| 日韩综合一区二区三区 | 亚洲一区免费在线观看 | 香蕉网在线 | 免费毛片一区二区三区久久久 | h视频在线免费看 | 骚虎av | 亚洲网av| 一区二区片 | 国产美女黄网站 | 精品一区二区电影 | 亚洲av片不卡无码久久 | 精品久久久久一区 | 亚洲国产精品久久久久久6q | 已满十八岁免费观看全集动漫 | 麻豆影视在线免费观看 | 免费久久久久久 | 99视频导航 | 国产欧美一区二区精品性色99 | 国产美女无遮挡免费 | 久久综合一区二区 | 91网站永久免费看nba视频 | 黄色视屏在线播放 | 秋霞影院一区二区 | 四色最新网址 | 国产情侣av在线 | 人妻精品久久久久中文字幕 | 800av在线视频 | 久久99精品久久久久久琪琪 | 亚洲v视频| 中国美女一级看片 | 免费看污片的网站 | 亚洲影视中文字幕 | 超碰黑丝| 国产精品久久久久久一区二区三区 | 国产毛片欧美毛片久久久 | 美女流白浆视频 | 色屁屁在线 | 天天爽天天做 | 中文字幕欧美专区 | 鲁丝一区二区三区 | 夜夜嗨av禁果av粉嫩av懂色av |