如何使用Epplus库在Excel工作表中添加宏? [英] How to add macro in excel worksheet using Epplus library ?

查看:303
本文介绍了如何使用Epplus库在Excel工作表中添加宏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为countMacro的宏和一个名为countCell()的函数

我已在excel表中测试过它工作正常。

但我想要使用C#添加此函数/宏,在运行时我必须将宏添加到动态excel并运行宏,结果将显示在单元格上。

我正在使用Epplus库。

做回复。

谢谢。

I have one macro called "countMacro" and one function called "countCell()"
I have tested in excel sheet it works fine.
But i want to add this function/macro using C#, at run time i have to add macro to dynamic excel and macro will be run and result will be shown on cell.
I am using Epplus library.
do reply.
Thank you.

推荐答案



http://www.nullskull.com/articles/create_macro_at_runtime_in_dotnet.asp [ ^ ]

认为这会对你有所帮助。但在本文中,他们使用Interop.Microsoft.Office.Core.dll创建excel,因此使用此方法可以将宏添加到Excel中。

http://www.nullskull.com/articles/create_macro_at_runtime_in_dotnet.asp[^]
think this will help you. But in this article their are using Interop.Microsoft.Office.Core.dll to create excel so by using this you can add macro to excel.


ExcelPackage xlPack = new ExcelPackage(excelFile);	// Open or Create the File
// Add VBA Code
xlPack.Workbook.CreateVBAProject();			// Can not append VBA Projects.Multiple "Code" can be added. See "https://github.com/pruiz/EPPlus/blob/master/SampleApp/Sample15.cs".
xlPack.Workbook.CodeModule.Name = "Module1";
xlPack.Workbook.CodeModule.Code = "Sub countMacro()\r\n" +
" ... Place Code Here ... \r\n" +
"End Sub\r\n";


这篇关于如何使用Epplus库在Excel工作表中添加宏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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