Web浏览器中使用的Excel对象 [英] Excel object utilized in a web browser

查看:104
本文介绍了Web浏览器中使用的Excel对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

这将是我第一次发布有关编码问题的信息,通常我很擅长研究问题并找到解决方案,但现在我无所适从.我的编程技能几乎已经离开了我,所以我想您可以将我视为一个初学者,直到它回来为止.

问题:
我正在尝试创建一个嵌入式Office文档,该文档可以使用Web浏览器控件插入到我的Windows窗体中.使用它作为方法: http://support.microsoft. com/?scid = kb%3Ben-us%3B304662& x = 11& y = 11 [

Hello,

This would be the first time I''ve ever posted about a coding problem I have, usually I''m pretty good at researching the problem and finding my solutions but I''m at a loss now. My skills in programming have almost left me, so I guess you could deem me as a beginner for now till it comes back.

The problem:
I''m trying to create an embedded office document, that being excel into my windows form using the web browser control. Using this as a how to: http://support.microsoft.com/?scid=kb%3Ben-us%3B304662&x=11&y=11[^]

I can use a button event to open my file and the file will populate into my window. Now for my first problem though not as serious, I cannot figure out how to hide the Excel application. When my app opens the file into the web browser, Microsoft Excel still opens though it''s blank with no workbook. I''ve tried many different methods to make this hidden, but I just can''t seem to understand how the web browser is using the object, when I try to declare a new one it will compile fine but throws out an error when it gets used.

My second problem, once I can understand how to use this object that the web browser is using, or have to activate it into my own object, I need to be able to use the SaveAs(), I just can''t save it because I''m unsure of what object is being used.


I appreciate any help, I haven''t programmed in over a year so please bare with me, I may not understand too much lingo but I have no problems looking what you might have to say up to better understand it :) PS I''m using Office 2007 and running Windows 7
Sorry for the long post, hope I didn''t leave anything out :cool:

~Nick

Here''s my source code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Reflection;
using Microsoft.Office.Core;
using Microsoft.Office.Interop.Excel;
using Excel = Microsoft.Office.Interop.Excel;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;


namespace TestIntegratedExcel
{
    public partial class Form1 : Form
    {
        private Object oDocument;
        // Contains a reference to the hosting application
        String strFileName;
        CSV_DAT csv_dat = new CSV_DAT("TestFile");

        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)
        {

            //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)
        {
            openButton.Text = "Browse";
            openFileDialog1.Filter = "Office Documents(*.xls, *.xlsx, *.csv)|*.xls;*.xlsx;*.csv";
            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);
        }
        private void clearButton_Click(object sender, EventArgs e)
        {
            axWebBrowser1.Navigate("about:blank");
            strFileName = null;
        }

推荐答案

尼克,

很高兴看到您的问题.那是一个有时甚至困扰我的问题.

好吧,您要问的内容需要花一些时间来研究代码.但是目前,请结帐
本文 [ ^ ]供参考.

祝你好运:thumbsup:
Hi Nick,

Good to see your question. Thats kind of a question that even bothered me sometimes.

Well what you are asking needs some time of research with the code. But for now please checkout this article[^] for reference.

Good luck :thumbsup:


这篇关于Web浏览器中使用的Excel对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆