Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 100709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:37:53+00:00 2026-05-11T00:37:53+00:00

I want my web application users to download some data as an Excel file.

  • 0

I want my web application users to download some data as an Excel file.

I have the next function to send an Input Stream in the response object.

public static void sendFile(InputStream is, HttpServletResponse response) throws IOException {         BufferedInputStream in = null;         try {             int count;             byte[] buffer = new byte[BUFFER_SIZE];             in = new BufferedInputStream(is);             ServletOutputStream out = response.getOutputStream();             while(-1 != (count = in.read(buffer)))                 out.write(buffer, 0, count);             out.flush();                     }   catch (IOException ioe) {              System.err.println('IOException in Download::sendFile');              ioe.printStackTrace();         } finally {             if (in != null) {                 try { in.close();                  } catch (IOException ioe) { ioe.printStackTrace(); }             }            }     } 

I would like to transform my HSSFWorkbook Object to an input stream and pass it to the previous method.

public InputStream generateApplicationsExcel() {     HSSFWorkbook wb = new HSSFWorkbook();     // Populate the excel object     return null; // TODO. return the wb as InputStream  } 

http://poi.apache.org/apidocs/org/apache/poi/hssf/usermodel/HSSFWorkbook.html

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:37:54+00:00Added an answer on May 11, 2026 at 12:37 am

    The problem with your question is that you are mixing OutputStreams and InputStreams. An InputStream is something you read from and an OutputStream is something you write to.

    This is how I write a POI object to the output stream.

    // this part is important to let the browser know what you're sending response.setContentType('application/vnd.ms-excel'); // the next two lines make the report a downloadable file; // leave this out if you want IE to show the file in the browser window String fileName = 'Blah_Report.xls'; response.setHeader('Content-Disposition', 'attachment; filename=' + fileName);   // get the workbook from wherever HSSFWorkbook wb = getWorkbook(); OutputStream out = response.getOutputStream(); try {    wb.write(out); }        catch (IOException ioe) {    // if this happens there is probably no way to report the error to the user   if (!response.isCommited()) {     response.setContentType('text/html');     // show response text now   } } 

    If you wanted to re-use your existing code you’d have to store the POI data somewhere then turn THAT into an input stream. That’d be easily done by writing it to a ByteArrayOutputStream, then reading those bytes using a ByteArrayInputStream, but I wouldn’t recommend it. Your existing method would be more useful as a generic Pipe implementation, where you can pipe the data from an InputStream to and OutputStream, but you don’t need it for writing POI objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a winform application that uses some referenced web services to get data.
I just want to send SMS from my web application in PHP. Can anyone
I have a web application using ASP.NET 2.0 and I want to know if
I have a web application that is becoming rather large. I want to separate
I have this web application that has grown to an unmanageable mess. I want
I have an application in which I change the data on web and then
I have Chinese users of my PHP web application who enter products into our
i have made a small web application with form.html output.jsp ServletOne.java In the form.html,users
I am developing a test engine web application. Users will be give some amount
Imagine that you want to develop a non-trivial end-user desktop (not web) application in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.