c-sharp
Conversion from XLSB to XLSX using microsoft interop
if (!File.Exists(strPath + filename.ToUpper().Replace("XLSB", "xlsx")))
{
try
{
Application excelApplication = new Application();
Workbooks workbooks = excelApplication.Workbooks;
// open book in any format
Workbook workbook = workbooks.Open(strPath + filename, XlUpdateLinks.xlUpdateLinksNever, true, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
// save in XlFileFormat.xlExcel12 format which is XLSB
workbook.SaveAs(strPath + filename.Substring(0, filename.Length - 4) + "xlsx", XlFileFormat.xlOpenXMLWorkbook, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
// close workbook
workbook.Close(false, Type.Missing, Type.Missing);
// ...
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication);
// shutdown excel
//excelApplication.Quit();
}
catch (Exception ex)
{
ClientSumDesc = "Load Failed, XLSB File Conversion" + ex;
return true;
}
finally
{
foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName("EXCEL"))
{
proc.Kill();
}
}
}
Used in springtel,
it uses library Microsoft interop
Was this helpful?
Similar Posts