Fill SERFF template XLSM File using C# EPPLUS library?

How to fill the SERFF template containing MACROS using EPPLUS Library. When i tried to edit template using this code the SERFF template crashes here is code i am using for editing and exporting template we can get SERFF template from here http://www.serff.com/plan_management_data_templates.htm

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"); 

Answers


This worked for me.

  1. Create xlsm template with macros saved
  2. Make a copy of it
  3. Fill the copy with required data
  4. Execute the macros after filling the data in copied 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();
    

    }


Need Your Help

Errors with structure in C (VS12)

function struct declaration binary-search-tree

I'm making a Binary Search Tree, this is my code for the structure:

pressing home button and access app again from app icon call onCreate?

android android-activity

I have an offline-online application, i found a strange issue in it, may be it is not, but i did'nt understand about it..