cancel
Showing results for 
Search instead for 
Did you mean: 

Issue of export to excel

Former Member
0 Kudos

Hi All

I got a requirement where i have to export the table to the excel 2003 i had done that. but not getting order of the fields as per the table, using the the following code

<i>for (int i = 0; i < dataNode.size(); ++i) {

IWDNodeElement dataNodeElement = dataNode.getElementAt(i);

x.append("<").append(entryName).append(">\n");

for (Iterator iter = columnInfos.keySet().iterator(); iter.hasNext();) {

attributeName = (String) iter.next();

headerName = (String) columnInfos.get(attributeName);

x

.append("<")

.append(headerName)

.append(">")

.append(dataNodeElement.getAttributeValue(attributeName))

.append("</")

.append(headerName)

.append(">\n");

}</i>

can any one give me a clue how to get the same order as in table or as iam passing to the excel from webdynpro code..

Thanks & Regards

Ashwin

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hey,

This is the simple instead of mar parameter u can chage the LinkedHashMap.

Then you can get the same order and u need to give the order when u give your value attributes at your method in TableApp.

wdthis.wdGetAPPInterface.ExpoertExcel(wdcontext.node<name>(),getValues());

the Imple of this method

private LinkedHashMap getValues()

{

// you can give ur value attrbute what ever order do u need.

return LikedhshMap;

}

Any probs post ur issues.

Thanks,

Lohi.

Answers (3)

Answers (3)

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Ashwin,

you refer to my Excel Export tutorial on SDN: <a href="https://wiki.sdn.sap.com/wiki/x/0mQ">Exporting Table Data Using On-Demand Streams - SAP NetWeaver 7.0</a>:

use <b>LinkedHashMap</b> instead of <i>HashMap</i>:

  private Map getProductColumnInfos() {
    Map columnInfosMap = new LinkedHashMap();
    columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.QUANTITY, "Quantity");
    columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.ARTICLE, "Article");
    columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.COLOR, "Color");
    columnInfosMap.put(IPrivateTableCompBasketView.IProductsElement.PRICE, "Price in EURO");
    columnInfosMap.put(
      IPrivateTableCompBasketView.IProductsElement.TOTAL__PER__ARTICLE,
      "Total Per Article In Euro");
    return columnInfosMap;
  }

This keeps the order of key-displaytext-pairs passed by the client (table component) to the service (excel export component) stable.

Regards, Bertram

Former Member
0 Kudos

Hi,

I was facing the same problem.

The reason is that , the order of the headers in Excel is, in the ascending order of the value attributes' name.

Eg:...if your value attribute names are: ctx_va_name, ctx_va_salary and ctx_va_age, then by default, in excel, the headers will be in the following order:

ctx_va_age, ctx_va_name, ctx_va_salary .

So, if you want the name to appear first, then the salary and then age,

then rename the vaule attributes as:

Actx_va_name, Bctx_va_salary, Cctx_va_age.

This has solved the problem, so i am sure it will solve yours too

former_member197348
Active Contributor
0 Kudos

Hi Ashwin,

by default you will get order of the feilds same as the order of attributes of the dataNode but not as in table.if you want the order same as table, you have to check and pass fields manually.

regards,

Siva

Former Member
0 Kudos

Hi Siva

My problem is that i am not getting the result in excel as in order of data node also. can you suggest where the mistake is done.

Regards

Ashwin

Former Member
0 Kudos

Hi Ashwin,

Probabaly this <a href="/people/subramanian.venkateswaran2/blog/2006/08/16/exporting-table-data-to-ms-excel-sheetenhanced-web-dynpro-binary-cache Webdynpro Table to Excel</a> should help you in resolving the problem.

- Nagarajan.