Export to Excel With Sort Function

Prajeesh_NairPrajeesh_Nair Member Posts: 70
Hi all,
I have Exported data to excel and sorted the data in excel from nav itself. The data was sorted ascending, But i want the data in descending order. Any idea? Please need help.
Created a function in Excel Buffer table for sorting

Function SortColumn(StartColumn:code;StartRow:Integer;EndColumn:Code;EndRow:Integer;SortColumn:Code);
BEGIN
XlWrkSht.Range(StartColumn+FORMAT(StartRow-1)).Select;
XlApp.ActiveWindow.FreezePanes := TRUE;
XlWrkSht.Range(StartColumn+FORMAT(StartRow) + ':'+EndColumn+FORMAT(EndRow-1)).Sort(XlWrkSht.Range(SortColumn+FORMAT(StartRow)));
END;


And in report, after calling the CreateSheet and before the GiveUserControl you should execute something like:
SortColumn('A',2,'Z',65000,'B');
to freeze panes and sort the column B from row 2 and on...


Refference: viewtopic.php?f=23&t=18606&start=0

Comments

  • Prajeesh_NairPrajeesh_Nair Member Posts: 70
    Any Help or suggestion ? :-k [-o<
  • David_CoxDavid_Cox Member Posts: 509
    I have Exported data to excel and sorted the data in excel from nav itself.

    As you are loading the buffer from a recordset sorted in Nav, load the buffer from last to first records, use SETCURRENTKEY, FIND('+'), REPEAT UNTIL NEXT(-1) = 0;
    WITH Customer DO BEGIN
      RESET;
      SETCURRENTKEY(Name,Address,City);
      IF ISEMPTY THEN
        ERROR('No Records');
      FIND('+');
      REPEAT
        //Add to Excel Buffer
    
      UNTIL NEXT(-1) = 0;
    END;
    

    HTH

    David
    Analyst Developer with over 17 years Navision, Contract Status - Busy
    Mobile: +44(0)7854 842801
    Email: david.cox@adeptris.com
    Twitter: https://twitter.com/Adeptris
    Website: http://www.adeptris.com
Sign In or Register to comment.