我有一个在"Office 2003"中创建的Excel模板,话虽如此,我需要以编程方式从这个现有模板创建一个新工作簿。此外,如果有任何会导致错误的事情,例如锁定的单元格,隐藏的公式,隐藏的工作表等,请提及。
一些可能有助于了解的事情
-
我已经从Office 2003 -> Office 2010升级,但是,文件格式是Excel 2007。
有超过 303 行和 26 列,每列都包含自己独特的公式( 仅在一张纸上(,总共可能有 700 多行和 100 列(在添加任何其他工作表之前(,每列都包含自己相对独特的公式.##
某些单元格和工作表被锁定,以防止用户引起的错误或用户篡改单元格内公式。
这个模板将被几个人使用,他们都有自己的电脑。我不能保证文件将在每台用户计算机上的相同位置。
软件信息:
Visual Studio 2013办公室 2010办公室 2003
找到了解决方案!
在VS2013中,他们提供Excel 2007插件,在预定义的互操作性中,有一种方法可以从模板创建文件,让我失望的部分是参数的一部分,它显示:
"类型缺失"。此代码结构的示例如下所示:
//the #region is simply so that if copied and pasted, the code will make sense, and there will be a label encapsulating the specific code lines. *Note it does not affect the results
#region add workbook from template file
Excel.Application f;
//the following line is written assuming that you would have already made sure that excel was in the Running Objects Table (ROT)
f=(Excel.Application)Marshal.GetActiveObject("Excel.Application");
f.visible=true;
f.Workbooks.Add("C:\...");
if there are any questions please comment, I will do my best to explain my own answer
#endregion
您需要检查 EPPlus http://epplus.codeplex.com
EPPlus 是一个 .net 库,它使用 Open Office Xml 格式 (xlsx( 读取和写入 Excel 2007/2010 文件。