在Vb.net中保存Word文档

时间:2018-07-15 16:43:29

标签: vb.net document savefiledialog

我是Vb的新手,将文本从文本框中保存到Word文档时遇到了一个问题。该文档可以很好地保存到我想保存的任何位置,但是当我打开它时会弹出 enter image description here

这是保存的代码

Private Sub BtnSave_Click(sender As Object, e As EventArgs) Handles BtnSave.Click
    Dim SaveDialog As New SaveFileDialog
    SaveDialog.Filter = "Word Document (*.docx)|*.docx|Word 97-2003 Document (*.doc)|*.doc|Plain Text (*.txt)|*.txt"
    SaveDialog.ShowDialog()
    If SaveDialog.FileName <> "" Then
        Dim writer As New StreamWriter(SaveDialog.FileName)
        writer.WriteLine(TxtPreviewcertificate.Text)
        writer.Close()
    End If
End Sub

结束类 如果有人可以帮助我,谢谢。

1 个答案:

答案 0 :(得分:-1)

我将其从.docx更改为doc

SaveDialog.Filter = "Word Document (*.docx)|*.docx|Word 97-2003 Document (*.doc)|*.doc|Plain Text (*.txt)|*.txt"