I am working with ClosedXML utility for excel operations. It only supports files created on office versions 2007 on-words. I have an xls file and required to convert to xlms(macro enabled). Simple copy as shown below is not working.
string oldFile = @"C:\Files\xls.xls";
string newFile = @"C:\Files\xlsnew.xlsm";
File.Copy(xls_file,xlsm_file);
And I have used below code also
byte[] byteArray = File.ReadAllBytes(oldFile);
using (MemoryStream stream = new MemoryStream())
{
stream.Write(byteArray, 0, (int)byteArray.Length);
using (SpreadsheetDocument spreadsheetDoc = SpreadsheetDocument.Open(stream, true))
{
// Change from template type to workbook type
spreadsheetDoc.ChangeDocumentType(SpreadsheetDocumentType.MacroEnabledWorkbook);
}
File.WriteAllBytes(newFile, stream.ToArray());
}
Please provide a helpful solution.
Thanks in advance.