poi-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Osmosis Paul <politr...@hotmail.com>
Subject Re: Create a XSSFWorkbook from a XSSFReder
Date Tue, 03 Aug 2010 16:30:59 GMT

Thanks Nick the point is that i was reading in internet and Apache FAQ web
page but i can not find any information about how modify the information
that we load from a xlsx into a XSSFReader and save as a Xlsx again, i just
saw the XSSFReader class and saw a constructor that accepted an inputStream
that's why i try to execute that code.
As i told, i need load an xslx something that already made it, but now i
would like modify information of this and save again, that's why i created
that's code:

     public void createNewXLSX(InputStream stream, int index){
        // Write the output to a file
        FileOutputStream fileOut = null;
        try {
           // OPCPackage xlsxPackage = OPCPackage.open(stream);
            XSSFWorkbook wb = new XSSFWorkbook(stream);
            fileOut = new FileOutputStream(index +".xlsx");
            wb.write(fileOut);
           fileOut.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();  //To change body of catch statement use
File | Settings | File Templates.
        } catch (IOException e) {
            e.printStackTrace();  //To change body of catch statement use
File | Settings | File Templates.
//        } catch (InvalidFormatException e) {
//            e.printStackTrace();  //To change body of catch statement use
File | Settings | File Templates.
        }
     }

My xslx have 5 sheets so my idea was load whole file, modify information of
several rows and save every sheet if it is possible into a new xslx file.
What do you think.




Nick Burch-11 wrote:
> 
> On Tue, 3 Aug 2010, Osmosis Paul wrote:
>>        XSSFReader.SheetIterator iter = (XSSFReader.SheetIterator)
>> xssfReader.getSheetsData();
>>        int index = 0;
>>        while (iter.hasNext()) {
>>            InputStream stream = iter.next();
>>            XSSFWorkbook wb = new XSSFWorkbook(stream);  //Here have the
>> error
> 
> I'm not entirely sure what you're trying to do, but the above line really 
> will never work....
> 
> If you want to use XSSFWorkbook, then you have to give it the whole file, 
> and you then don't need to touch XSSFReader
> 
> If you want to use XSSFReader, then you can't use XSSFWorkbook, and you 
> need to handle the sheet yourself
> 
> Nick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org
> 
> 
> 

-- 
View this message in context: http://old.nabble.com/Create-a-XSSFWorkbook-from-a-XSSFReder-tp29337186p29337466.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


Mime
View raw message