Spire.XLS for .NET is a professional Excel .NET library that can be used to any type of .NET( C#, VB.NET, ASP.NET, .NET Core) application, both ASP.NET web sites and Windows Forms application.

Mon Jan 30, 2012 10:52 pm

Hi Guys,

I'm not only new in Spire, I'm totally new in .Net. I'm a database guy.

I managed to open an existing excel, set some very simple formatting. Now I need to set an auto-filter on all the columns. The columns are from A-S sitting on row 4 of my sheet.

This is what I got so far:

Code: Select all

           Dim workbook As New Workbook()
            workbook.LoadFromFile("c:\MyReport.xls")

            'Gets first worksheet
            Dim sheet As Worksheet = workbook.Worksheets(0)

            sheet.Range("A1").ColumnWidth = 6
            sheet.Range("B1").ColumnWidth = 25
            sheet.Range("C1").ColumnWidth = 32
            sheet.Range("D1").ColumnWidth = 12
            sheet.Range("E1").ColumnWidth = 10
            sheet.Range("F1").ColumnWidth = 7
            sheet.Range("G1").ColumnWidth = 11
            sheet.Range("H1").ColumnWidth = 8
            sheet.Range("I1").ColumnWidth = 21
            sheet.Range("J1").ColumnWidth = 11
            sheet.Range("K1").ColumnWidth = 7
            sheet.Range("L1").ColumnWidth = 7
            sheet.Range("M1").ColumnWidth = 11
            sheet.Range("N1").ColumnWidth = 5
            sheet.Range("O1").ColumnWidth = 5
            sheet.Range("P1").ColumnWidth = 20
            sheet.Range("Q1").ColumnWidth = 11
            sheet.Range("R1").ColumnWidth = 50
            sheet.Range("S1").ColumnWidth = 11


            sheet.Range("A2").Text = " Run Date: " + CStr(Now)
            sheet.Range("A2:S2").Merge()
            sheet.Range.BorderAround()
            sheet.Range.BorderInside()

            sheet.Zoom = 75


            workbook.SaveToFile("c:\MyReport2.xls")


As you can see, that's very simple and straightforward. Now how, do I set the auto-filter?


Thanks

fglasala
 
Posts: 1
Joined: Fri Jan 13, 2012 5:38 pm

Tue Jan 31, 2012 8:13 am

Hello fglasala,

Thank you for your inquiry and your patience with our support team.

You can insert this code
Code: Select all
 sheet.AutoFilters.Range = sheet.Range["A4:S4"];

before you save your workbook to create an auto-filter on the 4 row. Please have a kind try.

If you still have any questions,please don't hesitate to contact us at any time.
Have a great day.

BR
Suvi
e-iceblue support
Tina
Technical Support/Developer,
e-iceblue Support Team
User avatar

Tina.Lin
 
Posts: 152
Joined: Tue Sep 13, 2011 5:37 am

Return to Spire.XLS