for my current project for university I am looking for help.
I have a production programm which tells me how much of a current product I need to produce in a given timeframe (1 Year). Based on this production programm I calculated production demands (machinery and manpower) in Excel.
Furthermore I calculated, that the need for a certain type of machine the amount needed is three to cover up demand. This number is now listed in Cell G33 (for workstation 1) in my excel-productionpProgramm. Now I need to get this data into my UML design language by using java rules.
What my UML code is supposed to do is to calculate optimal material flow between raw material source, workstations and semi-finished product sink and create their geometrys which I import via stp-files. However this is not what I am struggling with.
I cannot workout how to get the data of a single excel cell into my java code when using an .xlsm excelsheet (XSSF). Previously this code was used with Excel 2007 (or older). I tried to convert the code from HSSF to HSSX which mostly worked but there is still one error I cannot fix.
Here is what I coded so far (where I tried to import data of seven workstations that are needed for production). I am using a program which is only used within the university project. It is based on an eclipse framework (if this is important):
import de.iils.dc43.transformationengine.javarule.JavaRule;
import de.iils.dc43.transformationengine.popup.actions.TransformationRunner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
public class ReadExcel0 extends JavaRule {
//Variables
public static String numberwsone = null;
public static String numberwstwo = null;
public static String numberwsthree = null;
public static String numberwsfour= null;
public static String numberwsfive = null;
public static String numberwssix = null;
public static String numberwsseven = null;
@Override
public void execute(TransformationRunner trafoRunner) throws FileNotFoundException, IOException {
//get object which represents workspace
IWorkspace workspace = ResourcesPlugin.getWorkspace();
//get location of workspace
IPath workspaceDirectory = workspace.getRoot().getLocation();
String strWorkspace = workspaceDirectory.toString();
//location of Excel file
String fileName = strWorkspace+"/Projectname/Data/Data.xlsm";
POIFSFileSystem fileSystem = new POIFSFileSystem(new FileInputStream(fileName));
@SuppressWarnings("resource")
XSSFWorkbook workbook = new XSSFWorkbook(fileSystem);
XSSFSheet sheetBedarfsrechnung = workbook.getSheetAt(0); // Get Excel Sheet
XSSFCell excelArbeitsplatzeins = sheetBedarfsrechnung.getRow(34).getCell(8); //Excelcell
numberwsone = excelArbeitsplatzeins.toString();
System.out.println(excelArbeitsplatzeins);
XSSFCell excelArbeitsplatzzwei = sheetBedarfsrechnung.getRow(35).getCell(8); //Excelcell
numberwstwo= excelArbeitsplatzzwei.toString();
System.out.println(excelArbeitsplatzzwei);
XSSFCell excelArbeitsplatzdrei = sheetBedarfsrechnung.getRow(36).getCell(8); //Excelcell
numberwsthree = excelArbeitsplatzdrei.toString();
System.out.println(excelArbeitsplatzdrei);
XSSFCell excelArbeitsplatzvier = sheetBedarfsrechnung.getRow(37).getCell(8); //Excelcell
numberwsfour = excelArbeitsplatzvier.toString();
System.out.println(excelArbeitsplatzvier);
XSSFCell excelArbeitsplatzfuenf = sheetBedarfsrechnung.getRow(38).getCell(8); //Excelcell
numberwsfive = excelArbeitsplatzfuenf.toString();
System.out.println(excelArbeitsplatzfuenf);
XSSFCell excelArbeitsplatzsechs = sheetBedarfsrechnung.getRow(39).getCell(8); //Excelcell
numberwssix = excelArbeitsplatzsechs.toString();
System.out.println(excelArbeitsplatzsechs);
XSSFCell excelArbeitsplatzsieben = sheetBedarfsrechnung.getRow(40).getCell(8); //Excelcell
numberwsseven = excelArbeitsplatzsieben.toString();
System.out.println(excelArbeitsplatzsieben);
}
}
For:
XSSFWorkbook workbook = new XSSFWorkbook(fileSystem);
which seems to be the only problem I get the following solutions from Java:
- I either have to remove the argument to match XSSFWorkbook()
or
- I should change the type of fileSystem to "OCPPackage". Both of these Solutions do not seem to work.
Can you guys help me with my problem? I appreciate any kind of collaboration.
Have a nice day! Chris