This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

checking that an excel file is already opened by another application  RSS feed

 
Clare McLennan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the following code to check if an excel file is aready open by another app:-



When the file is already open, the following error is generated which I successfully catch and handle:-




All is fine. I shut the excel spreadsheet manually then run my application again. At the point where testOut.close() is executed, above - the file content is erased completely and I am left with a 0k file!

Please would someone be able to tell me where I am going wrong?

many thanks

Clare
 
Joe Ess
Bartender
Posts: 9425
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FileOutputStream, in fact all Streams and Readers, by default open a file for writing (or overwriting, if it exists). What you want to do is open the file for appending. Have a look at the javadoc and you'll find the appropriate constructor.
 
Clare McLennan
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm afraid I already tried that using the following code:



Problem is that this does not generate an error in the same way as the original code does. I want to check the file is open so I can close it. I am updating existing rows in the spreadsheet. The only thing that works is when the file is not opened by other users, and the FileOutputStream is opened using only the filename in the constructor. Appending the file (regardless of whether it is already open or closed) does not work. I'm looking for an elegant way of checking it is open before I attempt to write to it.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!