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

  • SEARCH
  • Home
  • 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 6120425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:40:01+00:00 2026-05-23T15:40:01+00:00

Using Apache POI HSSF, we can create xls file like this private void write(HSSFWorkbook

  • 0

Using Apache POI HSSF, we can create xls file like this

private void write(HSSFWorkbook workbook) {
    POIFSFileSystem filesystem = new POIFSFileSystem();
    filesystem.createDocument(new ByteArrayInputStream(workbook.getBytes()), 
                    "Workbook");
    FileOutputStream stream = new FileOutputStream("test.xls");
    filesystem.writeFilesystem(stream);
}

Similarly, how can I write with XSSFWorkbook? This does not have the getBytes() method.
I tried to create ByteArrayInputStream from XSSFWorkbook like this –

ByteArrayOutputStream baos = new ByteArrayOutputStream();
workbook.write(baos); //XSSFWorkbook here
ByteArrayInputStream bias = new ByteArrayInputStream(baos.toByteArray());

But the xlsx file created was corrupt. How can I write the workbook to disc using POIFSFileSystem?

The same XSSFWorkbook was written sucessfully when I did like this –

FileOutputStream stream = new FileOutputStream("test.xlsx");
workbook.write(stream);

When I extracted and compared the xlsx files, there was no difference. However, when I do a plain text compare on the xlsx files directly (without extracting), there are few differences in the bytes.

So the problem should be in the createDocument() and/or writeFilesystem() methods of POIFSFileSystem. Can someone let me know how to write XSSFWorkbook using POIFSFileSystem?

  • 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. Editorial Team
    Editorial Team
    2026-05-23T15:40:01+00:00Added an answer on May 23, 2026 at 3:40 pm

    You can’t!

    POIFSFileSystem works with OLE2 files, such as .xls, .doc, .ppt, .msg etc. The POIFS code handles reading and writing the individual streams within that for you.

    With the OOXML files (.xlsx, .docx, .pptx etc), the container for the file is no longer OLE2. Instead, the files are stored within a Zip container. In POI, this is handled by OPCPackage, which takes care of reading and writing from Zip files with the required OOXML metadata.

    If you want to write a XSSF file to disk, simply do:

    FileOutputStream stream = new FileOutputStream("test.xlsx");
    workbook.write(stream);
    stream.close();
    

    And XSSFWorkbook will handle talking to OPCPackage for you to make that happen.

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

Sidebar

Related Questions

In Java, we're using the following package to programmatically create excel documents: org.apache.poi.hssf If
I'm using Apache POI to create xls spreadsheets. Is there a way to detect
I am using the following the following class org.apache.poi.hssf.usermodel.HSSFCell , with a list of
Whilst trying to parse MS Excel file using POI-HSSF v3.2 I am getting IndexOutOfBoundsException.
I am using Apache POI to store data in excel sheet. I can store
I want to set comments for 3 excel cells using Apache POI. This is
I'm using apache poi to create an excel document. To create new sheet in
I am using Apache POI-HSSF for working with Excel files. I have a cell
How can i print Ms Office documents using Apache POI ?Can u provide me
I am using Apache HttpClient and would like to communicate HTTP errors (400 Bad

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.