You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "Murphy, Mark" <mu...@metalexmfg.com> on 2017/02/01 14:49:58 UTC

Saving modified Workbook in place

I thought that there was a way to save a workbook in place when using a File type input. But I can't find the secret sauce. If I open a Workbook using WorkbookFactory(new File(filename)); I cannot write to an output stream based on the same file name. If I write the modified workbook to an output stream based on a different file name, the original file is updated, but now I have a second file. If I do not write the changes, but instead just close the workbook, it does not create the second file, but it also does not update the existing file.

So how can I update an existing spreadsheet without creating a secondary file? I am guessing that if I use an InputStream to open the initial file, I can write the updated workbook to an OutputStream without the original being updated?

Re: Saving modified Workbook in place

Posted by Nick Burch <ap...@gagravarr.org>.
On Wed, 1 Feb 2017, Murphy, Mark wrote:
> I thought that there was a way to save a workbook in place when using a 
> File type input. But I can't find the secret sauce.

The method will be write() with no arguments:
https://poi.apache.org/apidocs/org/apache/poi/POIDocument.html#write()

Off the top of my head, I can't remember how much more work there is to do 
to finish the HSSF support for it...

Nick

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


Re: Saving modified Workbook in place

Posted by Javen O'Neal <ja...@gmail.com>.
https://bz.apache.org/bugzilla/show_bug.cgi?id=57919

This bug is still open as it hasn't been fully implemented for all
constructors and factories yet.

On Feb 1, 2017 06:50, "Murphy, Mark" <mu...@metalexmfg.com> wrote:

> I thought that there was a way to save a workbook in place when using a
> File type input. But I can't find the secret sauce. If I open a Workbook
> using WorkbookFactory(new File(filename)); I cannot write to an output
> stream based on the same file name. If I write the modified workbook to an
> output stream based on a different file name, the original file is updated,
> but now I have a second file. If I do not write the changes, but instead
> just close the workbook, it does not create the second file, but it also
> does not update the existing file.
>
> So how can I update an existing spreadsheet without creating a secondary
> file? I am guessing that if I use an InputStream to open the initial file,
> I can write the updated workbook to an OutputStream without the original
> being updated?
>