You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2013/03/08 12:50:56 UTC

[Bug 54654] New: Can not use same file for reading and writing a Workbook

https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

            Bug ID: 54654
           Summary: Can not use same file for reading and writing a
                    Workbook
           Product: POI
           Version: 3.9
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: POI Overall
          Assignee: dev@poi.apache.org
          Reporter: CarlVolhard@web.de
    Classification: Unclassified

I want to open read a workbook from a file and then safe it back to this file.

Workbook wb = WorkbookFactory.create("file.xlsx");
FileOutputStream fileOut = new FileOutputStream("file.xlsx");
wb.write(fileOut);
fileOut.close();

throws:
Exception in thread "main" org.apache.poi.POIXMLException: java.io.IOException:
Can't obtain the input stream from /docProps/app.xml
    at org.apache.poi.POIXMLDocument.getProperties(POIXMLDocument.java:141)
    at org.apache.poi.POIXMLDocument.write(POIXMLDocument.java:177)
    at line wb.write(fileOut)
Caused by: java.io.IOException: Can't obtain the input stream from
/docProps/app.xml
    at
org.apache.poi.openxml4j.opc.PackagePart.getInputStream(PackagePart.java:500)
    at org.apache.poi.POIXMLProperties.<init>(POIXMLProperties.java:75)
    at org.apache.poi.POIXMLDocument.getProperties(POIXMLDocument.java:139)
    ... 2 more

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54654] Can not use same file for reading and writing a Workbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

Carl Volhard <Ca...@web.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |CLOSED

--- Comment #6 from Carl Volhard <Ca...@web.de> ---
Thanks. Got it working.
An example for Windows in your HOWTO could be helpful.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54654] Can not use same file for reading and writing a Workbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

Carl Volhard <Ca...@web.de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW

--- Comment #2 from Carl Volhard <Ca...@web.de> ---
Yes it works, if I take another filename. The program runs under windows, so i
didn't try it on a linux system.
Is using a different file for writing the recommended way? Then it should be
descriped in the docs.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54654] Can not use same file for reading and writing a Workbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

--- Comment #5 from Nick Burch <ap...@gagravarr.org> ---
Well written Java programs can run anywhere, but there remain a few platform
specific ways you can shoot yourself in the foot...

On Windows, you either need to full close the input stream *before* trying to
open it again for writing, or you need to write to another file.

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54654] Can not use same file for reading and writing a Workbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

--- Comment #4 from Carl Volhard <Ca...@web.de> ---
Shouldn't a Java program run on all OSs?

Can you give me some example code for opening a workbook from an existing file
and writing into to it on windows?

Thanks!

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54654] Can not use same file for reading and writing a Workbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

Nick Burch <ap...@gagravarr.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |NEEDINFO

--- Comment #1 from Nick Burch <ap...@gagravarr.org> ---
Windows is fussy about reading and writing to the same file, so that might be
it. Does it work if you save to a different file name? Does it work if you try
it on linux?

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


RE: [Bug 54654] Can not use same file for reading and writing a Workbook [I]

Posted by Mladen Covic <ml...@db.com>.
Classification: For internal use only

Nick,

I don't think your statement (comment #3) is a exactly correct one. Windows does allow simultaneous read AND write on a single instance of the File object. It can be obtained through the RandomFileAccess object that can read and write at the same time ("rw" argument in the constructor). That being said, I don't know if this is useful to POI at all if in POI you access files through streams that are already implemented. If, on the other hand, you are interested only in low level byte read/write you can do it through random access file object.

Mladen Covic

-----Original Message-----
From: bugzilla@apache.org [mailto:bugzilla@apache.org]
Sent: Tuesday, March 12, 2013 1:44 PM
To: dev@poi.apache.org
Subject: [Bug 54654] Can not use same file for reading and writing a Workbook

https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

Nick Burch <ap...@gagravarr.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Nick Burch <ap...@gagravarr.org> --- It's a standard restriction on windows, nothing POI specific. You'll either need to use a 2nd file, or close the original one before trying to write out to it. Or switch to an OS without the restrictions!

--
You are receiving this mail because:
You are the assignee for the bug.

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


---
This communication may contain confidential and/or privileged information. If you are not the intended recipient (or have received this communication in error) please notify the sender immediately and destroy this communication. Any unauthorized copying, disclosure or distribution of the material in this communication is strictly forbidden.

Deutsche Bank does not render legal or tax advice, and the information contained in this communication should not be regarded as such.

[Bug 54654] Can not use same file for reading and writing a Workbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

Nick Burch <ap...@gagravarr.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |INVALID

--- Comment #3 from Nick Burch <ap...@gagravarr.org> ---
It's a standard restriction on windows, nothing POI specific. You'll either
need to use a 2nd file, or close the original one before trying to write out to
it. Or switch to an OS without the restrictions!

-- 
You are receiving this mail because:
You are the assignee for the bug.

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


[Bug 54654] Can not use same file for reading and writing a Workbook

Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=54654

--- Comment #7 from Nick Burch <ap...@gagravarr.org> ---
Send in the text and we'll add it!

-- 
You are receiving this mail because:
You are the assignee for the bug.

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