You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Palladian1881 <ds...@westminstercollege.edu> on 2011/07/14 21:21:13 UTC

Problem loading Excel file

I'm trying to load Excel files. Here's what I have so far:

import java.io.*;
import java.util.*;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.*;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Cell;  
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;


public class MergeExcel {
  public MergeExcel(String fileOne, String fileTwo, String fileThree, String
fileFour) throws InvalidFormatException, IOException{
    InputStream one = new FileInputStream(fileOne); 
    InputStream two = new FileInputStream(fileTwo); 
    InputStream three = new FileInputStream(fileThree); 
    InputStream four = new FileInputStream(fileFour); 
    //FileOutputStream stream = new FileOutputStream(fileOne);
    
    Workbook wb1 = new HSSFWorkbook(one);
    Workbook wb2 = WorkbookFactory.create(one); 

When I try to create a workbook using HSSFWorkbook(), I get this exception:
java.io.IOException: Unable to read entire header; 0 bytes read; expected 32
bytes

When I try to use WorkbookFactory.create(), I get this exception:
java.lang.IllegalArgumentException: Your InputStream was neither an OLE2
stream, nor an OOXML stream> 

How can I fix this problem?

Thank in advance.
(Also, I'm finding that "import org.apache.poi.*;" doesn't cut it--I'm
having spell out every individual thing I want imported. It's not a big
deal, I'm just wondering if I'm doing something stupid.)



--
View this message in context: http://apache-poi.1045710.n5.nabble.com/Problem-loading-Excel-file-tp4587882p4587882.html
Sent from the POI - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org


Re: Problem loading Excel file

Posted by Nick Burch <ni...@alfresco.com>.
On Thu, 14 Jul 2011, Palladian1881 wrote:
> When I try to use WorkbookFactory.create(), I get this exception: 
> java.lang.IllegalArgumentException: Your InputStream was neither an OLE2 
> stream, nor an OOXML stream>

As the exception says, what you've given poi is neither a .xls file nor a 
.xlsx file. You need to figure out what it actually is, and give it to an 
appropriate library based on that. For example, try opening it in a text 
editor - is it in fact a .csv or a .html file?

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org