如何使用Vb.Net将文本文件转换为.Doc格式 [英] How Can I Convert Text File To .Doc Format Using Vb.Net

查看:121
本文介绍了如何使用Vb.Net将文本文件转换为.Doc格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将.txt文件转换为.doc和.docx格式。我通过创建txt文件添加了代码,请继续使用此代码。

how to convert .txt file to .doc and .docx format. I have added code by creating txt file, Kindly proceed by this code.

Dim text As String = ""
           Dim files() As String = IO.Directory.GetFiles(sfilename)
           For Each sFile As String In files

               If sFile.Contains(".txt") Then
                   text &= IO.File.ReadAllText(sFile) & vbNewLine
               End If
           Next
           Dim objStreamWriter As StreamWriter
           Dim txtfilename As String
             txtfilename = sfilename  & ".txt"
           objStreamWriter = New StreamWriter(txtfilename)
           objStreamWriter.WriteLine(text)
           objStreamWriter.Close()

推荐答案

您必须创建Word文档,然后将您已阅读的文件的内容添加到其中。例如,请参阅如何在MSDN中自动化Visual Basic .NET中的Word以创建新文档[< a href =http://support.microsoft.com/kb/316383/entarget =_ blanktitle =New Window> ^ ]。
You have to create the Word Document and then add to it the content of the file you've read. See , for instance "How to automate Word from Visual Basic .NET to create a new document" at MSDN[^].


这篇关于如何使用Vb.Net将文本文件转换为.Doc格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆