如何显示/开/从WindowsForm项目启动ExcelWorkbook项目(工作表Sheet1)? [英] How to show/open/start ExcelWorkbook project(Sheet1) from WindowsForm project?

查看:583
本文介绍了如何显示/开/从WindowsForm项目启动ExcelWorkbook项目(工作表Sheet1)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所示,可以说,我有一个解决方案两个项目。我有三个,最后一个仅仅是一个例子。其中一个项目是 ExcelWorkbook 所谓的( EWB



< IMG SRC =http://i.stack.imgur.com/EDnk8.jpgALT =在这里输入的形象描述>



和另外一个是 WindowsForm 所谓的(核心)。我想显示/开/启动这个 EWB 核心。我已经添加引用第一个:





和我可以看到具体的工作簿的表。这不是那么容易,因为它是当你显示来自另一个项目的形式等。只是注意到, EWB.Sheet1 不包含一个构造函数 0 参数,它的构造函数有两个参数。 ..



下面是这些参数:




  • Microsoft.Office .Tools.Excel.Factory 工厂

  • 的IServiceProvider 的ServiceProvider



有关这个项目的表示如下:





我想打开按钮单击事件的工作簿,但我不知道如何为:




  • 启动

  • 显示它

  • 打开它

  • 或...



不知道如何可以这样做?任何帮助将不胜感激!



这怎么我打开从另一个项目的形式,和这是我想打开方式 EWB

 使用WindowsFormsApplication1; 

私人无效CoreBtn_Click(对象发件人,EventArgs五)
{
Form1中newForm =新Form1的();
newForm.Show();
}


解决方案

添加一个引用到的Microsoft.Office.Interop.Excel 使用Excel =的Microsoft.Office.Interop.Excel;



下面是一些简单的代码,让你开始:



<预类=郎-CS prettyprint-覆盖> Excel中。应用xlApp =新Excel.Application(); //创建新的Excel应用程序
xlApp.Visible = TRUE; //应用程序变为可见
xlApp.Workbooks.Open(@C:\workbook.xlsx); //从文件路径

xlApp.Quit打开工作簿(); //关闭应用程序时,你做

和获取更多信息的 Excel对象模型 这里。


As shown in title, lets say that I have two projects in one solution. I have three, the last one is just for an example. One project is ExcelWorkbook called (EWB)

and another one is WindowsForm called (Core). I would like to show/open/start this EWB from Core. I've added references to the first one:

and I can see sheets of that specific workbook. It's not so easy as it is like when you're showing form from another project. Just for note, EWB.Sheet1 does not contain a constructor that takes 0 arguments, its constructor has two argument, ...

Here are these arguments:

  • Microsoft.Office.Tools.Excel.Factory factory
  • IServiceProvider serviceProvider

For this project its says as following:

I would like to open that workbook on button click event but I don't know how to:

  • start it
  • show it
  • open it
  • or ...

Any idea how this could be done? Any help will be appreciated!

This how I open form from another project, and this is the way I would like to open that EWB.

using WindowsFormsApplication1;

private void CoreBtn_Click(object sender, EventArgs e)
        {
            Form1 newForm = new Form1();
            newForm.Show();
        }

解决方案

Add a reference to Microsoft.Office.Interop.Excel and using Excel = Microsoft.Office.Interop.Excel;

Here is some simple code to get you started:

Excel.Application xlApp = new Excel.Application();  // create new Excel application
xlApp.Visible = true;                               // application becomes visible
xlApp.Workbooks.Open(@"C:\workbook.xlsx");          // open the workbook from file path

xlApp.Quit();                                       // close the application when you are done

And for more information the Excel Object Model look here.

这篇关于如何显示/开/从WindowsForm项目启动ExcelWorkbook项目(工作表Sheet1)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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