如何使用新的CodeModule从模板复制ExcelWorkSheet [英] how to copy ExcelWorkSheet from template with new CodeModule
问题描述
我在复制 ExcelWorkSheet
和复制的工作表的相应 CodeModule
时遇到问题。让我解释一下:
I am having an issue with copying a ExcelWorkSheet
and the corresponding CodeModule
of the copied sheet. Let me explain:
场景:
我有一个带有宏(.xlsm)的excel文件,我将此excel文件用作模板来创建另一个excel文件(数据将被复制到新文件中。)
Scenario: I have an excel file with macro's (.xlsm) and I use this excel file as a template to create an other excel file (data will be copied into the new file).
因此,首先我从数据库中获取一些数据并打开excel模板( .xlsm
)文件。
So, first I fetch some data from a database and open the excel template (.xlsm
) file.
在某些情况下,某些条目需要位于不同的工作表中,在这里
At a certain point, some entries need to be in different worksheets, this is where the 'WorkSheets.Add()' comes in.
var newSheet = workbook.Worksheets.Add("someName", templateSheet);
复制模板工作表(包含我也要复制的 VBA代码)后,我遇到了问题。
After copying the template sheet (which contains 'VBA' code that I want to duplicate as well), I am experiencing problems.
似乎新创建的工作表的 CodeModule与模板中的名称和引用相同。
It seems that the 'CodeModule' of the newly created sheet equals the one from the template by name AND by reference.
所有属性值都相同,并且: workbook.VbaProject.Modules
仅包含模板文件的初始代码模块,而不包含新的 newSheet
。
That is; all the property values are the same and: workbook.VbaProject.Modules
contains only the initial code modules of the template file and not a new one for the new newSheet
.
更糟糕的是,如果我想绑定新的 CodeModule
Even worse, if I want to bind a new CodeModule
like this:
workbook.VbaProject.Modules.AddModule("test");
newSheet.CodeModule.Name = "test";
newSheet.CodeModule
和 templateSheet.CodeModule
设置为 null
(实际上 Nothing
我正在使用VB.Net。)
both the newSheet.CodeModule
and templateSheet.CodeModule
are set to null
(well Nothing
actually, since I am using VB.Net).
所以问题是:这是一个错误还是我在这里做错了?甚至更好:您可以指导完成此方案的方法吗?
So the question: is this a bug or am I doing something wrong here? And even better: can you guide the way to accomplish this scenario?
推荐答案
这似乎是一个错误。我在 epplus
项目的发布中心中创建了一个问题。它已标记为已解决
It seems to be a bug. I have created an issue in the issue center of the epplus
project. It has been marked as resolved
https://epplus.codeplex.com/workitem/15095
我尚未测试新版本。完成后,我将提供更新。
I haven't tested the new version yet. I'll give an update when that's done.
更新
在最新资源中,此问题已得到解决。
Update In the latest sources this issue is resolved.
这篇关于如何使用新的CodeModule从模板复制ExcelWorkSheet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!