Dim Excel As New Microsoft.Office.Interop.Excel.Application
Dim xlssht1 As Microsoft.Office.Interop.Excel.Worksheet
Dim xlssht2 As Microsoft.Office.Interop.Excel.Worksheet
Me.WindowState = FormWindowState.Minimized
Excel.Workbooks.Open(s_ExcelTemplatePath)
Excel.DefaultFilePath = s_save
xlssht1 = Excel.ActiveSheet
cmd.CommandText = s_sql
Me.WindowState = FormWindowState.Minimized
Dim i, j As Integer
Try
ds = cmd.ExecuteReader
Dim a(65535, ds.FieldCount)
While ds.Read()
For j = 0 To ds.FieldCount - 1
a(i, j) = ds.Item(j)
Next
i += 1
End While
ds.Close()
Excel.Workbooks.Open(s_ExcelTemplatePath)
Excel.DefaultFilePath = s_save
xlssht1 = Excel.ActiveSheet
Excel.Cells(2, 1) = "a"
Excel.Range(Excel.Cells(2, 1), Excel.Cells(i + 1, j + 1)).Value = a
Excel.Cells(1, 8) = s_from + "~" + s_to
Excel.Range("A2", Excel.ActiveCell.SpecialCells(Microsoft.Office.Interop.Excel.XlCellType.xlCellTypeLastCell)).Font.Size = 9
Catch ex As Exception
Me.WindowState = FormWindowState.Normal
MessageBox.Show(ex.Message.ToString)
Excel.Visible = True
Try
Excel.ActiveWorkbook.Close(SaveChanges:=False)
Catch ex1 As Exception
Excel.Quit()
Excel = Nothing
GC.Collect()
Exit Sub
End Try
Excel.Quit()
Excel = Nothing
GC.Collect()
End Try
xlssht2 = Excel.Sheets(2)
xlssht2.Activate()
xlssht1.Activate()
ReleaseExcel(Excel)
GC.Collect()