私は、muiltilneオプションを有効にしたテキストボックスを持っています。 特定の単語ファイルの内容をそのテキストボックスに表示したいと思います。これどうやってするの?このコードを使用しますが、ファイルの名前を表示しているだけです。Wordファイルの内容をテキストボックスに表示
private void btnOpen_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.Title = "Open Word File";
openFileDialog1.Filter = "Word Files (*doc)|*docx";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document doc = new Microsoft.Office.Interop.Word.Document();
object fileName = openFileDialog1.FileName;
// Define an object to pass to the API for missing parameters
object missing = System.Type.Missing;
doc = word.Documents.Open(ref fileName,ref missing, ref missing);
String read = string.Empty;
List<string> data = new List<string>();
for (int i = 0; i < doc.Paragraphs.Count; i++)
{
string temp = doc.Paragraphs[i + 1].Range.Text.Trim();
if (temp != string.Empty)
data.Add(temp);
}
doc.Close();
word.Quit();
txtTxt.Text = data.ToString();
}
}
これはC#のWindowsフォームアプリケーションです。
助けてください!あなたは
txtTxt.Text = data.ToString();
data
ラインを使用して、テキストボックスにデータを追加している
- あなたはそれを開いたが、それはに見えましたそれでは。 – BugFinder
@BugFinderどのようにして内容を読むことができますか?私のコードを編集できますか? – Uniquedesign