最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C#編程讀取文檔Doc、Docx及Pdf內(nèi)容的方法

 更新時(shí)間:2015年05月13日 11:14:50   作者:歐陽不瘋  
這篇文章主要介紹了C#編程讀取文檔Doc、Docx及Pdf內(nèi)容的方法,涉及C#操作COM組件讀取Doc、Docx及Pdf文檔的相關(guān)技巧,需要的朋友可以參考下

本文實(shí)例講述了C#編程讀取文檔Doc、Docx及Pdf內(nèi)容的方法。分享給大家供大家參考。具體分析如下:

Doc文檔:Microsoft Word 14.0 Object Library (GAC對象,調(diào)用前需要安裝word。安裝的word版本不同,COM的版本號也會不同)
Docx文檔:Microsoft Word 14.0 Object Library (GAC對象,調(diào)用前需要安裝word。安裝的word版本不同,COM的版本號也會不同)
Pdf文檔:PDFBox

/*
 作者:GhostBear
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
using org.pdfbox.pdmodel;
using org.pdfbox.util;
using Microsoft.Office.Interop.Word;
namespace TestPdfReader
{
 class Program
 {
 static void Main(string[] args)
 {
  //PDF
  PDDocument doc = PDDocument.load(@"C:\resume.pdf");
  PDFTextStripper pdfStripper = new PDFTextStripper();
  string text = pdfStripper.getText(doc);
  string result = text.Replace('\t', ' ').Replace('\n', ' ').Replace('\r', ' ').Replace(" ", "");
  Console.WriteLine(result);
  //Doc,Docx
  object docPath = @"C:\resume.doc";
  object docxPath = @"C:\resume.docx";
  object missing=System.Reflection.Missing.Value;
  object readOnly=true;
  Application wordApp;
  wordApp = new Application();
  Document wordDoc = wordApp.Documents.Open(ref docPath,
       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);
  string text2 = FilterString(wordDoc.Content.Text);
  wordDoc.Close(ref missing, ref missing, ref missing);
  wordApp.Quit(ref missing, ref missing, ref missing);
  Console.WriteLine(text2);
  Console.Read();
  
 }
 private static string FilterString(string input)
 {
  return Regex.Replace(input, @"(\a|\t|\n|\s+)", "");
 }
 }
}

希望本文所述對大家的C#程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評論

辽阳县| 叙永县| 合川市| 无锡市| 尉犁县| 竹北市| 绥中县| 东明县| 昌宁县| 永仁县| 航空| 仲巴县| 子长县| 南华县| 黔江区| 大冶市| 武安市| 贺州市| 泗洪县| 楚雄市| 连城县| 叶城县| 莱西市| 麟游县| 黎川县| 永清县| 濉溪县| 会泽县| 永靖县| 武平县| 通城县| 仁化县| 布拖县| 大理市| 甘德县| 宁化县| 汝南县| 宜昌市| 咸宁市| 辉县市| 许昌县|