Solved

Dex Library to export table to excel

  • 5 July 2024
  • 1 reply
  • 7 views

Dear all

 

I was using a DataLink library to export to excel. However, I have installed the latest version and this library is not there. I need to use DEX Library.

I created a table and a data mapping to export it to excel.

Below is the code. How could I implement it using DEX?

Thanks for helping.

----------------------------------------------------------------------

The code was this

 


dl::DataTables += 'Result2';
DataMap(dl::dt,dl::idn,dl::cn,dl::dn) := data {
    ( 'Result2', 'Scenarios', 1, 1 ) : "Scenarios",
    ( 'Result2', 'Port', 2, 2 ) : "Port",
    ( 'Result2', 'Destination', 3, 3 ) : "Destination",   
    ( 'Result2', 'Bidder', 4, 4 ) : "Bidder",       ! from fourRows.csv, read in a data pDem from a 3rd csv data column named "demand". This is a data column
    ( 'Result2', 'TransportMode', 5, 5 ) : "TransportMode",
    ( 'Result2', 'Days', 6, 6 ) : "Days",
    ( 'Result2', 'ScenarioAllocation', 7, 0 ) : "ScenarioAllocation",
    ( 'Result2', 'ForecastAllocation', 8, 0 ) : "ForecastAllocation",
    ( 'Result2', 'CostAllocation', 9, 0 ) : "CostAllocation",
    ( 'Result2', 'Allocation_Port_Lat', 10, 0 ) : "Allocation_Port_Lat",
    ( 'Result2', 'Allocation_Port_Long', 11, 0 ) : "Allocation_Port_Long",
    ( 'Result2', 'Allocation_Dest_Lat', 12, 0 ) : "Allocation_Dest_Lat",
    ( 'Result2', 'Allocation_Dest_Long', 13, 0 ) : "Allocation_Dest_Long",
    ( 'Result2', 'Total_CostAllocation', 14, 0 ) : "Total_CostAllocation",
    ( 'Result2', 'LeadTimeAllocation', 15, 0 ) : "LeadTimeAllocation",
    ( 'Result2', 'WeightedLeadTimeperLane', 16, 0 ) : "WeightedLeadTimeperLane",
    ( 'Result2', 'NormalizedUnitCost', 17, 0 ) : "NormalizedUnitCost"
};

dl::RemoveDataSourceMapping("Result2");
dl::AddDataSourceMapping(
    MapName        :  "Result2",
    DataMap        :  DataMap,
    ColDepend      :  dl::DependEmpty,
    TableAttribute :  dl::TableAttributesEmpty,
    ColAttribute   :  dl::ColAttributeEmpty);
sp_readAttribute :=  { 'DataProvider': xlsprovider::DataLink, 'ContainsHeaders' : "yes" };

dl::DataWrite(
    DataSource     :  "Result2.xlsx",
    MapName        :  "Result2",
    WriteAttributes :  sp_readAttribute);

icon

Best answer by gabiservidone 8 July 2024, 19:45

View original

1 reply

Userlevel 5
Badge +6

Hi @wilbelui, to use DEX, you will need to transform DataMap to an XML file with your mapping, see more here: https://how-to.aimms.com/Articles/534/534-dealing-with-the-different-data-types.html#excel-mapping-exporting-data. Once this is ready, you can add the mapping using dex::AddMapping and write to Excel using dex::WriteToFile.

 

Feel free to use this project (https://how-to.aimms.com/Articles/383/383-contract-allocation.html) as an example.

Reply


Didn't find what you were looking for? Try searching on our documentation pages:

AIMMS Developer & PRO | AIMMS How-To | AIMMS SC Navigator