.NET读取Office文件内容(word、excel、ppt)
来源:互联网 发布:03版倚天屠龙记 知乎 编辑:程序博客网 时间:2024/05/12 12:14
引用命名空间
using Microsoft.Office.Core;using Word = Microsoft.Office.Interop.Word;using Excel = Microsoft.Office.Interop.Excel;using PowerPoint = Microsoft.Office.Interop.PowerPoint;
Word文件的读取
public string ReadFile() { string text = string.Empty; Word.ApplicationClass app = null; Word.Document doc = null; object readOnly = true; object missing = System.Reflection.Missing.Value; object fileName = this.FileInstance.FullName; try { app = new Microsoft.Office.Interop.Word.ApplicationClass(); doc = app.Documents.Open(ref fileName, ref missing, ref readOnly, 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); text = doc.Content.Text.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty); } catch { } finally { doc.Close(ref missing, ref missing, ref missing); doc = null; app.Quit(ref missing, ref missing, ref missing); app = null; } return text; }
Excel文件的读取
public string ReadFile() { string text = string.Empty; Excel.ApplicationClass app = null; Excel.Workbook book = null; object readOnly = true; object missing = System.Reflection.Missing.Value; object fileName = this.FileInstance.FullName; try { app = new Microsoft.Office.Interop.Excel.ApplicationClass(); book = app.Workbooks.Open(fileName.ToString(), missing, readOnly, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing); foreach (Excel.Worksheet sheet in book.Sheets) { for (int i = 1; i <= sheet.UsedRange.Cells.Rows.Count; i++) { for (int j = 1; j <= sheet.UsedRange.Cells.Columns.Count; j++) { text += ((Excel.Range)sheet.Cells[i, j]).Text.ToString().Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty) + " "; } } } } catch { } finally { book.Close(missing, fileName, missing); book = null; app.Quit(); app = null; } return text; }
PPT文件的读取
public override string ReadFile() { string text = string.Empty; PowerPoint.ApplicationClass app = null; PowerPoint.Presentation pp = null; object readOnly = true; object missing = System.Reflection.Missing.Value; object fileName = this.FileInstance.FullName; try { app = new Microsoft.Office.Interop.PowerPoint.ApplicationClass(); pp = app.Presentations.Open(fileName.ToString(), Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); foreach (PowerPoint.Slide slide in pp.Slides) { foreach (PowerPoint.Shape shape in slide.Shapes) { text += shape.TextFrame.TextRange.Text.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty) + " "; } } } catch { } finally { pp.Close(); pp = null; app.Quit(); app = null; } return text; }
0 0
- .NET读取Office文件内容(word、excel、ppt)
- .net 实现Office文件预览 Word PPT Excel
- java读取word-excel-ppt文件
- VSTO 得到Office文档的选中内容(Word、Excel、PPT、Outlook)
- Java通过poi读取word,excel,ppt文件中文本(excel,ppt部分)
- office 文件 (Word / excel / ppt / access) 文件修复
- php office文件(word/excel/ppt)转pdf文件
- .NET WEB 实现office文档(word、excel、ppt)转PDF
- java操作office和pdf文件:读取word,excel和pdf文档内容
- .net 实现Office文件预览,word文件在线预览、excel文件在线预览、ppt文件在线预览,excel转html,office格式转换,
- 将Office(如:Word、Excel、PPT 等)文件转PDF(通过OpenOffice实现)
- 将Office(如:Word、Excel、PPT 等)文件转html(通过OpenOffice实现)
- Android遍历获取Office格式(Word,Excel,PPT,PDF)的文件并打开
- office(如:Word、Excel、PPT 等)文件轻松实现在线预览
- Java通过poi读取word,excel,ppt文件中文本(word部分)
- .NET读取Excel文件内容
- Winform中显示Office文档(word,EXCEL,PPT)
- Winform中显示Office文档(word,EXCEL,PPT)
- SSH 登录 免密码
- ios 支付宝支付问题解决demo的报错
- Linux C编程--进程介绍2--exec函数
- linux下杀死进程(kill)的N种方法
- 新的博客地址
- .NET读取Office文件内容(word、excel、ppt)
- java过滤器和监听器详解
- Mpeg2 Ts 流的分析
- Notification
- Ibatis开发环境搭建和编写第一个程序
- 命令行模式下java package的编译与运行
- JS 闭包理解
- 动态链接库和静态链接库
- ubuntu13.04 运行 BSR