Convert Xlsm to Xlsx

Mar 11, 2014 at 3:37 PM
Edited Mar 11, 2014 at 3:37 PM
Is there a way to convert a Xlsm file to Xlsx file using the library?

I'm writing a program in C# and I really need the CloneSheet() function, which I notice does not work with Xlsm but will work with Xlsx.

I try this code but it doesn't work.
XSSFWorkbook workbook;

//read original xlsm file into workbook
using (FileStream file = new FileStream(@"OriginalFile\" + filename, FileMode.Open, FileAccess.Read))
{ workbook = new XSSFWorkbook(file); }

//change file extension to xlsx and save in a new location
filename = Path.ChangeExtension(filename, "xlsx");
if (!Directory.Exists("NewFile"))
    Directory.CreateDirectory("NewFile");
FileStream stream = new FileStream(("NewFile\\New" + filename), FileMode.Create, System.IO.FileAccess.Write);
workbook.Write(stream);
stream.Close();

//read the newly created file from the new location
using (FileStream file = new FileStream(@"NewFile\\New" + filename, FileMode.Open, FileAccess.Read))
{ workbook = new XSSFWorkbook(file); }
The code creates a xlsx file, but the file cannot be open and seems to be corrupted.
Coordinator
Apr 12, 2014 at 10:35 PM
There is no plan to support xlsm because xlsm is for macro. NPOI has no support on Macro/VBA.
Marked as answer by tonyqus on 4/12/2014 at 2:35 PM