Hi!
Is there a way to open an existing Excel file (or Word file) with Groovy?
Thanks, bye!
Hello,
there is an Apache POI Java API to work with Microsoft Office document. The best would be to build new Bonita BPM connectors using this (or similar) library.
I found also this website where somebody made a Groovy builder out of it.
Hope this helps
I wrote this script :
import java.io.*;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCell;
public class provaExcel{
public static void main(Stringargs){
try{
String filename=“C:\Users\Chiara\Documents\test.ods”;
HSSFWorkbook workbook=new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("test");
HSSFRow rowhead= sheet.createRow((short)0);
rowhead.createCell(0).setCellValue("Name");
HSSFRow row= sheet.createRow((short)1);
row.createCell(0).setCellValue("Lastname");
FileOutputStream fileOut = new FileOutputStream(filename);
workbook.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
} catch ( Exception ex ) {
System.out.println(ex);
}
}
}
How can I move the process variables to the excel file using my script ?
Thanks!
This would depend on where you write and use your script and which variables are available. You will find on top of your script editor a drop-down list named Process variables, that gives you access to them. Choose a variable that you want to use and it will be placed in your code (make sure to put it where you need it).
If I look quickly at your code, it seems you might transform this:
rowhead.createCell(0).setCellValue(“Name”)
into somethins like:
rowhead.createCell(0).setCellValue(yourProcessVariable)
Hope this helps
First of all thank you for the reply.
I had already tried to do so , but it gives me error .
I have process variables (name , lastname , city etc ) and a form where the user insert these fields .
I would then insert this data into an excel .
In cell A1 I have “Name” and in cell B2 I have “Lastname”.
In cell B1 and B2 I would like to see the data entered by the user.
Where do you define your script - on task finish or elsewhere? Could you share the error with us (copy/paste from the log), please?
My script is on task.
name is a process variable.
With (for example):
rowhead.createCell(0).setCellValue(name);
I have this error :
“script groovy “excel” non compatibile con errore: Groovy:Apparent variable ‘nome’ was found in a static scope but doesn’t refer to a local variable, stic field or class.”
It seems to be a Groovy error, not sure if I can help you much here. But I don’t think you should define a class, but rather just execute the code (starting from try).