Ankur Garg
Ankur Garg

Reputation: 23

EPPlus import file xlsm

I am trying to import an xlsm file using EPPlus. I found the link that said EPPlus doesn't support this : Convert XLSM to XLSX . It's very old so I wanted to know if it supports it now ? If not, is there any way to do this with EPPlus by converting to XLSX but the way should be independent on Microsoft updates and just dependent on libraries used at the time of building the program. My current code looks like this :

FileInfo file = new FileInfo(Path.Combine(Program.source_path, s));
   using (ExcelPackage package = new ExcelPackage(file))
   {
       ExcelWorksheet worksheet = package.Workbook.Worksheets[3];
       for (int row = 9; row <= worksheet.Dimension.End.Row; row++)
       {
       }
   }

Upvotes: 2

Views: 3487

Answers (1)

Yahya Hussein
Yahya Hussein

Reputation: 9101

This will copy all content from the source xlsm file to a target xlsx file.

      using (var target = new ExcelPackage(new System.IO.FileInfo("D:\\target.xlsx")))
        {
            using (var source = new ExcelPackage(new System.IO.FileInfo("D:\\source.xlsm")))
            {

                foreach (var worksheet in source.Workbook.Worksheets)
                {
                    target.Workbook.Worksheets.Add(worksheet.Name, worksheet);
                }
            }
            target.Save();
        }

Upvotes: 2

Related Questions