I'm making a project in which the user has to give in a document with data. The program reads the data and makes some diagrams. It al works perfectly but i want to open the ExcelFile when the user has saved it...So I know the directory of the Excelfile but i don't know how to open an excelfile in javaFX, can someone help me?
kind regards
The JavaFX way to do this is
File excelFile = new File("/path/to/excel/file");
getHostServices().showDocument(excelFile.toURI().toURL().toExternalForm());
getHostServices()
is defined in Application
, so if you want to do this in another class (a controller, for example), you will have to arrange for the other class to be able to access the host services.
E.g.
public class MyApp extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
FXMLLoader loader = new FXMLLoader(...);
Parent root = loader.load();
MyController controller = loader.getController();
controller.setHostServices(getHostServices());
//... setup and show scene and stage...
}
}
With the obvious method in the controller and the code above suitably modified.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With