积极答复者
如何用VB.net读取Word文档,并提取文字

问题
答案
-
你好
或者你可以用以下的 CODE 自看能不能解決這個問題
這是我先前用的CODE...有時間會把他優化一點...先試試看..
Dim StringCopyFromWord as string = ""
Dim wd As New Microsoft.Office.Interop.Word.Application
wd.Documents.Open("d:\Hello.docx")
wd.Selection.WholeStory()
wd.Selection.Copy()
RichTextBox1.Paste()
wd.Quit()
StringCopyFromWord = RichTextBox1.Text
Please correct me if my concept is wrong
Chi- 已标记为答案 Mog Liang 2010年11月25日 2:30
全部回复
-
你好
或者你可以用以下的 CODE 自看能不能解決這個問題
這是我先前用的CODE...有時間會把他優化一點...先試試看..
Dim StringCopyFromWord as string = ""
Dim wd As New Microsoft.Office.Interop.Word.Application
wd.Documents.Open("d:\Hello.docx")
wd.Selection.WholeStory()
wd.Selection.Copy()
RichTextBox1.Paste()
wd.Quit()
StringCopyFromWord = RichTextBox1.Text
Please correct me if my concept is wrong
Chi- 已标记为答案 Mog Liang 2010年11月25日 2:30
-
尝试使用RichTextBox:
public void LoadMyFile()
{
// Create an OpenFileDialog to request a file to open.
OpenFileDialog openFile1 = new OpenFileDialog();
// Initialize the OpenFileDialog to look for RTF files.
openFile1.DefaultExt = "*.rtf";
openFile1.Filter = "RTF Files|*.rtf";
// Determine whether the user selected a file from the OpenFileDialog.
if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
openFile1.FileName.Length > 0)
{
// Load the contents of the file into the RichTextBox.
richTextBox1.LoadFile(openFile1.FileName);
}
}
richtextbox1.Text; //Get value here... -
ChiYau的办法应该可以 通过VSTO可以对Word中的任意对象进行操作
Raymond Tang (Microsoft C# MVP)
Denn Ich Gehoer nur mir
.NET交流群71840452
微软中文论坛同城社区成都QQ群:74268428
My Chinese Blog
Chengdu,Sichuan Province,China