I'm using an excel buffer now. And want to sort data in column "L4".
Anyone who now how I can manage it with Excel Buffer.?
I found there is Xlrange..but how do I use it??
:-k
For example to sort by column B try:
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'));
I can't help you exactly on where to put the code to sort the column in the excel buffer table, but I think at the end of the routine CreateSheet, like:
What do you mean look no good? The headers went to the bottom?
Experiment a little with the parameters about the xlColID + xlRowID and the XlWrkSht.Range('L4')...
The whole concept is to select all the data you have and sort them at L4...
Is the L1,L2,L3 headers? If yes then you could try freeze panes before sorting, so that the headings stay at the top...
Or choose 'A'+FORMAT(4) if your first 3 lines are headers...
Which report did you consult to make our own? I think Report 113 is a very nice example to use to make your own report export to excel.
I tested the following code with report 113 (Customer/Item) and it worked very well...
Function CreateSheet
.
.
.
UNTIL NEXT = 0;
XlWrkSht.Range(GetExcelReference(5) + ':' + xlColID + xlRowID).Columns.AutoFit;
XlWrkSht.Range('A2').Select;//added this line
XlApp.ActiveWindow.FreezePanes := TRUE;//added this line
XlWrkSht.Range('A' + FORMAT(2) + ':N65000').Sort(XlWrkSht.Range('D2'));//added this line
END;
IF UseInfoSheed THEN BEGIN
IF InfoExcelBuf.FIND('-') THEN BEGIN
XlWrkSht := XlWrkBk.Worksheets.Add();
.
.
.
To make it better you must make a new function in excel buffer table with name like:
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 your 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...
I suggest you study the report 113 on how it exports to excel... It is all in routines...
Hi Arhontis,
I have created a function in excel buffer like you said. The sorting is working perfectly =D> . The sorting is done in ascending order.
But i need the sorting order in Descending order. i have to create one more variable in the function with which i can tell the function to make the sorting order (xlDescending. Sorts Key1 in descending order. ) How can i achieve this please give your suggestion.
Try to use the following code properly in your function:
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'),1); // Sorting in ascending order.
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'),2); // Sorting in descending order.
Comments
http://www.mibuso.com/forum/viewtopic.p ... excel+sort
http://www.mibuso.com/forum/viewtopic.p ... excel+sort
For example to sort by column B try:
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'));
I can't help you exactly on where to put the code to sort the column in the excel buffer table, but I think at the end of the routine CreateSheet, like: It might do the trick...
Arhontis
https://forum.mibuso.com/search
If i use
XlWrkSht.Range('A' + FORMAT(1) + ':' + xlColID + xlRowID).Sort(XlWrkSht.Range('L4'));
Then the content in Excel look no good
Experiment a little with the parameters about the xlColID + xlRowID and the XlWrkSht.Range('L4')...
The whole concept is to select all the data you have and sort them at L4...
Is the L1,L2,L3 headers? If yes then you could try freeze panes before sorting, so that the headings stay at the top...
Or choose 'A'+FORMAT(4) if your first 3 lines are headers...
Anyway, practice makes perfect...
Arhontis
https://forum.mibuso.com/search
I've tried with
XlApp.Range('A3').Select; //...
XlApp.ActiveWindow.FreezePanes := TRUE;
XlWrkSht.Range('A' + FORMAT(4) + ':' + xlColID + xlRowID).Sort(XlWrkSht.Range('L4'));
but the result is still odd .. #-o
What do you mean odd?
Where do you export to excel from?
Analysis By Dimensions?
Arhontis
https://forum.mibuso.com/search
It's a new report I created to export invoices to Excel.
I want to sort Margin in percent in Column L4 via Excel Buffer
Which report did you consult to make our own? I think Report 113 is a very nice example to use to make your own report export to excel.
I tested the following code with report 113 (Customer/Item) and it worked very well... To make it better you must make a new function in excel buffer table with name like:
And in your 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...
I suggest you study the report 113 on how it exports to excel... It is all in routines...
Arhontis
https://forum.mibuso.com/search
The code works fine, how i can sort it in ascending order in excel.
Any one ?
Arhontis
https://forum.mibuso.com/search
I have created a function in excel buffer like you said. The sorting is working perfectly =D> . The sorting is done in ascending order.
But i need the sorting order in Descending order. i have to create one more variable in the function with which i can tell the function to make the sorting order (xlDescending. Sorts Key1 in descending order. ) How can i achieve this please give your suggestion.
Try to use the following code properly in your function:
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'),1); // Sorting in ascending order.
XlWorkSheet.Range('A6:AD600').Sort(XlWorkSheet.Range('B2'),2); // Sorting in descending order.
Best regards
It worked i have added one more variable in my function which will decide the Sort order. Thanks very much for your valuable replay.
SortColumn(StartColumn : Code[10];StartRow : Integer;EndColumn : Code[10];EndRow : Integer;SortColumn : Code[10];SortOrder : Integer)
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)),SortOrder)
END;