编写和Excel的执行VBA宏不使用Excel.Interop [英] Writing and Executing VBA Macros on Excel without using Excel.Interop

查看:208
本文介绍了编写和Excel的执行VBA宏不使用Excel.Interop的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

适用范围:

我生成使用Excel的自动报告,但因为我们有我们的服务器上的限制,我们无法安装 Excel.Interop 或使用任何 COM 对象执行此类行动。

I am generating automated reports using excel, but since we have restrictions on our server, we can't install Excel.Interop or use any COM object to perform such action.

我们一直在使用 EPPLUS 作为我们对这项任务的主要帮手,但它有一些严重的限制,当谈到更intricated的东西,如数据透视图

We have been using EPPLUS as our main helper on this task but it has some serious restrictions when it comes to more intricated things such as PivotCharts and Macros.

我们刚刚完成了这个项目,缺的只是在数据透视图自EPPLUS对他们没有支持。

We have just finished the project, missing only the PivotCharts since EPPLUS has no support for them.

问:

怎能:

A)编写宏到 .XLSM 文件? (我们可以写一个名为Auto_Open,以使Excel将运行它uppon开放,创造了图表和东西)

A) Write Macros to a .xlsm file? (We could write one named "Auto_Open" so that excel would run it uppon opening, creating the charts and stuff)

b)我们的代码中运行宏将所有需要的数据存在后,生成这些图表?

B) Run a macro within our code to generate those charts after putting all the needed data there?

不使用 Excel.Interop 是在这一刻必须的。我们是开放的一些建议,如
的SpreadsheetGear 并的 EasyXLS ,但我们无法找到真正展示了如何编写或运行宏任何样本或一段代码。

Not using Excel.Interop is a must at this moment. We are open for some suggestions such as SpreadsheetGear and EasyXLS, but we can't find any sample or piece of code that actually shows how to Write or Run macros.

在此先感谢

推荐答案

我意识到这个问题是有点老了,但在帮助未来游客的兴趣我要补充的是EPPlus的(4.0.4在写作的时间)的当前版本支持VBA的包容。

I realise this question is a bit old, but in the interest of helping future visitors I'll add that the current version of EPPlus (4.0.4 at time of writing) supports the inclusion of VBA.

其中, excelDoc ExcelPackage ,您可以使用的东西线沿线的拖放:

Where excelDoc is your ExcelPackage, you can drop it in using something along the lines of:

excelDoc.Workbook.CreateVBAProject();

StringBuilder vbaCode = new StringBuilder();

vbaCode.AppendLine("Private Sub Workbook_Open()");
vbaCode.AppendLine("    Application.DisplayFormulaBar = False");
vbaCode.AppendLine("End Sub");

excelDoc.Workbook.CodeModule.Code = vbaCode.ToString();



希望这有助于。

Hope this helps.

这篇关于编写和Excel的执行VBA宏不使用Excel.Interop的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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