cancel
Showing results for 
Search instead for 
Did you mean: 

Download Excel file through Web dynpro with no windows open?

Former Member
0 Kudos

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();
}

Accepted Solutions (1)

Accepted Solutions (1)

Qualiture
Active Contributor
0 Kudos

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

Former Member
0 Kudos

Thats what i was thinking too. Using servlet.

Answers (1)

Answers (1)

Former Member
0 Kudos

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