Dharun Babu
Dharun Babu

Reputation: 1

How to export data from datawindow to Excel in PowerBuilder?

I want to export data from data window into excel sheet with customized column order, what is the syntax for that? For ex: In my data window I have data in the order ID/Name/DOB/City. But I want to import in order Name/ID/DOB/City

Upvotes: 0

Views: 5261

Answers (3)

Here is the solution,

    datastore lds_datastore
    lds_datastore = CREATE datastore
    lds_datastore.DataObject = "d_student_filter"
    lds_datastore.SetTransObject (SQLCA)
    lds_datastore.Retrieve()

    long ll

    ll = dw_filter.Sharedata(lds_datastore)

    IF ll > 0 THEN
       lds_datastore.Saveas("c:\Document\export.xls",Excel!,TRUE)
    END IF

Upvotes: 0

Matt Balent
Matt Balent

Reputation: 2407

There are a few ways to do this. One way is via a second datastore which is populated via the ShareData method. This second datastore would use a datawindow object set up with the same columns as in the original datawindow but in the order you wish to have them in the export. Code example for this:

int li

li = dw_primary.Sharedata(ds_excelexport)
IF li > 0 THEN
   dw_excelexport.Saveas("c:\temp\export.xls",Excel!,TRUE)
END IF

Upvotes: 1

Terry
Terry

Reputation: 6225

There’s nothing automagic that can do that. Two options that I can think of:

  1. OLE the data to Excel
  2. Create a second DataStore with the data set columns in the order you want, then copy the data across, one column at a time using dot notation, and SaveAs() the second DataStore.

In terms of runtime performance, I’d expect the second option will be faster, especially as the data set gets larger.

Good luck.

Upvotes: 0

Related Questions