I am using EasyExcel to export an excel file.
implementation group: 'com.alibaba', name: 'easyexcel', version: '2.2.3'
This is my simplest code demo, the controller like this:
@Api
@RequestMapping("/illidan/report/game")
@FeignClient(name = "soa-illidan-service")
public interface IGameRecordController {
/**
* @return
*/
@GetMapping(value = "/export")
void export(HttpServletResponse httpServletResponse) throws IOException;
}
this is the implemention:
@Override
public void export(HttpServletResponse response) throws IOException {
EasyExcel.write(response.getOutputStream(), DemoData.class).sheet("bala").doWrite(data());
}
private List<DemoData> data() {
List<DemoData> list = new ArrayList<DemoData>();
for (int i = 0; i < 10; i++) {
DemoData data = new DemoData();
data.setString("bala" + i);
data.setDate(new Date());
data.setDoubleData(0.56);
list.add(data);
}
return list;
}
but when I using this url to download the excel:
https://api.example.com/illidan-hub/illidan/report/game/export
it not pop up the download UI in my browser and return 401 Unauthorized. I am dedugging the code,and it runs in server success and no error output. What should I do to make it works? This is DemoData class define:
@Data
public class DemoData {
@ExcelProperty("string")
private String string;
@ExcelProperty("date")
private Date date;
@ExcelProperty("number")
private Double doubleData;
@ExcelIgnore
private String ignore;
}