From 26cdfa723406fc4cbb667401704d2cdd2547331b Mon Sep 17 00:00:00 2001 From: lxw <810412026@qq.com> Date: 星期六, 03 九月 2022 14:37:40 +0800 Subject: [PATCH] 下载替换件变红 --- src/main/java/com/whyc/service/CategoryService.java | 130 +++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 130 insertions(+), 0 deletions(-) diff --git a/src/main/java/com/whyc/service/CategoryService.java b/src/main/java/com/whyc/service/CategoryService.java index a4e71e5..74245dd 100644 --- a/src/main/java/com/whyc/service/CategoryService.java +++ b/src/main/java/com/whyc/service/CategoryService.java @@ -3,10 +3,19 @@ import com.whyc.dto.Response; import com.whyc.mapper.CategoryMapper; import com.whyc.pojo.Category; +import com.whyc.util.ActionUtil; +import org.apache.poi.hssf.usermodel.*; +import org.apache.poi.hssf.util.HSSFColor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import javax.swing.*; +import java.io.FileOutputStream; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.List; +import java.util.Random; @Service public class CategoryService { @@ -19,4 +28,125 @@ List<Category> list=mapper.getAllPermit(); return new Response().setII(1,list.size()>0,list,"鏉冮檺淇℃伅"); } + + public static void main(String[] args) { + HSSFWorkbook wb=new HSSFWorkbook(); + HSSFSheet sheet=wb.createSheet(); + +//绗竴涓牱寮忓拰杈撳嚭(杈规) + /*HSSFCellStyle style=wb.createCellStyle(); + style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //璁剧疆搴曠嚎鍜岄鑹� + style.setBottomBorderColor(HSSFColor.BLACK.index); + style.setBorderLeft(HSSFCellStyle.BORDER_THIN); //璁剧疆宸﹁竟绾垮拰棰滆壊 + style.setLeftBorderColor(HSSFColor.BLACK.index); + style.setBorderRight(HSSFCellStyle.BORDER_THIN); //璁剧疆鍙宠竟绾垮拰棰滆壊 + style.setRightBorderColor(HSSFColor.BLACK.index); + style.setBorderTop(HSSFCellStyle.BORDER_THIN); //璁剧疆涓婇潰绾垮拰棰滆壊 + style.setTopBorderColor(HSSFColor.BLACK.index);*/ + //HSSFRow row=sheet.createRow((short)1); + // HSSFCell cell=row.createCell((short)1); + /*cell.setCellValue("hello"); + cell.setCellStyle(style);*/ + + +//绗簩涓牱寮忓拰杈撳嚭(鑳屾櫙/鍓嶆櫙鑹�) + /*style = wb.createCellStyle(); + style.setFillBackgroundColor(HSSFColor.ORANGE.index);//娣诲姞鑳屾櫙鑹�,鍐呭鐪嬩笉娓呮 + style.setFillPattern(HSSFCellStyle.BIG_SPOTS); + row=sheet.createRow((short)2); + cell=row.createCell((short)2); + cell.setCellValue("hello"); + cell.setCellStyle(style); +*/ + /*style = wb.createCellStyle(); + style.setFillForegroundColor(HSSFColor.ORANGE.index);//娣诲姞鍓嶆櫙鑹�,鍐呭鐪嬬殑娓呮 + style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + row=sheet.createRow((short)3); + cell=row.createCell((short)3); + cell.setCellValue("hello"); + cell.setCellStyle(style);*/ + + //HSSFFont font = wb.createFont(); +//绗笁涓牱寮忓拰杈撳嚭(瀛椾綋) + /*font.setFontHeightInPoints((short)8); //瀛椾綋澶у皬 + font.setFontName("Arial"); //浠�涔堝瓧浣� + font.setItalic(false); //鏄笉鍊炬枩 + font.setStrikeout(false); //鏄笉鏄垝鎺� + font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //瀛椾綋鍔犵矖 + + + style = wb.createCellStyle(); //寮曠敤瀛椾綋鐨勮繖涓牱寮� + style.setFont(font); + + row=sheet.createRow((short)4); //杈撳嚭鐪嬬粨鏋� + cell=row.createCell((short)4); + cell.setCellValue("BJ10012-1241"); + cell.setCellStyle(style);*/ + + +//绗洓鏍峰紡鍜岃緭鍑猴紙鑷畾涔夐鑹诧級 + /*style = wb.createCellStyle(); //璁剧疆棰滆壊鏍峰紡锛屽悗闈㈠畾涔夐鑹茬殑鍊� + style.setFillForegroundColor(HSSFColor.LIME.index); + style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + row=sheet.createRow((short)5); + cell=row.createCell((short)5); + cell.setCellValue("BJ10012-1241"); + cell.setCellStyle(style); + HSSFPalette palette = wb.getCustomPalette(); //瀹氫箟棰滆壊鐨勫�� + palette.setColorAtIndex(HSSFColor.LIME.index, (byte) 255, (byte) 0, (byte) 0);*/ + + +//绗簲鏍峰紡鍜岃緭鍑猴紙姘村钩鍜屽瀭鐩村榻愶級 + /*style = wb.createCellStyle(); + style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//姘村钩灞呬腑 + style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//鍨傜洿灞呬腑 + row=sheet.createRow((short)6); + cell=row.createCell((short)6); + cell.setCellValue("BJ10012-1241"); + cell.setCellStyle(style);*/ + +//璁剧疆涓�涓爣棰樻牱寮� + HSSFFont font = wb.createFont(); //璁剧疆瀛椾綋鐨勬牱寮� + font.setFontHeightInPoints((short)8); //瀛椾綋澶у皬 + font.setFontName("Arial"); //浠�涔堝瓧浣� + font.setItalic(false); //鏄笉鍊炬枩 + font.setStrikeout(false); //鏄笉鏄垝鎺� + font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD); //瀛椾綋鍔犵矖 + font.setColor(HSSFFont.COLOR_RED); + HSSFCellStyle style = wb.createCellStyle(); //寮曠敤瀛椾綋鐨勮繖涓牱寮� + style.setFont(font); + /* style.setBorderBottom(HSSFCellStyle.BORDER_THIN); //璁剧疆搴曠嚎鍜岄鑹� + style.setBottomBorderColor(HSSFColor.BLACK.index); + style.setBorderLeft(HSSFCellStyle.BORDER_THIN); //璁剧疆宸﹁竟绾垮拰棰滆壊 + style.setLeftBorderColor(HSSFColor.BLACK.index); + style.setBorderRight(HSSFCellStyle.BORDER_THIN); //璁剧疆鍙宠竟绾垮拰棰滆壊 + style.setRightBorderColor(HSSFColor.BLACK.index); + style.setBorderTop(HSSFCellStyle.BORDER_THIN); //璁剧疆涓婇潰绾垮拰棰滆壊 + style.setTopBorderColor(HSSFColor.BLACK.index); + style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//姘村钩灞呬腑 + style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);//鍨傜洿灞呬腑*/ + //style.setFillForegroundColor(HSSFColor.RED.index);//娣诲姞鍓嶆櫙鑹�,鍐呭鐪嬬殑娓呮 + //style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND); + + HSSFRow row=sheet.createRow((short)7); + HSSFCell cell=row.createCell((short)6); + cell.setCellValue("lxw"); + //cell.setCellStyle(style); + cell=row.createCell((short)7); + cell.setCellValue("BJ10012-1241"); + //cell.setCellStyle(style); + row.setRowStyle(style); + + +//杈撳嚭鏂囦欢 + try { + String name="workbook_"+ ActionUtil.sdfwithFTP.format(new Date()).replace(" ","_")+".xls"; + FileOutputStream fileOut = new FileOutputStream("D://"+name); + wb.write(fileOut); + fileOut.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + } } -- Gitblit v1.9.1