2017-10-13 12 views
0

私はワードファイルからテキストを読むには? C#

  1. 私はC#で新しい文書を作成することはできませんC#での文書ファイルからテキストを読み取るしようとしています。
    "Microsoft.Office.Interop.Word" または "using System.Windows.Documents"を使用しようとしましたが、コード "Document doc = new Document"を認識しません。
  2. さらに、.docxファイルからテキストを読み取るにはどうすればよいですか?

コード:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Data; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Imaging; 
using System.Windows.Navigation; 
using System.Windows.Shapes; 
using Microsoft.Office.Interop.Word; //didnt recognize "Office" 



namespace DocumentTest1 
{ 
    /// <summary> 
    /// Interaction logic for MainWindow.xaml 
    /// </summary> 
    public partial class MainWindow : Window 
{ 
    public MainWindow() 
    { 
     InitializeComponent(); 
    } 

    Application word = new Application(); 
    Document doc = new Document(); 
    } 

}


何が問題だろうか? TNX

+2

あなたが参照を追加しませんでしたコードは、以下を参照してください? – KeithL

+0

このリンクを確認してください:https://stackoverflow.com/questions/3633615/how-can-i-read-docx-file – Bambuk

+0

「Microsoft Office List 16.0」というリファレンスを追加します。私は別のものが必要ですか? – Olive

答えて

-2

こんにちは

List<string> data = new List<string>(); 
Application app = new Application(); 
Document doc = app.Documents.Open(ref readFromPath); 

foreach (Paragraph objParagraph in doc.Paragraphs) 
    data.Add(objParagraph.Range.Text.Trim()); 
+0

tnx。行 "Document doc = app.Documents.Open(ref readFromPath);"私が前に述べたように動かない。多分私は参照に問題があるが、私は一致参照を見つけられなかった。 – Olive

関連する問題