C#实现Word中表格信息读取 |
您所在的位置:网站首页 › wordapplication › C#实现Word中表格信息读取 |
C# 实现 Word 中表格信息读取 很多时候,会有很多信息存放在 Word ⽂档中。⽽我们需要把这些信息提取出来,另做它⽤。⽽ Word 的格式是 ms 的机密,不知道有没有 NB ⼈可以对其做字符流的分析,反正 我是没这能⼒也没这打算。所以就只能⽤ ms 提供的组件来进⾏编程。但 ms 没有提供托管的类库,⽽是提供了对 com 组件的 PIA 转换。具体添加,使⽤和相关知识,可以参见 kaneboy's blog 中的。⾼⼿的讲解,很是清晰。 ⽽我想做的是对 word ⽂档中的表信息进⾏提取。⽹上很难找到相关的代码(打开⼀个已有⽂档,对其内容进⾏分析),但我觉得这种⼯作是很有意义的。写了⼀段⼩的 Demo ,如下: object oFileName = @"C:\Documents and Settings\liush\My Documents\TestDoc.doc"; object oReadOnly = true; object oMissing = System.Reflection.Missing.Value; Word._Application oWord; Word._Document oDoc; oWord = new Word.Application(); oWord.Visible = true;// 只是为了⽅便观察 oDoc = oWord.Documents.Open(ref oFileName, ref oMissing, ref oReadOnly, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing); //MessageBox.Show(oDoc.Tables.Count.ToString()); for (int tablePos = 1; tablePos |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |