3 Replies Latest reply: Sep 12, 2011 4:44 PM by Faraz Siddiqui RSS

Download Excel file through Web dynpro with no windows open?

Faraz Siddiqui
Currently Being Moderated

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.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++) {
     String content = lines.getString("LINES") + "\n";


  • Re: Download Excel file through Web dynpro with no windows open?
    Jay K
    Currently Being Moderated



    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;
              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);
                   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);
                        label = new Label(1,i+1,strBatchID,blueFormat);
                   workbook.setColourRGB(Colour.LIME, 0xff, 0, 0);
                   FileInputStream excelCSVFile = new FileInputStream(f);
                   IWDCachedWebResource cachedWebResource = null;
                   if (excelCSVFile!= null)
                        cachedWebResource = WDWebResource.getWebResource(excelCSVFile, WDWebResourceType.getWebResourceType("xls","application/ms-excel"));
              cachedExcelResource = cachedWebResource;
         catch (Exception ex)
              wdComponentAPI.getMessageManager().reportException("Error in Excel Download"+ex.getMessage(),false);




  • Re: Download Excel file through Web dynpro with no windows open?
    R. van het Hof
    Currently Being Moderated

    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)