引入依赖包
<!-- start 打印文件,文件生成-->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
</dependency>
<!-- end 打印文件,文件生成-->
//订单文件生成
private DownLoadDto ordersXLS(OrdersDto ordersDto) {
boolean flag = true;
String name = null;
try {
//设置输出到本地的excel文件的名字和路径
name = "F:\\" + ordersDto.getUserName() + "-" + ordersDto.getOrdersNumber() + ".xls";
FileOutputStream out = new FileOutputStream(name);
//生成excel文档对象
HSSFWorkbook workBook = new HSSFWorkbook();
//创建工作簿
HSSFSheet mySheet = workBook.createSheet();
//设置工作簿的名字
workBook.setSheetName(0, "我的工作簿1");
//创建第一行,标题行
int rowNomber = -1;
HSSFRow myRow = mySheet.createRow(++rowNomber);
HSSFCellStyle style = workBook.createCellStyle();
//设置字体样式
HSSFFont font = workBook.createFont();
font.setFontName("宋体");
font.setFontHeightInPoints((short) 10);
style.setFont(font);
//设置标题行,每一列的标题
HSSFCell cell = myRow.createCell((short) 0);
cell.setCellStyle(style);
cell.setCellValue("菜名");
cell = myRow.createCell((short) 1);
cell.setCellStyle(style);
cell.setCellValue("单价");
cell = myRow.createCell((short) 2);
cell.setCellStyle(style);
cell.setCellValue("数量");
cell = myRow.createCell((short) 3);
cell.setCellStyle(style);
cell.setCellValue("订单编号");
cell = myRow.createCell((short) 4);
cell.setCellStyle(style);
cell.setCellValue("用户id");
cell = myRow.createCell((short) 5);
cell.setCellStyle(style);
cell.setCellValue("用户姓名");
cell = myRow.createCell((short) 6);
cell.setCellStyle(style);
cell.setCellValue("订单总金额");
cell = myRow.createCell((short) 7);
cell.setCellStyle(style);
cell.setCellValue("评价信息");
cell = myRow.createCell((short) 8);
cell.setCellStyle(style);
cell.setCellValue("联系电话");
cell = myRow.createCell((short) 9);
cell.setCellStyle(style);
cell.setCellValue("备注");
cell = myRow.createCell((short)