on 09-02-2011 9:46 PM
Can we have a web dynpro application that just returns an Excel file in the response with no open windows? Similar to a java servlet that is used to download a Excel file?
This basically means that I cannot use wdComponentAPI.getWindowManager().createNonModalExternalWindow()
Java Servlet Code
HttpSession session = request.getSession(); // get a handle on the session id
response.setContentType("application/download");
response.setHeader("Content-Disposition", "filename=RTIS_Report.xls");
PrintWriter out = null;
out = response.getWriter();
String report = request.getParameter("REPORT");
JCO.Table lines = download(request, session, report);
for (int i = 0; i < lines.getNumRows(); i++) {
lines.setRow(i);
String content = lines.getString("LINES") + "\n";
out.write(content);
out.flush();
}
out.flush();
out.close();
}
Hi Faraz,
then why not simply use a servlet?
Web Dynpro is SAP's MVC framework, and as such requires at least one View element, so I don't think your requirement is possible (i.e. to write directly to the output stream)
Best,
Robin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I think you can use IWD Cached Web Resource to achieve this..
See the below code FYI..
public void downloadToExcel( )
{
String fileName = "Customer" + ".xls";
IWDCachedWebResource cachedExcelResource = null;
try
{
File f = new File("Customer.xls");
WritableWorkbook workbook = Workbook.createWorkbook(f);
WritableFont black = new WritableFont(WritableFont.createFont("Trebuchet MS"),WritableFont.DEFAULT_POINT_SIZE,WritableFont.BOLD,false,UnderlineStyle.SINGLE,Colour.BLACK);
WritableCellFormat blackFormat = new WritableCellFormat(black);
WritableFont blue = new WritableFont(WritableFont.createFont("Trebuchet MS"),WritableFont.DEFAULT_POINT_SIZE,WritableFont.NO_BOLD,false,UnderlineStyle.NO_UNDERLINE,Colour.BLUE);
WritableCellFormat blueFormat = new WritableCellFormat(blue);
WritableSheet sheet = workbook.createSheet("Customer", 0);
Label label;
String[] header={"Corporate Code","Batch ID"};
for (int i=0;i<2;i++)
{
label = new Label(i,0,header<i>.toString(),blackFormat);
sheet.addCell(label);
}
WritableCellFormat integerFormat = new WritableCellFormat(NumberFormats.INTEGER);
jxl.write.Number number;
// Reading the contents
for(int i=0;i<wdContext.nodeVn_DownloadToExcel().size();i++)
{
String strCorpName = wdContext.currentContextElement().getVa_CorpCode();
String strBatchID = wdContext.nodeVn_DownloadToExcel().getVn_DownloadToExcelElementAt(i).getVa_BatchID();
label = new Label(0,i+1,strCorpName,blueFormat);
sheet.addCell(label);
label = new Label(1,i+1,strBatchID,blueFormat);
sheet.addCell(label);
}
workbook.setColourRGB(Colour.LIME, 0xff, 0, 0);
workbook.write();
FileInputStream excelCSVFile = new FileInputStream(f);
IWDCachedWebResource cachedWebResource = null;
if (excelCSVFile!= null)
{
cachedWebResource = WDWebResource.getWebResource(excelCSVFile, WDWebResourceType.getWebResourceType("xls","application/ms-excel"));
cachedWebResource.setResourceName(fileName);
}
cachedExcelResource = cachedWebResource;
wdContext.currentContextElement().setVa_DownloadToExcel(cachedExcelResource.getURL());
workbook.close();
}
catch (Exception ex)
{
wdComponentAPI.getMessageManager().reportException("Error in Excel Download"+ex.getMessage(),false);
}
Regards,
Vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
81 | |
24 | |
11 | |
9 | |
7 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.