| | |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.swing.*; |
| | | import java.awt.*; |
| | | import java.io.FileOutputStream; |
| | | import java.io.IOException; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | public Response getAllPermit() { |
| | | 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(); |
| | | } |
| | | |
| | | } |
| | | } |