on 03-19-2008 12:05 PM
Hi friends,
I am using Binary Cache method for Export to Excel. I am using a separate method for generating the column headers. My question is : Is there a way to put the attribute names from the node directly instead of the one I am currently using.
public java.util.Map getOrderColumnInfos( )
{
//@@begin getOrderColumnInfos()
// Returns Header for the Table to be passed on to method toExcel()
Map columnInfosMap = new LinkedHashMap();
columnInfosMap.put(
IPrivateABC.ISearchResultstoExcelElement.ATTRIBUTE1,
"Name");
columnInfosMap.put(
IPrivateABCSearchResultstoExcelElement.ATTRIBUTE2,
"Reference");
columnInfosMap.put(
IPrivateABC.ISearchResultstoExcelElement.ATTRIBUTE3,
"Created By");
columnInfosMap.put(
IPrivateABC.ISearchResultstoExcelElement.ATTRIBUTE4,
"Input Date");
return columnInfosMap;
//@@end
}
Instead of putting the header texts, I want the attribute names to be displayed on the Excel file headers. Please let me know if this is possible.
Hi Avik,
Use the below code to get dynamically the attribute.
Iterator itr = wdContext.node<YourNode>().getNodeInfo().iterateAttributes();
int count=0;
while(itr.hasNext())
{
Object attr = itr.next();
String attrname1 = null;
String attrname = attr.toString();
StringTokenizer str = new StringTokenizer(attrname, " .");
while(str.hasMoreTokens()){
attrname1 = str.nextToken();
}
attrname1 = attrname1.replace(')',' ').trim();
}
With Regards,
Laksh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello AVIK SANYAL
Please, Could you share your solution with us ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Rasim,
The idea was to create the Column headers dynamically. This means basically at runtime the Application would recognize what is there in the screen and use it for Column headers. This involved reading the from the View Table->The Table Column Element-> The header and saving those values in a Context. This context is then mapped to the Excel Custom Controller and then all we have to do is read from the context, Convert to XML (The usual way that is.... )
And ...There it is....!!!!
Bit hectic to code this than the obvious Map and stuff. But it saves a lot of headache for future additions/deletions of columns to the table.
Sample Code :
public void populateExcelColumnsFromView( java.lang.String tableName, com.sap.tc.webdynpro.progmodel.api.IWDView view )
{
//@@begin populateExcelColumnsFromView()
//Created By : AVIK SANYAL Date : 28 March 2008
//This method will fetch the header names from the Table in the View and set the
// Attributes in nodeExcelTableColumns(). These nodes are mapped to
//Excel Custom Controller and hence used to set the Column headers for the Excel File.
IWDTable searchTable = (IWDTable) view.getElement(tableName);
wdContext.nodeExcelTableColumns().invalidate();
String tableDataSource = searchTable.bindingOfDataSource();
wdContext.currentContextElement().setDataSource(tableDataSource);
for (int i = 0; i < searchTable.numberOfGroupedColumns(); i++) {
// Read the Column
IWDTableColumn col =
(IWDTableColumn) searchTable.getGroupedColumn(i);
IWDTableCellEditor TCE = col.getTableCellEditor();
IWDCaption header = col.getHeader();
// This will check if the column is visible in the View only then it will
// go for further processing.
if (WDVisibility.VISIBLE.equals(col.getVisible())) {
IExcelTableColumnsElement columnElement =
wdContext
.nodeExcelTableColumns()
.createExcelTableColumnsElement();
// If the header is not null then set the header as in the View
if (header != null) {
columnElement.setHeading(header.getText());
} else {
}
// Add the column name to the nodeExcelTableColumns()
//This checks the type of column in the View and then take the value.
if (TCE != null) {
if (TCE instanceof IWDTextView) {
IWDTextView element = (IWDTextView) TCE;
columnElement.setBinding(element.bindingOfText());
wdContext.nodeExcelTableColumns().addElement(
columnElement);
}
}
}
}
//@@end
}
Thank You. I found a solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks friends, Your inputs were very helpful.
Regards
Avik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I want the attribute names to be displayed on the Excel file headers. Please let me know if this is possible
To get the attribute name use as follows
wdContext.node<YourNode>().getNodeInfo().getAttribute("Your Attribute").getName()
wdContext.getNodeInfo().getAttribute("Your Attribute").getName()
Regards
Ayyapparaj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
73 | |
26 | |
10 | |
9 | |
7 | |
6 | |
4 | |
4 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.