在Excel编程方式创建工作表添加在(C#) [英] Programmatically creating worksheets in an Excel Add In (C#)

查看:315
本文介绍了在Excel编程方式创建工作表添加在(C#)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据MSDN,可以编程方式创建和删除Excel工作表在Visual Studio( http://msdn.microsoft.com/en-us/library/6fczc37s.aspx )。在code这样做如下:

According to MSDN, one can programmatically create and delete Excel Worksheets in Visual Studio (http://msdn.microsoft.com/en-us/library/6fczc37s.aspx). The code to do so is as follows:

private void createNewAccount()
{            
    Excel.Worksheet newWorksheet;
    newWorksheet = Globals.ThisAddIn.Application.ThisWorkbook.Worksheets.Add();            
}

一个在我的项目形成具有携带这种code按钮。用户应该能够preSS它并创建一个新的工作表,但它不工作。所以,我决定把它功能区选项卡上的一个按钮,来代替。这也不起作用。我缺少什么?

One of the forms in my project has a button carrying this code. The user is supposed to be able to press it and create a new worksheet, but it doesn't work. So I decided to make it a button on a ribbon tab, instead. That didn't work either. What am I missing?

推荐答案

我的回答是不会太长。

如果你需要去微软的方式,请先务必先创建一本书。记住Excel文件类似于工作簿,那么,在里面,你可以创建的工作表

If you need to go Microsoft way, please first be sure to first create a Book. Remember Excel files resemble a workbook, then, inside, you can create worksheets.

如果你不请看看 NPOI项目

这两种方式,你必须创建工作簿,然后工作表中。

With both approaches you will have to create the workbook, then the worksheets inside.

更多关于此链接

好吧,如果你确信你有机会获得一个工作簿,我会建议你:

Well, If you are sure you have access to a WorkBook I would recommend you to:

1:使用的<一个参数href=\"http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.worksheets.add%28v=office.15%29.aspx\"相对=nofollow> WorkSheets.Add方法

2:请看看<一个href=\"http://stackoverflow.com/questions/14109102/how-do-i-add-a-worksheet-after-all-existing-excel-worksheets\">this例如。

3 .-坚持添加工作表后,工作簿。这将允许判断是否添加或不

3.- Persist the workbook after the worksheet is added. This will allow to check if it was added or not.

最后但并非最不重要的,调试,调试和调试。

Last but not least, debug, debug and debug.

希望帮助,

这篇关于在Excel编程方式创建工作表添加在(C#)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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