所以我有一个 Spring 控制器,我想创建一个 Excel 文件并将其返回,以便浏览器下载它。
我正在使用 JEXcelApi。
这是我的控制器代码
@RequestMapping(value="/excel/cols/{colString}/rows/{rowString}/", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<String> exportExcel(HttpServletResponse response,
    @PathVariable List<String> colString,
    @PathVariable List<String> rowString) throws JSONException, IOException, WriteException {
    WritableWorkbook workbook = Workbook.createWorkbook(new File("exported.xls"));
    WritableSheet sheet = workbook.createSheet("Exported",0);
    String[] cols = colString.get(0).split(",");
    String[] rows = rowString.get(0).split(","); 
    for(int i = 0; i < cols.length;i++){
        Label label = new Label(i,0, cols[i]);
        sheet.addCell(label);
    }
    int excelCol = 0;
    int excelRow = 1;
    for(int i = 0; i < rows.length;i++){
        Label label = new Label(excelCol,excelRow, rows[i]);
        sheet.addCell(label);
        excelCol++;
        if((i+1) % cols.length == 0){
            excelCol = 0;
            excelRow++;
        }
    }
    workbook.write();
    workbook.close();
    return null;
}
我怎么做?我怀疑我可以设置一些内容标题。我知道一种方法是使用 Spring 的 Abstract Excel 视图类,但有更简单的方法吗?