How to make it as downloadable excel file using servlets

前端 未结 2 802
甜味超标
甜味超标 2021-01-22 08:46

I am reading a txt file and writing it into excel file, but while making it as downloadable excel file it is not writing any data to excel and giving showing this message

2条回答
  •  孤独总比滥情好
    2021-01-22 09:49

    Your writeDataToExcelFile method writes the Excel data into a FileOutputStream - this is not connected to the response OutputStream.

    You should update the writeDataToExcelFile method to include another parameter:

    private void writeDataToExcelFile(String string, 
                                      ArrayList> excelData,
                                      OutputStream outputStream) 
    

    and the writing of the data, change to this:

    myWorkBook.write(outputStream);
    

    This should then permit the myWorkBook object to write back to the browser.

    Also, change the line that calls the method to:

    writeDataToExcelFile("praveen",exceldata, response.getOutputStream());
    

提交回复
热议问题