-3

How to close an opened excel file?

Open excel code is:

File file = new File("e:\\aaa.xlsx");
Desktop desktop = Desktop.getDesktop();
desktop.open(file);

What would be the close code?

just using java open and close Windows application like use mouse.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
moysakura
  • 27
  • 1
  • 3

1 Answers1

3

Forget it. Open here means that the registered application, Excel, takes over and opens a Window. After that you have no control, but watching. Excel will close.

File is a class that represents a file system path. Itself it has no state of associated reader/writer. Java 7 now parallel introduces a more evolved class Path. Besides (obviously) the path on the file system, it also stores what file system. With Path one can have more than one FileSystem, like a ZipFileSystem. That allows you to copy and rename files in a zip.

That was just an elaboration.

Joop Eggen
  • 107,315
  • 7
  • 83
  • 138
  • thank you ! any other solution for open and close excel file? – moysakura Jun 28 '13 at 08:22
  • Do you mean reading/writing an Excel file in java, or starting/quitting the Excel application? I believe, an Excel sheet might even be used as a database with ODBC/JDBC [link](http://www.ehow.com/how_4810548_use-jdbc-connect-ms-excel.html). Though much one sees Apache POI and such. – Joop Eggen Jun 28 '13 at 08:23
  • start and close excel,like in Windows.thank you . (sorry , my english is very bad) – moysakura Jun 28 '13 at 08:28
  • Maybe with its own [process](http://www.avajava.com/tutorials/lessons/how-do-i-run-another-application-from-java.html). – Joop Eggen Jun 28 '13 at 09:00