XlCall.xlcFilter

瀏覽次數:46 次
跳到第一則未讀訊息

Chad Kelley

未讀,
2023年3月15日 晚上8:30:542023/3/15
收件者:Excel-DNA
Hey everyone,
I'm Trying to speed up an Autofilter Function i currently have in a large spreadsheet.  I currently have the Following:

Sheet.Range["A:A"].AutoFilter(Field: 1, Criteria1: ">=" + StartValue, Operator: XlAutoFilterOperator.xlFilterValues, Criteria2: "<=" + EndValue);

Where StartValue and EndValue are numbers from the "A" Column.


Here is what i am Trying:

  [ExcelCommand(Name = "MyTestCommand", ShortCut = "^Q")]
        public void ToggleSheetFilterAdvanced(Worksheet Sheet, double StartValue, double EndValue)
        {

            // Get the Excel application object
            Application excelApp = (Application)ExcelDnaUtil.Application;

            // Get the range to apply the filter to
            Range range = excelApp.Selection;

            // Define the filter criteria
            object[] filterCriteria = new object[] { "1" };

            // Call the XlCall.xlcFilter function to apply the filter
            XlCall.Excel(XlCall.xlcFilter, range, filterCriteria);

            }
        }


Initially i'm thinking the C API calls might be much faster but I cannot find any reason why this is throwing an exception.

anyone have any ideas?

Capture.PNG

Govert van Drimmelen

未讀,
2023年3月16日 清晨5:30:402023/3/16
收件者:Excel-DNA
The C API calls would need to take an ExcelReference object, instead of the COM Range object.
You can try to start with a C API call to get the selection (as an ExcelReference object)

   var selection = XlCall.Excel(XlCall.xlfSelection);

then it might work better.

I'm not sure whether the C API is faster or as full featured as the COM approach for this kind of sheet manipulation, but it's worth checking.

-Govert
回覆所有人
回覆作者
轉寄
0 則新訊息