title: NPOI: Convert Xlsm to Xlsx
body: <p>I'm writing a program to process some excel documents, the program is written in C# in Visual Studio 2010, and I'm using the NPOI library.</p>
  
  <p>I notice the I was not able to use <code>CloneSheet()</code> for the <strong>xlsm</strong> file, but I was able to do so with xlsx.</p>
  
  <p><code>CloneSheet()</code> is a function that I really need for the process, so I really would like to get it working instead of copy everything cell by cell.</p>
  
  <p>I thought of converting the file to xlsx. I was able to do it manually, but not programmatically.</p>
  
  <p>This is the code I wrote to attempt to do so:</p>
  
  <pre><code>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); }
  </code></pre>
  
  <p>The above code will create the new xlsx file, but the file cannot be open and seems to be corrupted...</p>
  
  <p>I've been googling for a while and couldn't seem to find a solution, can anyone help or point me to the right direction?</p>
  
  <p>--EDIT---</p>
  
  <p>I tried a different method using Open XML I found <a href="https://stackoverflow.com/questions/11175343/convert-xlsm-to-xlsx">here</a>, but I have the same issue, where the file is created but I can't open the file.</p>
  
  <p>However, the file doesn't seem to be corrupted. My program that is reading the file have no problem reading the data, and when I try to open the file in excel it's saying "<em>The file is a macro-free file, but contains macro-enable content.</em>"</p>
  
  <p>Seems like I'm getting closer, but I need to be able to open the output file otherwise it's no use....</p>