以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- 如果读取全部都是字符的rtf文件? (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=162838) |
-- 作者:ap9709130 -- 发布时间:2021/4/16 18:29:00 -- 如果读取全部都是字符的rtf文件? 老师 比如官方的代码文件,EventCode.rtf。要怎么才能读取出来,并得到相应的字符? 多谢!
|
-- 作者:有点蓝 -- 发布时间:2021/4/17 9:21:00 -- 参考: Dim Curfile As String = "D:\\问题\\EventCode.rtf" Try Dim Rich As String = FileSys.ReadAllText(Curfile) Dim rtBox As new System.Windows.Forms.RichTextBox() rtBox.Rtf = Rich Output.Show(rtBox.text) Catch ex As Exception msgbox(ex.message) End Try |
-- 作者:ap9709130 -- 发布时间:2021/4/17 10:12:00 -- 有点蓝老师 多谢。你这种可以读出来,但是分行符会没有了。我昨晚通过论坛的例子和查了一下资料,也可以读出来。代码如下: Dim app As New MSWord.Application try Dim fileName = ProjectPath & "EventCode.rtf" Dim doc = app.Documents.Open(fileName) For i As Integer = 1 To doc.paragraphs.count Output.show(Doc.paragraphs(i).range.text) Next catch ex As exception msgbox(ex.message) app.Quit End try app.Quit 大家看哪种方便吧。再次感谢有点蓝老师。
|
-- 作者:ap9709130 -- 发布时间:2021/4/17 10:27:00 -- 有点蓝老师 你的方法非常快,如果可以输出原来的格式,不去除了换符就好了,有方法吗?
|
-- 作者:有点蓝 -- 发布时间:2021/4/17 10:36:00 -- Dim Curfile As String = "D:\\问题\\EventCode.rtf" Try Dim Rich As String = FileSys.ReadAllText(Curfile) Dim rtBox As new System.Windows.Forms.RichTextBox() rtBox.Rtf = Rich Dim cr() As String = rtBox.text.split(vblf) For Each s As String In cr Output.Show(s) Next Catch ex As Exception msgbox(ex.message) End Try
|