VB.NET excel 按列排序
今天在VB.NET的项目中需要导出数据到EXCEL,并且还要对VB.NET EXCEL进行列的排序操作(sort),总结了下,把关键代码帖出来,备用下
Dim Xls As Excel.Application = New Excel.Application '定义excel应用程序 Dim Xlsbook As Excel.Workbook '定义工作簿 Dim Xlssheet As Excel.Worksheet '定义工作表 Xlsbook = Xls.Application.Workbooks.Open("c:\sort.xls") Xlssheet = Xlsbook.Sheets(1) CType(Xlssheet.Columns(1),Excel.Range).ColumnWidth = 30 CType(Xlssheet.Columns(2),Excel.Range).ColumnWidth = 60 CType(Xlssheet.Columns(3),Excel.Range).ColumnWidth = 10 Xlssheet.UsedRange.Sort(Key1:=Xlssheet.Range(Xlssheet.Cells(1,3).Address),_ Order1:=Excel.XlSortOrder.xlAscending,_ Header:=Excel.XlYesNoGuess.xlNo,_ Orientation:=Excel.XlSortOrientation.xlSortColumns)
关键的一句VB.NET EXCEL sort 列排序代码就是
Xlssheet.UsedRange.Sort(Key1:=Xlssheet.Range(Xlssheet.Cells(1,_ Orientation:=Excel.XlSortOrientation.xlSortColumns)原文链接:https://www.f2er.com/vb/257685.html