vb.net .Excel 追加保存

2025-04-07 06:58:57
推荐回答(1个)
回答(1):

 Sub Excel()
        Const FilePath As String = "C:\1.xls"   '文件名
        Dim ExApp As Object = CreateObject("Excel.Application")
        ExApp.Visible = True

        If Not IO.File.Exists(FilePath) Then
            ExApp.Workbooks.Add()
            ExApp.ActiveWorkbook.SaveAs(FilePath)
        Else
            ExApp.Workbooks.Open(FilePath)
        End If

        Dim Wk As Object = ExApp.ActiveWorkbook
        Dim iRow As Integer = Wk.ActiveSheet.Range("A65535").End(3).Row + 1
        '添加需要的代码
        Wk.ActiveSheet.Cells(iRow, 1).Value = "xxxxx"
        ExApp = Nothing
        Wk = Nothing
    End Sub