16,555
社区成员
发帖
与我相关
我的任务
分享
Private Function CreateFile() As Boolean
Dim rValue As Boolean = False
Dim myExcel As New Excel.Application
Dim myBook As Excel.Workbook
Dim mySheet As Excel.Worksheet
Dim Folder as string="C:\File\"
Dim FileName as string = "A.csv"
Try
myBook = myExcel.Workbooks.Add()
mySheet = CType(myBook.Worksheets.Item(1), Excel.Worksheet)
mySheet.Activate()
mySheet.Cells(2, 1) = "Name"
mySheet.Cells(3, 1) = "Sex"
myBook.SaveAs(Folder & FileName)
myBook.Close(True)
myExcel.Quit()
myBook = Nothing
myExcel = Nothing
ProcessKill()
GC.Collect()
bReturnVal = True
Catch ex As Exception
mErrMsg = ex.Message
myBook.Close()
myExcel.Quit()
myBook = Nothing
myExcel = Nothing
ProcessKill()
rValue= False
End Try
Return rValue
End Function
Private Sub ProcessKill()
Dim p As System.Diagnostics.Process
p = New System.Diagnostics.Process
For Each p In System.Diagnostics.Process.GetProcesses()
If p.ProcessName.ToUpper() = "EXCEL" Then
p.Kill()
End If
Next
End Sub