Hi,
I need to import an XLS/XLSX spreadsheet via an agent, but the agent is running on an UNIX box, so the automation route to Excel is not an option. Am attempting to use the Apache POI libraries in Java but having no luck. Have attempted to connect the agent to the Java Debugger in Designer, but it can't be reached so have resorted to writing small files to locate where the agent crashes. Below is a simple agent I'm trying out
import java.io.FileInputStream;
import java.io.PrintWriter;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import lotus.domino.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
PrintWriter errorWrite;
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db=agentContext.getCurrentDatabase();
// (Your code goes here)
errorWrite= new PrintWriter( "d:\\tmp\\testOutput.txt", "UTF-8");
errorWrite.write("Start");
errorWrite.write("Database title is "+db.getTitle());
errorWrite.write("About to open spreadsheet");
errorWrite.close();
//InputStream inp = new FileInputStream("C:\\tmp\\TestImportSheet.xlsx");
// Workbook wb = WorkbookFactory.create(inp);
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("d:\\tmp\\TestImportSheet.xlsx"));
errorWrite=new PrintWriter( "d:\\tmp\\testOutput.txt", "UTF-8");
errorWrite.write("Spreadsheet opened");
Sheet sheet = wb.getSheetAt(0);
Row row = sheet.getRow(2);
String value=getCellValue(row,1);
// Write the output to a file
errorWrite.write(value);
errorWrite.close();
}
catch(Exception e) {
e.printStackTrace();
}
}
I've narrowed down the crash to this line
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream("d:\\tmp\\TestImportSheet.xlsx"));
But have no idea what the error is as I can't see any output. The file definitely exists.
If anyone has any alternatives or ideas, would appreciate any suggestions.
Thanks,
Cameron