Dim dlg As New OpenFileDialog '定义一个新的OpenFileDialog
dlg.Filter= "Excel文件|*.xls" '设置筛选器
If dlg.ShowDialog = DialogResult.Ok Then '如果用户单击了确定按钮
Dim savefile = ProjectPath & "test.txt"
Dim App As New MSExcel.Application
Dim workbooks As object
Dim mWorkBook As object
Dim mWSheet As object
try
App.Visible = False
App.DisplayAlerts = False
workbooks = App.Workbooks
mWorkBook = workbooks.Open(dlg.FileName, 0, False, 5, "", "", False, MSExcel.XlPlatform.xlWindows, "", True, False, 0, True, False, False)
mWSheet = mWorkBook.Worksheets(1)
Dim range = mWSheet.UsedRange
Dim rngCurrentRow As object
range.Replace("\n", " ", Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
'range.Replace(",", columnDelimeter, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing)
mWorkBook.SaveAs(savefile, MSExcel.XlFileFormat.xlCSV, Type.Missing, Type.Missing, Type.Missing, Type.Missing, MSExcel.XlSaveAsAccessMode.xlExclusive,Type.Missing, Type.Missing, Type.Missing, Type.Missing, False)
catch ex As exception
msgbox(ex.message)
finally
If mWSheet IsNot Nothing Then mWSheet = Nothing
If mWorkBook IsNot Nothing Then mWorkBook.Close(Type.Missing, Type.Missing, Type.Missing)
If mWorkBook IsNot Nothing Then mWorkBook = Nothing
app.Quit()
System.Runtime.InteropServices.Marshal.ReleaseComObject(app)
If app IsNot Nothing Then app = Nothing
GC.WaitForPendingFinalizers()
GC.Collect()
GC.WaitForPendingFinalizers()
GC.Collect()
End try
End If