Try this code, change to your suit before
'' Working example
Imports System.IO
Imports System.Reflection
Imports System.Runtime.InteropServices
Imports System.Globalization
Imports System.Threading
Imports Microsoft.Office.Interop.Excel
Imports Excel = Microsoft.Office.Interop.Excel
'' References -> COM -> Microsoft.Excel XX.0 Object Library
''' <summary>
''' Export one-dimensional array to Excel column
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
''' <remarks></remarks>
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim oldCult = CultureInfo.CurrentCulture()
'' This line is very important!
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US") '<-- change culture on whatever you need
Dim miss As Object = Type.Missing 'System.Reflection.Missing.Value
Dim i As Integer
Dim textfile As String = "C:\Test\MyCodes.txt"
If (Not File.Exists(textfile)) Then
MessageBox.Show("File does not exists")
Return
End If
'' Open Excel
Dim m_objExcel As Excel.Application = New Excel.Application
m_objExcel.Visible = True
m_objExcel.UserControl = True
Dim m_objBooks As Excel.Workbooks = CType(m_objExcel.Workbooks, Excel.Workbooks)
Dim m_objBook As Excel.Workbook = Nothing
Try
'' Open workbook
m_objBooks.Open("C:\Test\Invoices.xlsx", False, False, miss, "", miss, miss, Excel.XlPlatform.xlWindows, miss, miss, miss, miss, miss, miss, miss)
m_objBook = m_objExcel.ActiveWorkbook
m_objBook.Activate() 'optional
Dim m_objSheets As Sheets = m_objBook.Sheets
Dim m_objSheet As Worksheet = m_objSheets.Item(1) '<--"Sheet1"
m_objSheet.Cells.ClearContents() 'optional may to remove this line
Dim m_objCells As Range = m_objSheet.Cells
Dim m_objRange As Range = Nothing
If IO.File.Exists(textfile) Then
'Create a StreamReader and open our text file
Using pars As New StreamReader(textfile)
i = 1
'Now add our columns (we will check to make sure the column doesnt exist before adding it)
While Not pars.EndOfStream
Dim line As String = pars.ReadLine
'' write data starting from cell "A1"
m_objRange = m_objSheet.Range(m_objCells(i, 1), m_objCells(i, 1))
m_objRange.NumberFormat = "@"
m_objRange.Value2 = line
i += 1
End While
End Using
End If
'' optional just for debug only
m_objSheet.Range(m_objCells(1, 1), m_objCells(i - 1, 1)).Select()
m_objRange = m_objSheet.Range(m_objCells(1, 1), m_objCells(i - 1, 1))
m_objRange.BorderAround(Excel.XlLineStyle.xlContinuous, _
Excel.XlBorderWeight.xlMedium, Excel.XlColorIndex.xlColorIndexAutomatic, Excel.XlColorIndex.xlColorIndexAutomatic)
m_objSheet.Columns.AutoFit()
'' Save the file in the typical workbook format
m_objBook.SaveAs("C:\Test\numbers.xlsx", Excel.XlFileFormat.xlWorkbookDefault, "", "", False, False, XlSaveAsAccessMode.xlNoChange, miss, miss, miss, miss, miss)
Catch ex As System.Exception
MessageBox.Show(ex.Message & vbCrLf & ex.StackTrace)
Finally
'' close workbook and quit Excel
If Not m_objBook Is Nothing Then
m_objBook.Close(False, miss, miss)
m_objBook = Nothing
End If
m_objExcel.Quit()
'' release process if it's still active
System.Runtime.InteropServices.Marshal.FinalReleaseComObject(m_objExcel)
Thread.CurrentThread.CurrentCulture = oldCult
End Try
End Sub
_____________________________________
C6309D9E0751D165D0934D0621DFF27919