逐行从Word文档中读取

逐行从Word文档中读取,第1张

逐行从Word文档中读取

好。我在这里找到了解决方案

最终代码如下:

Application word = new Application();document doc = new document();object fileName = path;// Define an object to pass to the API for missing parametersobject missing = System.Type.Missing;doc = word.documents.Open(ref fileName,        ref missing, ref missing, ref missing, ref missing,        ref missing, ref missing, ref missing, ref missing,        ref missing, ref missing, ref missing, ref missing,        ref missing, ref missing, ref missing);String read = string.Empty;List<string> data = new List<string>();for (int i = 0; i < doc.Paragraphs.Count; i++){    string temp = doc.Paragraphs[i + 1].Range.Text.Trim();    if (temp != string.Empty)        data.Add(temp);}((_document)doc).Close();((_Application)word).Quit();GridView1.DataSource = data;GridView1.DataBind();


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5064003.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-16
下一篇 2022-11-16

发表评论

登录后才能评论

评论列表(0条)

保存