如何使用EPPLUS Library填充包含MACROS的SERFF模板。 当我尝试使用此代码编辑模板时,SERFF模板崩溃 这里是我用于编辑和导出模板的代码,我们可以从http://www.serff.com/plan_management_data_templates.htm
获取SERFF模板FileInfo newFile = new FileInfo(@"D:\FFM Sharred\SERFF-PlansBenefits.xlsm");
ExcelPackage pck = new ExcelPackage(newFile);
var ws = pck.Workbook.Worksheets.First();
ws.SetValue("B2", "33333");
Response.BinaryWrite(pck.GetAsByteArray());
Response.ContentType = "application/vnd.ms-excel.sheet.macroEnabled.12";
Response.AddHeader("content-disposition", "attachment; filename=Sample4.xlsm");
答案 0 :(得分:1)
这对我有用。
在复制的Excel中填写数据后执行宏。
FileInfo templateFile = new FileInfo(@"D:\DOTNET\navigatetest.xlsm");
FileInfo newFile = new FileInfo(@"D:\DOTNET\navigatetest11.xlsm");
if (newFile.Exists)
{
newFile.Delete();
newFile = new FileInfo(@"D:\DOTNET\navigatetest11.xlsm");
}
using (ExcelPackage package = new ExcelPackage(newFile, templateFile))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets[1];
String ConnectionString = "SERVER=localhost;DATABASE=excelmaps;UID=root;PASSWORD=;";
MySqlConnection connection = new MySqlConnection(ConnectionString);
connection.Open();
MySqlCommand cmd = new MySqlCommand("Select * FROM `sheet1`", connection);
MySqlDataReader reader = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(reader);
DataRow row1 = dt.NewRow();
worksheet.Cells["A1"].LoadFromDataTable(dt, true);
package.Save();
}