lxw
2022-09-03 26cdfa723406fc4cbb667401704d2cdd2547331b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
package com.whyc.service;
 
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 {
 
    @Autowired(required = false)
    private CategoryMapper mapper;
 
    //查询所有的权限
    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();
        }
 
    }
}