求怎样导出这种表格,后端用Java写的,前端是vue

yanshao666 2018-12-12 03:32:05
...全文
833 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
邹小青 2018-12-27
  • 打赏
  • 举报
回复
《外部数据导入导出》这篇文章里有比较全的关于excel,txt文件的导入导出介绍,支持各种格式和数据量,可以参考一下
RUA好多鱼~ 2018-12-14
  • 打赏
  • 举报
回复
poi的excel相关的api里有类似的方法,自己写一个这样的excel模板就行
Silly-77 2018-12-12
  • 打赏
  • 举报
回复
以前写过一个 不过没有设置格式使用的是POI,你可以百度下怎么设置合并单元格

public String outBook() {
List<Book> bookList = findBookService(0,100,null);
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("图书档案表");
HSSFRow hssfRow = sheet.createRow(0);
HSSFCell headCell = hssfRow.createCell(0);
headCell.setCellValue("图书档案");
// 设置单元格格式居中
HSSFCellStyle cellStyle = workbook.createCellStyle();
cellStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
// 添加表头行
hssfRow = sheet.createRow(1);
// 添加表头内容
headCell = hssfRow.createCell(0);
headCell.setCellValue("序号");
headCell.setCellStyle(cellStyle);
headCell = hssfRow.createCell(1);
headCell.setCellValue("图书条形码");
headCell.setCellStyle(cellStyle);
headCell = hssfRow.createCell(2);
headCell.setCellValue("图书名称");
headCell.setCellStyle(cellStyle);
headCell = hssfRow.createCell(3);
headCell.setCellValue("作者");
headCell.setCellStyle(cellStyle);
headCell = hssfRow.createCell(4);
headCell.setCellValue("出版社");
headCell.setCellStyle(cellStyle);
headCell = hssfRow.createCell(5);
headCell.setCellValue("价格");
headCell.setCellStyle(cellStyle);
// 添加数据内容
for (int i = 0; i < bookList.size(); i++) {
hssfRow = sheet.createRow((int) i + 2);
Book book = bookList.get(i);

// 创建单元格,并设置值
HSSFCell cell = hssfRow.createCell(0);
cell.setCellValue(i);
cell.setCellStyle(cellStyle);

cell = hssfRow.createCell(1);
cell.setCellValue(book.getBookbarcode());
cell.setCellStyle(cellStyle);

cell = hssfRow.createCell(2);
cell.setCellValue(book.getBookname());
cell.setCellStyle(cellStyle);

cell = hssfRow.createCell(3);
cell.setCellValue(book.getAuthor());
cell.setCellStyle(cellStyle);

cell = hssfRow.createCell(4);
cell.setCellValue(book.getPublisher());
cell.setCellStyle(cellStyle);

cell = hssfRow.createCell(5);
cell.setCellValue(book.getPrice());
cell.setCellStyle(cellStyle);
}
// 保存Excel文件
try {
OutputStream outputStream = new FileOutputStream("C://new//bookinfo.xls");
workbook.write(outputStream);
outputStream.close();
return "导出成功";
} catch (Exception e) {
e.printStackTrace();
}
return "导出失败";
}
我爱娃哈哈 2018-12-12
  • 打赏
  • 举报
回复
后端写excel的时候可以设置格式的,包括字体大小,单元格合并都可以
咸哼酒家 2018-12-12
  • 打赏
  • 举报
回复
easypoi按设置好的excel模板导出
例子参考https://blog.csdn.net/u013374164/article/details/78292194

50,527

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧