You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by Aram Mirzadeh <aw...@mbcli.com> on 2010/12/06 04:38:25 UTC

Updating an embedded Excel file inside Word

Hi,

I'm reading in a docx (2007 xml based [actually it's from word 2010]) 
file which has a Excel chart embedded in it (suprisingly it isn't xlsx, 
it's binary xls file format).

I'm trying to update the values for the excel chart.   I can read the 
docx, get the embeded object, and read and modify the cells that I 
need.   My question is how do you save the embedded excel file?  The way 
I normally do it is to do a Stream out to a file, however in this case 
that just generates a new file and does not update the embedded file.

Here is what I have so far:

final FileInputStream fis = new FileInputStream(new File("c:\\test.docx"));
         final XWPFDocument doc = new XWPFDocument(fis);

         for (final PackagePart pPart : doc.getAllEmbedds()) {
             final String contentType = pPart.getContentType();
             System.out.println(contentType + "\n");
             if (contentType.equals("application/vnd.ms-excel")) {
                 final HSSFWorkbook embeddedWorkbook = new 
HSSFWorkbook(pPart.getInputStream());

                 for (int sheet = 0 ; sheet < 
embeddedWorkbook.getNumberOfSheets(); sheet++) {
                     final HSSFSheet activeSheet = 
embeddedWorkbook.getSheetAt(sheet);
                     if 
(activeSheet.getSheetName().equalsIgnoreCase("Sheet1")) {
                         for (int rowIndex = 
activeSheet.getFirstRowNum() ; rowIndex <= activeSheet.getLastRowNum(); 
rowIndex++) {
                             final HSSFRow row = 
activeSheet.getRow(rowIndex);
                             for (int cellIndex = row.getFirstCellNum() 
; cellIndex <= row.getLastCellNum(); cellIndex++) {
                                 final HSSFCell cell = 
row.getCell(cellIndex);
                                 if (cell != null) {
                                     if (cell.getCellType() == 
Cell.CELL_TYPE_STRING)
                                         System.out.println("Row:" + 
rowIndex + " Cell:" + cellIndex + " = " + cell.getStringCellValue());
                                     if (cell.getCellType() == 
Cell.CELL_TYPE_NUMERIC) {
                                         System.out.println("Row:" + 
rowIndex + " Cell:" + cellIndex + " = " + cell.getNumericCellValue());
                                         
cell.setCellValue(cell.getNumericCellValue() * 2); // update the value
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }

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


Re: Updating an embedded Excel file inside Word

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
That's a surprise as it works quite well for me. If this is OK, I will send
the code I use to your personal email address - as this is now only
partially a POI discussion, I do not think it ought to take place on the
list really. The code I have ben using is scruffy and is very much test code
only so bear that in mind when you look at it please.

Yours

Mark B
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Updating-an-embedded-Excel-file-inside-Word-tp3293554p3301317.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: Updating an embedded Excel file inside Word

Posted by Aram Mirzadeh <aw...@mbcli.com>.
If I try what you suggest, the output file is actually corrupted.  I can 
still open the resulting word document in office (the original image is 
there, but it's no longer an excel embedded file) - I think the image 
that shows up is a cached image. If I try to open it back in POI, I get 
all sorts of exceptions.

Looking at the zip files, the embedded xls file shrinks from 86k to 
35k.   That tells me that the packagePart that is written back is not 
correct.

Aram

On 12/10/2010 10:52 AM, Mark Beardsley wrote:
> The approach I tried was this;
>
> Open the Word doucment by instntaiting the XWPFDocument class.
> Get the list of embedded documents.
> Iteratate through the list to find the embedded workbook.
> > From the PackagePart, recover an InputStream and use this to create an
> HSSFWorkbook object that allowed me to manipulate the embedded workbook.
> > From that same PackagePart, recover an OutputStream.
> Pass the OutputStream to the write method of the HSSFWorkbook.
> Finally, call the write method on the XWPFDocument.
>
> The resulting Word document was valid - in so far as Word would open it
> without complaint - but I found that the embedded workbook was now
> completely empty. All of the workbooks contents had been erased and I am
> guessing this was caused by the streaming process but cannot be at all
> certain as I have not investigated further.
>
> To date, the only way I have found to successfully update the embedded
> object is to use a mix of care java code to unzip and then re-zip the docx
> file and POI to manipulate the embedded workbook. This works but it still
> leaves the problem of updating the .emf to reflect the changes made to the
> embedded object.
>
> Yours
>
> Mark B


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


Re: Updating an embedded Excel file inside Word

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
The approach I tried was this;

Open the Word doucment by instntaiting the XWPFDocument class.
Get the list of embedded documents.
Iteratate through the list to find the embedded workbook.
>From the PackagePart, recover an InputStream and use this to create an
HSSFWorkbook object that allowed me to manipulate the embedded workbook.
>From that same PackagePart, recover an OutputStream.
Pass the OutputStream to the write method of the HSSFWorkbook.
Finally, call the write method on the XWPFDocument.

The resulting Word document was valid - in so far as Word would open it
without complaint - but I found that the embedded workbook was now
completely empty. All of the workbooks contents had been erased and I am
guessing this was caused by the streaming process but cannot be at all
certain as I have not investigated further.

To date, the only way I have found to successfully update the embedded
object is to use a mix of care java code to unzip and then re-zip the docx
file and POI to manipulate the embedded workbook. This works but it still
leaves the problem of updating the .emf to reflect the changes made to the
embedded object.

Yours

Mark B
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Updating-an-embedded-Excel-file-inside-Word-tp3293554p3300507.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: Updating an embedded Excel file inside Word

Posted by Aram Mirzadeh <aw...@mbcli.com>.
On 12/10/2010 6:51 AM, Mark Beardsley wrote:
> Hello Nick,
>
> No, that does not seem to work for me. The result is that the workbook in
> the embeddings folder is actually empty or blank following the write
> operation and using the OutputStream obtained from the PackagePart object.
> Also, deleting the .emf does not cause Word to update the image when the
> document is subsequently opened. The best compromise I found was to delete
> the image and then double click on where the object should have appeared -
> there was a red cross showing in the page to denote that something was
> missing. The double click caused Word to create another image for the
> worksheet page.
>
> Yours
>
> Mark B
Mark,

Did you actually get the OutputStream and convert it back to a zip part 
and be able to write it back out?  I can't even get that to work.  Mind 
sharing what you did?

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


Re: Updating an embedded Excel file inside Word

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Nick

Test created and logged with bugzilla. Have recompiled and run the test
against 3.8 beta1 just to ensure that any recent changes have not addressed
the issue and the test still fails - the file created by streaming is still
empty even though the correct information is streamed out; verified this by
simply writing it to a file on my disc.

Yours

Mark B
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Updating-an-embedded-Excel-file-inside-Word-tp3293554p3304880.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: Updating an embedded Excel file inside Word

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Will do Nick. Before I do that though, I do want to re-test the example
against the latest version of the API - currently, I am running it against
3.7 and do not want the result to be vaysed by my missing a feature that has
subsequently been added. With luck, I should be able to post tonight or
early Tuesday.

Yours

Mark B
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Updating-an-embedded-Excel-file-inside-Word-tp3293554p3302763.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: Updating an embedded Excel file inside Word

Posted by Aram Mirzadeh <aw...@mbcli.com>.
On 12/12/2010 11:26 PM, Nick Burch wrote:
> On Fri, 10 Dec 2010, Mark Beardsley wrote:
>> No, that does not seem to work for me. The result is that the 
>> workbook in
>> the embeddings folder is actually empty or blank following the write
>> operation and using the OutputStream obtained from the PackagePart 
>> object.
>
> Hmm. That ought to work. Any chance you could knock up a unit test for 
> that when you get a minute?
>
>> Also, deleting the .emf does not cause Word to update the image when 
>> the document is subsequently opened.
>
> Maybe you need to delete the image section from within the word 
> stream, as well as zapping the .emf itself. (I'm going on what was 
> suggested by someone a month or two back)
>
> Nick

Just to be clearn, Mark's method is different than what I am doing.

Mark is --- Unzipping docx on the filesystem, opening the xls embedded 
file as a File in POI, and re-assemblying the original docx from the 
resulting files.
Mine method, I'm opening the docx withing POI streams and opening the 
embedded streams and trying to write only that porition back.

I'm going to use his method to do what I need to get done which is due 
today, but I think my method is the cleaner more portable way of doing it.

Aram

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


Re: Updating an embedded Excel file inside Word

Posted by Nick Burch <ni...@alfresco.com>.
On Fri, 10 Dec 2010, Mark Beardsley wrote:
> No, that does not seem to work for me. The result is that the workbook in
> the embeddings folder is actually empty or blank following the write
> operation and using the OutputStream obtained from the PackagePart object.

Hmm. That ought to work. Any chance you could knock up a unit test for 
that when you get a minute?

> Also, deleting the .emf does not cause Word to update the image when the 
> document is subsequently opened.

Maybe you need to delete the image section from within the word stream, as 
well as zapping the .emf itself. (I'm going on what was suggested by 
someone a month or two back)

Nick

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


Re: Updating an embedded Excel file inside Word

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Hello Nick,

No, that does not seem to work for me. The result is that the workbook in
the embeddings folder is actually empty or blank following the write
operation and using the OutputStream obtained from the PackagePart object.
Also, deleting the .emf does not cause Word to update the image when the
document is subsequently opened. The best compromise I found was to delete
the image and then double click on where the object should have appeared -
there was a red cross showing in the page to denote that something was
missing. The double click caused Word to create another image for the
worksheet page.

Yours

Mark B
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Updating-an-embedded-Excel-file-inside-Word-tp3293554p3300184.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: Updating an embedded Excel file inside Word

Posted by Nick Burch <ni...@alfresco.com>.
On Thu, 9 Dec 2010, Aram Mirzadeh wrote:
> Well I tried everything I could think of.  I cannot seem to figure out 
> how to write that one section back in.  I even tried recreating the zip 
> file but word thinks that it's corrupted so I'm doing something wrong.

Just get the OutputStream for the PackagePart you're reading from, and 
pass that to the hssf write method. Won't that do it?

Nick

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


Re: Updating an embedded Excel file inside Word

Posted by Aram Mirzadeh <aw...@mbcli.com>.
On 12/8/2010 8:06 PM, Nick Burch wrote:
> On Wed, 8 Dec 2010, Aram Mirzadeh wrote:
>> Let me make sure I'm on the right path here, because this isn't 
>> sticking in my head yet.
>>
>> 1. Open the docx
>> 2. Get all embedded part as pPart
>> 3. Use pPart.getPartName().getName() to get the name of the embedded 
>> file.
>
> You might want to do this with relationships rather than enumerating 
> all the names.
>
>> 4. Open the pPart.
>> 5. Find and modify the cells that I want.
>> 6. Re-Open the docx as a ZipInputStream
>
> You shouldn't need to do this. Just write back to the part you already 
> have to hand, then write out the overall package when done.
>
>> // TODO ... also need to find the original image of the chart and 
>> delete that out of the docx so that it's re-generated.
>
> I think you might be able to spot this using the relationships, but I 
> might be wrong. I'd suggest you look at the xml of a few sample files 
> (both of the document stream and the relationships of it) to figure 
> out what's done
>
>> That seems like it's very awkward.  Any examples or piece of code 
>> that you can point me to that does this?
>
> Maybe not, but there is some code in Apache Tika that does steps 1-4 
> for you, in the context of text extraction with embedded attachemnts. 
> If you do get this working, do please submit an example though!

Well I tried everything I could think of.  I cannot seem to figure out 
how to write that one section back in.  I even tried recreating the zip 
file but word thinks that it's corrupted so I'm doing something wrong.

Aram

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


Re: Updating an embedded Excel file inside Word

Posted by Nick Burch <ni...@alfresco.com>.
On Wed, 8 Dec 2010, Aram Mirzadeh wrote:
> Let me make sure I'm on the right path here, because this isn't sticking in 
> my head yet.
>
> 1. Open the docx
> 2. Get all embedded part as pPart
> 3. Use pPart.getPartName().getName() to get the name of the embedded file.

You might want to do this with relationships rather than enumerating all 
the names.

> 4. Open the pPart.
> 5. Find and modify the cells that I want.
> 6. Re-Open the docx as a ZipInputStream

You shouldn't need to do this. Just write back to the part you already 
have to hand, then write out the overall package when done.

> // TODO ... also need to find the original image of the chart and delete that 
> out of the docx so that it's re-generated.

I think you might be able to spot this using the relationships, but I 
might be wrong. I'd suggest you look at the xml of a few sample files 
(both of the document stream and the relationships of it) to figure out 
what's done

> That seems like it's very awkward.  Any examples or piece of code that 
> you can point me to that does this?

Maybe not, but there is some code in Apache Tika that does steps 1-4 for 
you, in the context of text extraction with embedded attachemnts. If you 
do get this working, do please submit an example though!

Nick

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


Re: Updating an embedded Excel file inside Word

Posted by Aram Mirzadeh <aw...@mbcli.com>.
On 12/7/2010 7:56 PM, Nick Burch wrote:
> On Tue, 7 Dec 2010, Aram Mirzadeh wrote:
>> On 12/7/2010 12:47 AM, Nick Burch wrote:
>>> On Sun, 5 Dec 2010, Aram Mirzadeh wrote:
>>>> I'm trying to update the values for the excel chart.   I can read 
>>>> the docx, get the embeded object, and read and modify the cells 
>>>> that I need. My question is how do you save the embedded excel file?
>>>
>>> You'll get the ooxml document part for the embedded file, from which 
>>> you get the input stream to read it. You should be able to get an 
>>> output
>>> stream onto the same part too, to save the changed version.
>>
>> I was with you until the "output stream onto the same part".  If it's 
>> an inputstream for the file, how do you write it back out as the same 
>> part?
>
> The PackagePart is read/write. You can get both an inputstream and an 
> outputstream from it
> http://poi.apache.org/apidocs/org/apache/poi/openxml4j/opc/PackagePart.html 
>
>
Let me make sure I'm on the right path here, because this isn't sticking 
in my head yet.

1. Open the docx
2. Get all embedded part as pPart
3. Use pPart.getPartName().getName() to get the name of the embedded file.
4. Open the pPart.
5. Find and modify the cells that I want.
6. Re-Open the docx as a ZipInputStream
7. find the embedded file inside of the zip via step #3
8. save the pPart as a ZipEntry file?
9. save the Zip from #5?

// TODO ... also need to find the original image of the chart and delete 
that out of the docx so that it's re-generated.

That seems like it's very awkward.   Any examples or piece of code that 
you can point me to that does this?


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


Re: Updating an embedded Excel file inside Word

Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 7 Dec 2010, Aram Mirzadeh wrote:
> On 12/7/2010 12:47 AM, Nick Burch wrote:
>> On Sun, 5 Dec 2010, Aram Mirzadeh wrote:
>>> I'm trying to update the values for the excel chart.   I can read the 
>>> docx, get the embeded object, and read and modify the cells that I need. 
>>> My question is how do you save the embedded excel file?
>> 
>> You'll get the ooxml document part for the embedded file, from which you 
>> get the input stream to read it. You should be able to get an output
>> stream onto the same part too, to save the changed version.
>
> I was with you until the "output stream onto the same part".  If it's an 
> inputstream for the file, how do you write it back out as the same part?

The PackagePart is read/write. You can get both an inputstream and an 
outputstream from it
http://poi.apache.org/apidocs/org/apache/poi/openxml4j/opc/PackagePart.html

Nick

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


Re: Updating an embedded Excel file inside Word

Posted by Aram Mirzadeh <aw...@mbcli.com>.
On 12/7/2010 12:47 AM, Nick Burch wrote:
> On Sun, 5 Dec 2010, Aram Mirzadeh wrote:
>> I'm trying to update the values for the excel chart.   I can read the 
>> docx, get the embeded object, and read and modify the cells that I 
>> need.   My question is how do you save the embedded excel file?
>
> You'll get the ooxml document part for the embedded file, from which 
> you get the input stream to read it. You should be able to get an output
> stream onto the same part too, to save the changed version.

I was with you until the "output stream onto the same part".  If it's an 
inputstream for the file, how do you write it back out as the same part?

>
> Note that an embedded document is usually emf rendering of the 
> contents + the contents themselves. Saving the excel spreadsheet won't 
> change the image, so you might want to remove the image to force word 
> to re-generate the excel view on next load. Otherwise, you'd see the 
> old file until you clicked on the spreadsheet.

Ah, this is a good point.  I'll have to see if I can figure out how to 
do this after updating the embedded file.

Aram

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


Re: Updating an embedded Excel file inside Word

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Thanks Nick, looks like you saved me some time.

Yours

Mark B


-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Updating-an-embedded-Excel-file-inside-Word-tp3293554p3295371.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: Updating an embedded Excel file inside Word

Posted by Nick Burch <ni...@alfresco.com>.
On Sun, 5 Dec 2010, Aram Mirzadeh wrote:
> I'm trying to update the values for the excel chart.   I can read the docx, 
> get the embeded object, and read and modify the cells that I need.   My 
> question is how do you save the embedded excel file?

You'll get the ooxml document part for the embedded file, from which you 
get the input stream to read it. You should be able to get an output
stream onto the same part too, to save the changed version.

Note that an embedded document is usually emf rendering of the contents + 
the contents themselves. Saving the excel spreadsheet won't change the 
image, so you might want to remove the image to force word to re-generate 
the excel view on next load. Otherwise, you'd see the old file until you 
clicked on the spreadsheet.

Nick

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


Re: Updating an embedded Excel file inside Word

Posted by Mark Beardsley <ma...@tiscali.co.uk>.
Hello Aram

I do not know if you are aware of this but the Word file you are dealing
with is actually zipped xml. It should be possible to use a utility such as
WinRAR or PKUnzip to open the file and reveal it's underlying structure.
Now, I am guessing that if you do this and then take a dig around, that
somewhere in those files will be the binary 'source' for the embedded
document and it is this that you will need to update. Speaking off of the
top of my head, you may be able to use a combination of POI and core java
code to accomplish the task. At the moment, I am imagining something where
you use POI to recover the Excel document and update it. the, stream out to
a file on your local drive. Next, you use the core java api to unzip the
document, open a stream onto the Excel document you created earlier and then
stream it's contents into the appropriate location within the Word zip file.
Finally, the core java api can be used to create a new zipped, and updated,
file. If I have the chance, I will play around with something like this in
the next couple of days - the weather is making it impossible for us to work
outside currently. Should it prove to be sucessful, I will post the code
here.

Another course of action would be to look at the xmlbeans code that
underpins XWPF. I suspect that somewhere there will ne in place the hooks
required to allow us to work with embedded files in the manner you require -
for example creating something like an setEmbeddedDocument() method. If you
can download a copy of the project's source and if you have the time, it may
ne worthwhile starting to dig into the inner workings to try and find out if
this is possible.

Yours

Mark B

PS Thinking about it further, it might - and that is might - be possible to
unzip the Word document and open an HSSFWorkbook on the embedded object
directly, update it, stream it to disc and then re-zip the Word document.
Will take a look at this also.
-- 
View this message in context: http://apache-poi.1045710.n5.nabble.com/Updating-an-embedded-Excel-file-inside-Word-tp3293554p3294398.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: Updating an embedded Excel file inside Word

Posted by Aram Mirzadeh <aw...@mbcli.com>.
Forgot to mention that I'm on POI 3.7.

Thanks.

On 12/5/2010 10:38 PM, Aram Mirzadeh wrote:
>
> Hi,
>
> I'm reading in a docx (2007 xml based [actually it's from word 2010]) 
> file which has a Excel chart embedded in it (suprisingly it isn't 
> xlsx, it's binary xls file format).
>
> I'm trying to update the values for the excel chart.   I can read the 
> docx, get the embeded object, and read and modify the cells that I 
> need.   My question is how do you save the embedded excel file?  The 
> way I normally do it is to do a Stream out to a file, however in this 
> case that just generates a new file and does not update the embedded 
> file.
>
> Here is what I have so far:
>
> final FileInputStream fis = new FileInputStream(new 
> File("c:\\test.docx"));
>         final XWPFDocument doc = new XWPFDocument(fis);
>
>         for (final PackagePart pPart : doc.getAllEmbedds()) {
>             final String contentType = pPart.getContentType();
>             System.out.println(contentType + "\n");
>             if (contentType.equals("application/vnd.ms-excel")) {
>                 final HSSFWorkbook embeddedWorkbook = new 
> HSSFWorkbook(pPart.getInputStream());
>
>                 for (int sheet = 0 ; sheet < 
> embeddedWorkbook.getNumberOfSheets(); sheet++) {
>                     final HSSFSheet activeSheet = 
> embeddedWorkbook.getSheetAt(sheet);
>                     if 
> (activeSheet.getSheetName().equalsIgnoreCase("Sheet1")) {
>                         for (int rowIndex = 
> activeSheet.getFirstRowNum() ; rowIndex <= 
> activeSheet.getLastRowNum(); rowIndex++) {
>                             final HSSFRow row = 
> activeSheet.getRow(rowIndex);
>                             for (int cellIndex = row.getFirstCellNum() 
> ; cellIndex <= row.getLastCellNum(); cellIndex++) {
>                                 final HSSFCell cell = 
> row.getCell(cellIndex);
>                                 if (cell != null) {
>                                     if (cell.getCellType() == 
> Cell.CELL_TYPE_STRING)
>                                         System.out.println("Row:" + 
> rowIndex + " Cell:" + cellIndex + " = " + cell.getStringCellValue());
>                                     if (cell.getCellType() == 
> Cell.CELL_TYPE_NUMERIC) {
>                                         System.out.println("Row:" + 
> rowIndex + " Cell:" + cellIndex + " = " + cell.getNumericCellValue());
>                                         
> cell.setCellValue(cell.getNumericCellValue() * 2); // update the value
>                                     }
>                                 }
>                             }
>                         }
>                     }
>                 }
>             }
>         }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org


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