Let us try to create convert Drools decision table (excel spread sheet) to a (.DRL) file in Drools.
The SpreadsheetCompiler class is used to convert the input XLS and CSV file to a (.DRL) expedient. The required package is “org.drools.decisiontable.SpreadsheetCompiler”.You need to use the compile () method of this class to do the conversion. Following example shows the processs.
Example program:-
importar java.io.FileInputStream;
importació java.io.FileNotFoundException;
importar java.io.InputStream;
importació org.drools.decisiontable.InputType;
importació org.drools.decisiontable.SpreadsheetCompiler;
public class ExcelToDrlDemo {
public static void principal(String args[]) {
// create an input stream
InputStream is = nul;
tractar de {
// assign the excel to the input stream
// mention the local directory path where your excel is kept
// you can take any decision table (excel sheet) for testing
= New FileInputStream és(“D:/Workspace/TestProj/src/ExamplePolicyPricing.xls”);
} agafar (FileNotFoundException i) {
e.printStackTrace();
}
// create compiler class instance
SpreadsheetCompiler sc = new SpreadsheetCompiler();
// compile the excel to generate the (.DRL) expedient
String drl=sc.compile(és, InputType.XLS);
// check the generated (.DRL) expedient
System.out.println(“Generate DRL file is –: “);
System.out.println(DRL);
}
}