Quantcast
Channel: npoi Discussions Rss Feed
Viewing all articles
Browse latest Browse all 637

New Post: Convert Xlsm to Xlsx

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

Viewing all articles
Browse latest Browse all 637

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>