第二步:编写导出代码。
1、在项目中引入poi的依赖包poi-3.17.jar。
2、编写导出的代码
public static void main(String[] args) throws Exception{
//1.创建Excel对象
Workbook wb =new HSSFWorkbook();
//2.创建表格的sheet页
Sheet sheet = wb.createSheet();
//3.创建行
Row row = sheet.createRow(3);
//4.1创建列
Cell cell = row.createCell(3);
//4.2设置列宽便于展示
sheet.setColumnWidth(3, 10000);
//5设置内容
cell.setCellValue("有困难找度娘");
//6.设置样式
//6.1创建字体
Font font = wb.createFont();
font.setFontHeightInPoints((short) 36);
font.setFontName("华文琥珀");
font.setColor(Font.COLOR_RED);
//6.2创建单元格格式CellStyle
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFont(font);
//6.3字体作用单元格
cell.setCellStyle(cellStyle);
//7.写入到硬盘
//7.1创建流
FileOutputStream os = new FileOutputStream(new File("E:/file/export.xls"));
//7.2将wb的内容写入字符流中
wb.write(os);
//7.3关流
os.flush();
os.close();
}