Dim t = CurrentTable Dim Book As New XLS.Book '定义一个Excel工作簿 Dim Sheet As XLS.Sheet = Book.Sheets(0) '引用工作簿的第一个工作表 Dim lms As new List(of String) For Each c As Col In t.Cols If c.Visible = True lms.Add(c.Name) If c.IsDate Then Dim style As XLS.Style = book.NewStyle style.Format = "yyyy-MM-dd" sheet.Cols(lms.Count-1).Style = style End If End If Next For i As Integer = 0 To lms.Count-1 Sheet(0,i).Value = lms(i) Next For r As Integer = 0 To t.Rows.Count-1 '填入数据 For i As Integer = 0 To lms.Count-1 If t.rows(r)(lms(i)) <> Nothing Sheet(r+1,i).Value = t.rows(r)(lms(i)) End If Next Next Dim dlg As New SaveFileDialog '定义一个新的SaveFileDialog dlg.Filter= "Excel文件|*.xls" '设置筛选器 If dlg.ShowDialog = DialogResult.Ok Then Book.Save(dlg.FileName) Dim Proc As New Process Proc.File = dlg.FileName Proc.Start() End If
|