|
|
|
| вот код
Public Function exporthv() As Boolean
Dim t As New db.ph_exportDataTable
Dim ta As New dbTableAdapters.ph_exportTableAdapter
ta.Fill(t, userid, d1, d2)
If FileIO.FileSystem.FileExists(Application.StartupPath & "\Export\Hamayqayin\PayDB.xlsx") = True Then
My.Computer.FileSystem.DeleteFile(Application.StartupPath & "\Export\Hamayqayin\PayDB.xlsx")
End If
Dim Excel As Object = CreateObject("Excel.Application")
Dim strFilename As String
Dim intCol, intRow As Integer
Dim strPath As String = Application.StartupPath & "\Export\Hamayqayin\"
If Excel Is Nothing Then
DevComponents.DotNetBar.MessageBoxEx.Show("", "Վճարներ", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Return False
End If
Try
With Excel
.SheetsInNewWorkbook = 1
.Workbooks.Add()
.Worksheets(1).Select()
.cells(1, 1).value = "Heading"
.cells(1, 1).EntireRow.Font.Bold = True
Dim intI As Integer = 1
For intCol = 0 To t.Columns.Count - 1
.cells(2, intI).value = t.Columns(intCol).ColumnName
.cells(2, intI).EntireRow.Font.Bold = True
intI += 1
Next
intI = 3
Dim intK As Integer = 1
For intCol = 0 To t.Columns.Count - 1
intI = 3
For intRow = 0 To t.Rows.Count - 1
.Cells(intI, intK).Value = t.Rows(intRow).ItemArray(intCol)
intI += 1
Next
intK += 1
Next
If Mid$(strPath, strPath.Length, 1) <> "\" Then
strPath = strPath & "\"
End If
strFilename = strPath & "PayDB.xlsx"
.ActiveCell.Worksheet.SaveAs(strFilename)
End With
Excel.Workbooks.Close()
Excel.Quit()
Excel = Nothing
'System.Runtime.InteropServices.Marshal.ReleaseComObject(Excel)
GC.Collect()
DevComponents.DotNetBar.MessageBoxEx.Show("Տվյալները արտահանված են", "Վճարներ", MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
DevComponents.DotNetBar.MessageBoxEx.Show(ex.Message, "Վճարներ", MessageBoxButtons.OK, MessageBoxIcon.Information)
End Try
'Dim pro() As Process = System.Diagnostics.Process.GetProcessesByName("EXCEL")
'For Each i As Process In pro
'i.Kill()
'Next
Return True
End Function
|
| |
|
| |
|
|
|
|
| можно попробовать так
Dim xlsApp As Object
xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = False
xlsApp.Workbooks.Open(имя_файла)
...
xlsApp.ActiveWorkbook.Close(False)
xlsApp.Quit()
xlsApp = Nothing | |
|
| |
|
|
|
| нет( | |
|
| |
|
|