How to make it as downloadable excel file using servlets

前端 未结 2 784
甜味超标
甜味超标 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:38

    I would strongly discourage implementing this on your own, since you are very likely forget some special cases, for example concerning different separators, special characters, ...

    Instead, use one of the many existing libraries for that.

    0 讨论(0)
  • 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<ArrayList<String>> 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());
    
    0 讨论(0)
提交回复
热议问题