123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using Microsoft.Office.Interop.Word;
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace WindowsFormsWordExcelDemo
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog = new OpenFileDialog();
- openFileDialog.Filter = "Word Files(*.docx)|*.docx|Word Files(*.doc)|*.doc";
- if (openFileDialog.ShowDialog() == DialogResult.OK)
- {
-
- Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
- Document document = word.Documents.Add(openFileDialog.FileName);
-
-
-
-
-
-
- Range range = document.Paragraphs[5].Range;
- document.Paragraphs.Add(range);
- document.Paragraphs[5].Range.Text = "hello world\n";
-
- word.Visible = true;
-
-
-
-
-
- MessageBox.Show("完成");
- }
- }
- }
- }
|