Dim dlg As new OpenFileDialog dlg.Filter = "Excel|*.xls;*.xlsx" If dlg.ShowDialog = DialogResult.OK Then Dim App As New MSExcel.Application try Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open(dlg.FileName) For i As Integer = 7 To 20 Dim Ws1 As MSExcel.WorkSheet = Wb.WorkSheets("Page " & i) '指定工作表 Dim Ws2 As MSExcel.WorkSheet = Wb.WorkSheets("Page " & (i + 175)) '指定工作表 ws2.UsedRange.Copy ws1.Select ws1.Cells(2, 6).Select ws1.paste Dim Rg As MSExcel.Range = Ws1.Cells 'Rg.WrapText = True Rg.EntireColumn.AutoFit '自动调整列宽 Next app.Visible = True catch ex As exception msgbox(ex.message) app.quit End try End If
|