欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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對(duì)象,調(diào)用前需要安裝word。安裝的word版本不同,COM的版本號(hào)也會(huì)不同)
Docx文檔:Microsoft Word 14.0 Object Library (GAC對(duì)象,調(diào)用前需要安裝word。安裝的word版本不同,COM的版本號(hào)也會(huì)不同)
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+)", "");
 }
 }
}

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

相關(guān)文章

最新評(píng)論