| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 808 人关注过本帖
标题:想在这个程序中加点东西,求助!
只看楼主 加入收藏
cywanwy520
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2011-11-17
结帖率:0
收藏
已结贴  问题点数:20 回复次数:2 
想在这个程序中加点东西,求助!
我做的是,在C#中嵌入Word,可以阅读它,但是,我现在想要能够在里面对它进行修改,保存,以及一些别的功能,有大神能解决么?请教。代码如下。附件如下!
using System;
using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        private Object oDocument;

        public Form1()
        {
            InitializeComponent();
            this.axWebBrowser1.NavigateComplete2 += new AxSHDocVw.DWebBrowserEvents2_NavigateComplete2EventHandler(this.axWebBrowser1_NavigateComplete2);
            this.Load += new System.EventHandler(this.Form1_Load);
            this.Closed += new System.EventHandler(this.Form1_Closed);
                    

        }

        private void button1_Click(object sender, System.EventArgs e)
        {

            String strFileName;

            //Find the Office document.
            openFileDialog1.FileName = "";
            openFileDialog1.ShowDialog();
            strFileName = openFileDialog1.FileName;

            //If the user does not cancel, open the document.
            if (strFileName.Length != 0)
            {
                Object refmissing = System.Reflection.Missing.Value;
                oDocument = null;
                axWebBrowser1.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
            }
        }

        public void Form1_Load(object sender, System.EventArgs e)
        {
            button1.Text = "Browse";
            openFileDialog1.Filter = "Office Documents(*.doc, *.xls, *.ppt)|*.doc;*.xls;*.ppt";
            openFileDialog1.FilterIndex = 1;
        }

        public void Form1_Closed(object sender, System.EventArgs e)
        {
            oDocument = null;
        }

        public void axWebBrowser1_NavigateComplete2(object sender, AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event e)
        {

            //Note: You can use the reference to the document object to
            //      automate the document server.

            Object o = e.pDisp;

            oDocument = o.GetType().InvokeMember("Document", BindingFlags.GetProperty, null, o, null);

            Object oApplication = o.GetType().InvokeMember("Application", BindingFlags.GetProperty, null, oDocument, null);

            Object oName = o.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, oApplication, null);

           //MessageBox.Show("File opened by: " + oName.ToString());
        }

        private void axWebBrowser1_Enter(object sender, EventArgs e)
        {

        }
                    
    }
}


WindowsFormsApplication1.zip (189.4 KB)
搜索更多相关主题的帖子: 阅读 private Object public 
2011-11-17 10:41
冲冲走过
Rank: 2
等 级:论坛游民
帖 子:69
专家分:72
注 册:2011-10-2
收藏
得分:10 
关注
2011-11-18 12:12
单行道1129
Rank: 3Rank: 3
来 自:山东潍坊
等 级:论坛游侠
帖 子:38
专家分:118
注 册:2011-10-26
收藏
得分:10 
private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog sg = new SaveFileDialog();
            sg.Filter = "文本文件(*.TXT)|*.txt";
            sg.AddExtension = true;
            if (sg.ShowDialog() == DialogResult.OK)
            {
                StreamWriter wg = new StreamWriter(sg.FileName);
                wg.Write(textBox1.Text);
                wg.Close();

            }

        }

        private void 新建ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                DialogResult result = MessageBox.Show("要保存正在编辑的文件吗?", "保存文件", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    保存ToolStripMenuItem_Click(null, null);
                    textBox1.Clear();

                }
                else
                    textBox1.Clear();

            }

        }

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (textBox1.Text != "")
            {
                DialogResult result = MessageBox.Show("要保存正在编辑的文件吗?", "保存文件", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (result == DialogResult.Yes)
                {
                    保存ToolStripMenuItem_Click(null, null);
                    textBox1.Clear();

                }
            }
            OpenFileDialog fg = new OpenFileDialog();
            fg.Filter = "文本文件(*.TXT)|*.txt";
            if (fg.ShowDialog() == DialogResult.Yes)
            {
                FileInfo f = new FileInfo(fg.FileName);
                StreamReader reader = f.OpenText();
                textBox1.Text = reader.ReadToEnd();
                reader.Close();
            }
        }
是不是要这些东西啊 ???
2011-11-18 12:58
快速回复:想在这个程序中加点东西,求助!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.025091 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved