1
votes

I would likte to create an excel file in SSJS. It will be the same in LotusScript (You can find the code sample at the bottom of this question.) I started this but i could not finish it yet :(

var response = facesContext.getExternalContext().getResponse(); 
var DataWriter = facesContext.getResponseWriter(); 
response.setContentType("application/vnd.ms-excel");
response.setHeader("Cache-Control", "no-cache");
response.setHeader("Content-Disposition","attachment; filename='ExportedExcel1.xls'");

DataWriter.write("Denenee");
DataWriter.endDocument();



xlsFile =Environ("Temp") & "\firstExcel.xls"
Call object.ExtractFile( xlsFile )
Set excelappl = Nothing
Set excelappl = CreateObject("Excel.Application")
ver$ = excelappl.Version    
Select Case Left(ver$,2)
Case "9.":
Set excelappl = CreateObject( "Excel.Application.9" )       
Case "10":
Set excelappl = CreateObject( "Excel.Application.10" )      
Case "11":
Set excelappl = CreateObject( "Excel.Application.11" )      
Case "12":
Set excelappl = CreateObject( "Excel.Application.12" )  
Case "13":
Set excelappl = CreateObject( "Excel.Application.13" )  
End Select
excelappl.visible = False
Set wb = excelappl.Workbooks.Open(xlsFile)
If wb Is Nothing Then
Error 10003, "Hata: Dosya bulunamadı."
End If
Set excelSheet = excelappl.workbooks(1).Worksheets(1)
Call excelsheet.Activate
row = 1
2
Besides not being a good idea: any admin would ensure no desktop app like excel is installed on a Domino server. Use Poi4xpages as Knut suggested and avoid writing into the file systemstwissel

2 Answers

7
votes

XPages' SSJS runs on server. It's not a good idea to use OLE objects like LotusScript's CreateObject("Excel.Application") on server.

Use POI 4 XPages instead. It allows you to create Excel files in an approved way.

1
votes

Your LS code suggests (extractObject) that your Excel file is actually an attachment. In this case your approach would be different.

Write a small Java class. There's a method in NotesEmbeddedObject to get the object as input stream. Use the Apache Commons to pump that input stream into the XPages output stream. Makes your life easier.

Keep in mind: to use the OutputStream you can't use the Writer. There can be only one of the two open