1 package org.simantics.spreadsheet.fileimport;
3 import java.nio.file.Path;
4 import java.util.HashMap;
6 import java.util.Optional;
8 import org.simantics.Simantics;
9 import org.simantics.db.Resource;
10 import org.simantics.fileimport.SimanticsResourceFileImport;
11 import org.simantics.spreadsheet.graph.ExcelImport;
13 public class ExcelFileImport extends SimanticsResourceFileImport {
15 private static final Map<String, String> ALLOWED_EXTENSIONS = new HashMap<>(2);
18 ALLOWED_EXTENSIONS.put("*.xls", "Excel file *.xls");
19 ALLOWED_EXTENSIONS.put("*.xlsx", "Excel file *.xlsx");
23 public Optional<Resource> perform(Resource possibleSelection, Path file) throws Exception {
24 if(possibleSelection != null) {
25 //Make sure the selection is of valid type here
26 return Optional.ofNullable(ExcelImport.importBookR(possibleSelection, file.toFile()));
28 throw new NullPointerException("No selection provided - Cannot import book");
33 public Map<String, String> allowedExtensionsWithFilters() {
34 return ALLOWED_EXTENSIONS;
38 public Resource defaultParentResource() {