以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]Word另存为rtf文件  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=158400)

--  作者:天一生水
--  发布时间:2020/11/18 21:29:00
--  [求助]Word另存为rtf文件

老师好!

我利用代码更改Word文档的后缀为.rtf后,通过RichTextBox打开会出现乱码。打开rtf代码如下。


Dim ct As New System.Windows.Forms.RichTextBox

ct.Dock = System.Windows.Forms.DockStyle.Fill

ct.Name ="RichTextBox1"

e.Form.Controls("Panel1").BaseControl.Controls.Add(ct)

Dim f As Font = New Font("Verdana", 16F, FontStyle.Regular, GraphicsUnit.Point)

ct.Font = f

ct.LoadFile("d:\\test.rtf",System.Windows.Forms.RichTextBoxStreamType.PlainText)


-----------------

打开Word后另存为rtf文件,没有出现乱码问题。因此请教怎样把Word文件另存为rtf文件?

Dim app As New MSWord.Application
try
    Dim fileName = "e:\\test.docx"
    app.Documents.Open(fileName)


    app.


catch ex As exception
    msgbox(ex.message)
finally
    app.Quit
End try

[此贴子已经被作者于2020/11/19 8:28:04编辑过]

--  作者:有点蓝
--  发布时间:2020/11/19 8:42:00
--  
Dim tmp As String  =  "D:\\问题\\123.docx" 
Dim name As String =  "D:\\问题\\123.rtf"

Dim app As New MSWord.Application
Dim doc = app.Documents.Open(tmp)
doc.SaveAs(Filename:=name , FileFormat:=MSWord.WdSaveFormat.wdFormatRTF)
app.quit