如何冻结顶行和应用过滤器在Excel自动化与C# [英] How to Freeze Top Row and Apply Filter in Excel Automation with C#

查看:203
本文介绍了如何冻结顶行和应用过滤器在Excel自动化与C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自动化从C#创建一个Excel文档。我试图冻结我的工作表的顶行并应用过滤器。如果您选择查看>冻结>冻结顶部行,然后选择顶部数据>过滤器,则与Excel 2010中的相同。我不知道如何应用过滤器,但以下是我试图冻结顶部行,它只是冻结整个工作表。有没有人有解决我的问题。数据过滤器问题是我需要更多帮助的地方,如果有人有解决方案,请启发我。



非常感谢
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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆