发布时间:2024-09-07 14:01
@IgnoreAuth
@RequestMapping(\"/test3\")
@ResponseBody
public Map<String,Object> test3() throws IOException, InterruptedException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);
// 设置SHEET
Sheet sheet = new Sheet(1, 0);
sheet.setSheetName(\"sheet1\");
// 设置标题
Table table = new Table(1);
List<List<String>> titles = new ArrayList<>();
titles.add(Arrays.asList(\"用户ID\"));
titles.add(Arrays.asList(\"名称\"));
titles.add(Arrays.asList(\"年龄\"));
titles.add(Arrays.asList(\"生日\"));
table.setHead(titles);
// 查询数据导出即可 比如说一次性总共查询出100条数据
List<List<String>> userList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
userList.add(Arrays.asList(\"ID_\" + i, \"小明\" + i, String.valueOf(i), new Date().toString()));
}
writer.write0(userList, sheet, table);
writer.finish();
String url = OSSFactory.build().upload(new ByteArrayInputStream(out.toByteArray()),\"orderData/5.xlsx\");
return toResponsOK(url);
}
@IgnoreAuth
@RequestMapping(\"/test3\")
@ResponseBody
public Map<String,Object> test3() throws IOException, InterruptedException {
//OutputStream out = new FileOutputStream(\"E:\\\\user.xlsx\");
OutputStream out = new FileOutputStream(request.getServletContext().getRealPath(\"/\")+\"user.xlsx\");
ExcelWriter writer = new ExcelWriter(out, ExcelTypeEnum.XLSX);
// 设置SHEET
Sheet sheet = new Sheet(1, 0);
sheet.setSheetName(\"sheet1\");
// 设置标题
Table table = new Table(1);
List<List<String>> titles = new ArrayList<>();
titles.add(Arrays.asList(\"用户ID\"));
titles.add(Arrays.asList(\"名称\"));
titles.add(Arrays.asList(\"年龄\"));
titles.add(Arrays.asList(\"生日\"));
table.setHead(titles);
// 查询数据导出即可 比如说一次性总共查询出100条数据
List<List<String>> userList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
userList.add(Arrays.asList(\"ID_\" + i, \"小明\" + i, String.valueOf(i), new Date().toString()));
}
writer.write0(userList, sheet, table);
writer.finish();
return toResponsOK(\"OK\");
}
@IgnoreAuth
@RequestMapping(\"/test3\")
@ResponseBody
public Map<String,Object> test3(HttpServletResponse response) throws IOException, InterruptedException {
ExcelWriter writer = new ExcelWriter(response.getOutputStream(), ExcelTypeEnum.XLSX);
// 设置SHEET
Sheet sheet = new Sheet(1, 0);
sheet.setSheetName(\"sheet1\");
// 设置标题
Table table = new Table(1);
List<List<String>> titles = new ArrayList<>();
titles.add(Arrays.asList(\"用户ID\"));
titles.add(Arrays.asList(\"名称\"));
titles.add(Arrays.asList(\"年龄\"));
titles.add(Arrays.asList(\"生日\"));
table.setHead(titles);
// 查询数据导出即可 比如说一次性总共查询出100条数据
List<List<String>> userList = new ArrayList<>();
for (int i = 0; i < 100; i++) {
userList.add(Arrays.asList(\"ID_\" + i, \"小明\" + i, String.valueOf(i), new Date().toString()));
}
writer.write0(userList, sheet, table);
writer.finish();
return toResponsOK(\"OK\");
}