Exporting Webdynpro Table to CSV File.
1)Paste the below code in a Java file named [Link] the file in
some package([Link]) in src/packages.
package [Link];
/*
* Created on Feb 13, 2008
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
* @Author : Sudhir Gorantla
* @Company : HCL Technologies Ltd.,
*/
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class ExportTableCSV {
private IWDNode wdTableNode = null;
public ExportTableCSV(IWDNode tableNode) {
[Link] = tableNode;
}
public Map<String, Object> DownloadToCSV() {
byte[] bytes = null;String linktoFile = null;
StringBuffer err = new StringBuffer();
StringBuffer csv_file = new StringBuffer();
Map<String, Object> resultMap = new HashMap<String, Object>();
int noOfElements = [Link]();
List<? extends IWDAttributeInfo> attributesInfoList =
[Link]().getAttributes();
for (int i = 0;i < [Link](); i++) {
IWDNodeElement nodeElement = [Link](i);
Iterator<? extends IWDAttributeInfo> attributesIterator =
attributesInfoList .iterator();
while ([Link]()) {
IWDAttributeInfo attributeInfo = [Link]();
csv_file.append([Link]([Link](
)));
if ([Link]()){
csv_file.append(",");
try{
bytes = csv_file.toString().getBytes("UTF-8");
catch (UnsupportedEncodingException e){
[Link]("" + [Link]());
[Link]("data", bytes);
[Link]("error", err);
return resultMap;
}
2)Insert a UI Element of type [Link] a context value attribute named
fileResource of type [Link] the
"resource" attribute of the FileDownload UI Element to already created fileResource
value [Link] the "behaviour" property of FileDownload UI element to
"allowSave".
In wdDoModifyView() paste the following code
if (firstTime){
IWDResource resource =[Link]((byte[])new
ExportTableCSV(wdContext .nodeTableData
()).DownloadToCSV(). get("data"), "File",[Link]);
[Link](). setFileResource(resource);
where TableData node is the dataSource of the table whoose data has to be exported
to a CSV File.
3)Now Click on the FileDownload UI Element to download the CSV File.