Exporting Webdynpro Table To CSV File
Exporting Webdynpro Table To CSV File
1)Paste the below code in a Java file named ExportTableCSV.java.Place the file in
some package(ex.com.hcl.ui.utils) in src/packages.
package com.hcl.ui.utils;
/*
*/
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.sap.tc.webdynpro.progmodel.api.IWDAttributeInfo;
import com.sap.tc.webdynpro.progmodel.api.IWDNode;
import com.sap.tc.webdynpro.progmodel.api.IWDNodeElement;
this.wdTableNode = tableNode;
}
while (attributesIterator.hasNext()) {
csv_file.append(nodeElement.getAttributeAsText(attributeInfo.getName(
)));
if (attributesIterator.hasNext()){
csv_file.append(",");
try{
bytes = csv_file.toString().getBytes("UTF-8");
err.append("" + e.getCause());
resultMap.put("data", bytes);
resultMap.put("error", err);
return resultMap;
}
2)Insert a UI Element of type FileDownload.Create a context value attribute named
fileResource of type com.sap.ide.webdynpro.uielementdefinitions.Resource.Bind the
"resource" attribute of the FileDownload UI Element to already created fileResource
value attribute.Change the "behaviour" property of FileDownload UI element to
"allowSave".
if (firstTime){
wdContext.currentContextElement(). setFileResource(resource);
where TableData node is the dataSource of the table whoose data has to be exported
to a CSV File.