cetee
級別: 略有小成
|
vb.net 求助,請大家?guī)兔ΑVx謝 Imports excel = Microsoft.Office.Interop.Excel Imports System.IO Public Class Form1 Private Sub Button1_Click(sender As Object, e As EventArgs) End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End Sub Private Sub Button1_Click_1(sender As Object, e As EventArgs) Handles Button1.Click Dim fileTest As String = "c:\Temp\ExcelTest\test.xlsx" If File.Exists(fileTest) Then File.Delete(fileTest) End If Dim oexcel As Object oexcel = CreateObject("excel.Application") Dim obook As excel.Workbook Dim osheet As excel.Worksheet obook = oexcel.Workbooks.Add osheet = oexcel.Worksheets(1) osheet.Name = "test name" osheet.Range("A").Value = "button 1" obook.SaveAs(fileTest) obook.Close() obook = Nothing oexcel.Quit() oexcel = Nothing End Sub End Class |
---|---|
|
不小心遇見你
自動項目、PLC、視覺、通訊等工控軟件開發(fā)QQ3515716
級別: 工控俠客
|
你是對某一表格讀寫吧? osheet.Range("A").Value是讀取 再說你這個也沒指定那個表格 默認讀取sheet1 再說也應(yīng)該是 dim str1 as string str1=osheet.Range("A1").Value 'A是列號 1是行號 正確的寫法 dim str1 as string AppXls.Workbooks(1).Sheets("Sheet1").Cells(1, 1).Value = "這是寫入的" '這是寫入 用Cells(A, 1)也可 str1 = AppXls.Workbooks(1).Sheets("Sheet1").Cells(1, 1).Value '這是讀取 用Cells(A, 1)也可 MsgBox(str1 ) 雖然沒用過VB net 應(yīng)該和vb語法很接近 C#也差不多是這樣 |
|
---|---|---|
|