cancel
Showing results for 
Search instead for 
Did you mean: 

Table to Excel - correct order

Former Member
0 Kudos

Hi,

I want to display the contents of a table in excel format.

I have followed the below link for the same.

/people/sap.user72/blog/2006/05/04/enhancing-tables-in-webdynpro-java-150-custom-built-table-utilities

The excel is generated with all contents, but the order in which the columns appear is not same as the order in which i add them to the Arraylist. It actually takes the order of the contex attributes(of the table node).

Is there a way to change the order of the columns?

Accepted Solutions (0)

Answers (2)

Answers (2)

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Shikha,

I 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

Shikha,

Please post your code where you creating ArrayList of column info objects.

VS

Former Member
0 Kudos

Hi,

Below is the code:

public java.util.ArrayList getColumns( )

{

//@@begin getColumns()

ArrayList columnsList = new ArrayList();

columnsList.add(IPublicDashboardCust.IDashboardViewElement.CRID);

columnsList.add(IPublicDashboardCust.IDashboardViewElement.TYPENAME);

columnsList.add(IPublicDashboardCust.IDashboardViewElement.STATNAME);

columnsList.add(IPublicDashboardCust.IDashboardViewElement.CRDATE);

columnsList.add(IPublicDashboardCust.IDashboardViewElement.DELIBUCKAPPL);

columnsList.add(IPublicDashboardCust.IDashboardViewElement.DELIPROJAPPL);

columnsList.add(IPublicDashboardCust.IDashboardViewElement.RECVBUCKAPPL);

columnsList.add(IPublicDashboardCust.IDashboardViewElement.RECVPROJAPPL);

return columnsList;

//@@end

}