如何冻结顶行和应用过滤器在Excel自动化与C# [英] How to Freeze Top Row and Apply Filter in Excel Automation with C#
问题描述
非常感谢
KBP
workSheet.Activate();
Excel.Range firstRow =(Excel.Range)workSheet.Rows [1];
firstRow.Activate();
firstRow.Select();
firstRow.Application.ActiveWindow.FreezePanes = true;
我想出来了!
@ Jaime的解决方案冻结顶部排名工作完美。以下是我应用过滤器的解决方案:
感谢,
KBP
//修复第一行
workSheet.Activate();
workSheet.Application.ActiveWindow.SplitRow = 1;
workSheet.Application.ActiveWindow.FreezePanes = true;
//现在应用autofilter
Excel.Range firstRow =(Excel.Range)workSheet.Rows [1];
firstRow.AutoFilter(1,
Type.Missing,
Excel.XlAutoFilterOperator.xlAnd,
Type.Missing,
true);
I have automation to create an Excel document from C#. I am trying to freeze the top row of my worksheet and apply filter. This is the same as in Excel 2010 if you select View > Freeze Panes > Freeze top row, and then after selecting top row Data > Filter. I do not have any idea how to apply the filter but the following is what I tried for freezing the top row and it just froze the entire worksheet. Does anyone have a solution to my problem. The data filter problem is where I need more help so if anyone has a solution to that please enlighten me.
Many thanks, KBP
workSheet.Activate();
Excel.Range firstRow = (Excel.Range)workSheet.Rows[1];
firstRow.Activate();
firstRow.Select();
firstRow.Application.ActiveWindow.FreezePanes = true;
I figured it out!
@Jaime's solution to freezing the top row worked perfectly. And the following is my solution to applying the filter:
Thanks, KBP
// Fix first row
workSheet.Activate();
workSheet.Application.ActiveWindow.SplitRow = 1;
workSheet.Application.ActiveWindow.FreezePanes = true;
// Now apply autofilter
Excel.Range firstRow = (Excel.Range)workSheet.Rows[1];
firstRow.AutoFilter(1,
Type.Missing,
Excel.XlAutoFilterOperator.xlAnd,
Type.Missing,
true);
这篇关于如何冻结顶行和应用过滤器在Excel自动化与C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!