I try to take cell's data from excel file and save this data on text file, but after I use this code:
我尝试从excel文件中获取单元格数据并将此数据保存在文本文件中,但在使用此代码后:
Imports System.IO
Imports Microsoft.Office.Interop
Imports Microsoft.Office.Interop.Excel
Public Class Form1
Private myWriter As New StreamWriter("C:\myFile.txt")
Dim appXL As Excel.Application
Dim wbXL As Excel.Workbook
Dim shXL As Excel.Worksheet
Dim XRng As Excel.Range
Dim CellValue As String
Private Sub btnRead_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRead.Click
appXL = New Excel.Application
wbXL = appXL.Workbooks.Open("C:\Worksheet.xlsx")
appXL.Visible = True
appXL.Workbooks.Add(Type.Missing)
shXL = wbXL.Worksheets(1)
shXL.Visible = True
XRng = CType(appXL.ActiveSheet, Excel.Worksheet).Range("A1").Value2
CellValue = XRng.ToString()
myWriter.WriteLine(CellValue)
myWriter.Close()
wbXL.Close()
appXL.Quit()
End Sub
End Class
The result in text file was System.__ComObject
文本文件中的结果是System .__ ComObject
What should I make correction in the code?
我应该在代码中进行哪些更正?
1 个解决方案
#1
0
Instead of using CellValue = XRng.ToString()
, try using CellValue = XRng.Value
.
而不是使用CellValue = XRng.ToString(),尝试使用CellValue = XRng.Value。
#1
0
Instead of using CellValue = XRng.ToString()
, try using CellValue = XRng.Value
.
而不是使用CellValue = XRng.ToString(),尝试使用CellValue = XRng.Value。