引用命名空间

 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 = ; i <= sheet.UsedRange.Cells.Rows.Count; i++)
{
for (int j = ; 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;
}

.NET读取Office文件内容(word、excel、ppt)的更多相关文章

  1. 在线读取office 文件(Word excel 等)

    https://view.officeapps.live.com/op/view.aspx?src=http://www.xxx.com/uploadfile/app/11.xls src 后面的网址 ...

  2. 微信小程序云开发-云存储-下载并打开文件文件(word/excel/ppt/pdf)

    一.wxml文件 1.写文本框,用来获取文件链接. 2.按钮,点击下载文件 <!-- 下载文件(word/excel/ppt/pdf等) --> <view class=" ...

  3. 微信小程序云开发-云存储-上传文件(word/excel/ppt/pdf)到云存储

    说明 word/excel/ppt/pdf是从客户端会话选择文件.使用chooseMessageFile中选择文件. 一.wxml文件 上传按钮,绑定chooseFile <!--上传文件(wo ...

  4. 微信小程序云开发-云存储-上传、下载、打开文件文件(word/excel/ppt/pdf)一步到位

    一.wxml文件 <!-- 上传.下载.打开文件一步执行 --> <view class="handle"> <button bindtap=&quo ...

  5. 在线文档转换API word,excel,ppt等在线文件转pdf、png

    在线文档转换API提供word,excel,ppt等在线文件转pdf.png等,文档:https://www.juhe.cn/docs/api/id/259 接口地址:http://v.juhe.cn ...

  6. Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件

    Aspose是一个很强大的控件,可以用来操作word,excel,ppt等文件,用这个控件来导入.导出数据非常方便.其中Aspose.Cells就是用来操作Excel的,功能有很多.我所用的是最基本的 ...

  7. Atitit.office word  excel  ppt pdf 的web在线预览方案与html转换方案 attilax 总结

    Atitit.office word  excel  ppt pdf 的web在线预览方案与html转换方案 attilax 总结 1. office word  excel pdf 的web预览要求 ...

  8. java 如何将 word,excel,ppt如何转pdf--jacob

    问题:java 如果将 word,excel,ppt如何转pdf 我个人的观点:windows server下用 jacob; linux server下 用openoffice.   PS:1.本文 ...

  9. PDF/WORD/EXCEL/PPT 文档在线阅读

    查资料看了2种解决方法: 1.通过办公软件dll转换,用flans去看 2.通过Aspose转换成pdf格式,在用js前台读pdf(我用的pdf.js) 今天我解决的就是WORD/EXCEL/PPT ...

随机推荐

  1. SQL触发器中的deleted表和inserted表

    SQL触发器中的deleted表和inserted表 在触发器语句中用两个特殊的表一个是deleted表和inserted.它们是通过触发器操作自动创建驻留在内存中的临时表. 描述: Deleted表 ...

  2. iOS的设备及分辨率、图片命名

    iOS的设备及分辨率(iPhone竖屏/iPad横屏) 设备 分辨率 横宽比 iPhone 3GS.iPod Touch第三代 320 * 480 2 : 3 iPhone 4.iPod Touch第 ...

  3. jsp学习---使用jsp和JavaBean实现超简单网页计算器

    一.需求 如题,用jsp实现一个超简单的网页计算器. 二.实现 1.效果图 1)初始界面: 2)随便输入两个数进行相乘: 3)当除数为零时提示报错: 2.代码 Calculator.java pack ...

  4. WCF学习记录

    一个demo: http://www.cnblogs.com/iamlilinfeng/p/4083827.html

  5. hihocode 1077 : RMQ问题再临-线段树

    #1077 : RMQ问题再临-线段树 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到:小Hi给小Ho出了这样一道问题:假设整个货架上从左到右摆放了N种商品,并 ...

  6. [Shell]Bash变量:环境变量的配置文件和登录信息

    ----------------------------------------------------------------------------------------- 只有把环境变量放入配 ...

  7. hp小机定位网卡位置

    rad已经被olrad取代 HPUX下定位网卡位置                                                   一台HP小型机,可能配了多块网卡,在系统中以la ...

  8. SQl server master

    取一段连续时间,SQl server 2008可用,其他版本暂时没测试.           ),                                      ), )), )      ...

  9. SQL删除重复数据

    --首先将不是重复的数据提取出来,保存到一个临时表中 select distinct * into #temp from JX_Score --然后删除原来的表 delete from JX_Scor ...

  10. net.sf.json.JSONObject 和org.json.JSONObject 的差别

    http://my.oschina.net/wangwu91/blog/340721 net.sf.json.JSONObject 和org.json.JSONObject  的差别. 一.创建jso ...