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.
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.