以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- 打开一个EXCEL表,再保存为CSC文档并关闭,再用文本TXT程序打开并保存为TXTS格式, (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=90857) |
-- 作者:zhuxin -- 发布时间:2016/9/22 22:28:00 -- 打开一个EXCEL表,再保存为CSC文档并关闭,再用文本TXT程序打开并保存为TXTS格式, 打开一个EXCEL表,再保存为CSC文档并关闭,再用文本TXT程序打开并保存为TXTS格式,这样的代码怎样写?想很久,也查了很久也查不出有什么好语句 |
-- 作者:有点蓝 -- 发布时间:2016/9/22 23:24:00 -- 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
|
-- 作者:zhuxin -- 发布时间:2016/9/23 9:15:00 -- 多谢版主甘晚还帮击键盘 |