最近使用VB 去生成Excel,正常添加都可以,但是添加的顺序都是倒叙的,看着比较揪心。
解决方法如下:
Private _excelApp As Object = Nothing Private _wBooks As Excel.Workbooks = Nothing Private _wBook As Excel.Workbook = Nothing Private _activeSheet As Excel.Worksheet = Nothing _excelApp = New Excel.Application() _wBooks = _excelApp.Workbooks _wBook = _wBooks.Add(True) _activeSheet = _wBook.Sheets.Add(After:=_wBook.Sheets(_wBook.Sheets.Count))'添加到最后 _activeSheet.Name = "NewSheet" _activeSheet.PageSetup.CenterHorizontally = True '自动调整列宽 _activeSheet.Cells.EntireColumn.AutoFit() '排序 _activeSheet.UsedRange.Sort(Key1:=_activeSheet.Range(_activeSheet.Cells(1,2).Address),Order1:=Excel.XlSortOrder.xlAscending,_Header:=Excel.XlYesNoGuess.xlYes,Orientation:=Excel.XlSortOrientation.xlSortColumns)原文链接:https://www.f2er.com/vb/257858.html