on 01-20-2007 4:33 PM
Hi Friends,
I have to download a table content to an excel sheet that is dynamically generated on the basis of users' selection. I gone through examples 23 & 39 given in samples section for web dynpro but that works when I know the exact file to be downloaded from WAS but in my case, I have to create a file (as it seems to me) having the dynamically generated content & then I can download it to the client system. Here comes the problem, jxl package is not getting recognised by Web Dynpro (atleast not with the version I am using) and I am not getting any Web Dynpro API that can work in my case.
Please help me out as this problem is obstructing my way in creating a critical development component.
Thanks & Regards,
Aditya P. Srivastava
Hi,
You can get the data to be downloaded from the context node attached to the table and then either use jxl method or downloading using binary cache method (the one which is given in the SDN) to convert the data to excel format. It would be better if you use jxl method, as you can use a lot of formatting.
Regards,
Mahesh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mahesh,
I am using SAP Netweaver 2.0.16 and I tried jxl.write.WritableWorkbook to do the desirable but Web Dynpro is not recognising the above said package. So, I
have to abandon the approach.
Now I am trying the one having the following steps:
(1) In the eventhandler for the link to "Download to Excel" (LinkTOAction UI),
I am trying to implement the following code:
/This method, after setting the file name & MIME type for the context attribute FileResource (that corresponds to link "Download to Excel"), fetches the path for the node that holds the data I have to download, and then sets that data to the above said path for the context attribute FileResource after converting it into byte[] (as FileResource is of type binary)/
public void onActionDownloadExcel(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
{
//@@begin onActionDownloadExcel(ServerEvent)
IWDAttributeInfo attInfo = wdContext.getNodeInfo().getAttribute(IPrivateZuw_ReposView.IContextElement.CTX__VA__FILE_RESOURCE);
// attInfo.getModifiableSimpleType();
IWDModifiableBinaryType binary = (IWDModifiableBinaryType)attInfo.getModifiableSimpleType();
binary.setFileName(fileName);
binary.setMimeType(WDWebResourceType.XLS);
IPrivateZuw_ReposView.ICtx_vn_showallNode showData = wdContext.nodeCtx_vn_showall();
IPrivateZuw_ReposView.ICtx_vn_showallElement showEle = null;
try
{
String resourcePath = WDURLGenerator.getResourcePath(wdContext.nodeCtx_vn_showall().toString());
wdComponentAPI.getMessageManager().reportSuccess(resourcePath);
ByteArrayOutputStream out = new ByteArrayOutputStream();
out = this.getByteArrayFroResourcePath(resourcePath);
if(out != null)
{
wdContext.currentContextElement().setCtx_va_FileResource(out.toByteArray());
}
else
{
wdComponentAPI.getMessageManager().reportWarning("ByteArrayOutputStream returned as NULL");
}
}
catch(Exception e)
{
wdComponentAPI.getMessageManager().reportWarning("Exception");
}
//@@end
}
(2) And for the function getByteArrayFroResourcePath(String), I've written:
/*This returns ByteArrayOutputStream for the given resourcePath (It is, in my case, for the context node that holds the data I have to download) */
public java.io.ByteArrayOutputStream getByteArrayFroResourcePath( java.lang.String resourcePath )
{
//@@begin getByteArrayFroResourcePath()
try
{
FileInputStream in = new FileInputStream(new File(resourcePath));
ByteArrayOutputStream out = new ByteArrayOutputStream();
int length;
byte[] part = new byte[10*1024];
while((length = in.read(part)) != -1 )
{
out.write(part, 0 , length);
}
in.close();
return out;
}
catch(FileNotFoundException e)
{
wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(),true);
}
catch(IOException e)
{
wdComponentAPI.getMessageManager().reportException(e.getLocalizedMessage(),true);
}
return null;
//@@end
}
But this approach, though seems to me quite right, has problem. As the context node that holds data I need to download in Excel is not a Deployable object, so the system doesn't returns me the resource path; instead it is giving me
".\temp\webdynpro\web\Context_Node(system cannot find the file specified)".
ByteArrayOutputStream returned as NULL.
See into the issue and help me in getting the right solution.
Thanks & Regards,
Aditya P. Srivastava
Sorry,
It is returning me the resourcePath but not getting the File for the corresponding path (check the getByteArrayFroResourcePath(String) ) as expected.
So, I am thinking to create a file having the contents of the context node whose data I need to download & then using that file object to get FileInputStream as in getByteArrayFroResorcePath(String) method.
What do you think, am I going in right direction?
Thanks,
Aditya.
hi,
for downloading to a file u need to use a filedownload UI Element and not the link to action UI Element
In this method u have to convert the node data into binary and store the data into a context attribute. Then u have to bind the context attribute which stores the binary to the file download <b>UI Element( FileDownload)</b>
You can write the code to read the data from the node and convert it into the binary in the doModifyView method.
Hi,
My problem has been solved using the excellant blog " Exporting table data to MS-Excel Sheet " (enhanced Web Dynpro Binary Cache) written by Mr. Subramanian Venkateswaran. This can be accessed using https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/4210. [original link is broken] [original link is broken] [original link is broken] [original link is broken]
My approach was wrong as I was trying to use Java APIs to fetch the data and fill up the excel sheet while it required a precise route to follow provided in Web Dynpro APIs.
Thanks to all who have shown interest in solving my problem & I appreciate their efforts.
Regards,
Aditya P. Srivastava
User | Count |
---|---|
81 | |
25 | |
12 | |
9 | |
7 | |
6 | |
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.