1,931 questions
I got the below code after searching google and it can convert XLSB to XLSX extension. here i am sharing. if anyone see any problem in code then please make me aware. thanks
private void Form1_Load(object sender, EventArgs e)
{
string strPath = @"D:\test\PJ_CVX.xlsb";
ConvertFromXLSBToXLSX(strPath);
}
private string ConvertFromXLSBToXLSX(string filepath)
{
string strNewPath = "";
if (!File.Exists(filepath.Replace("xlsb","xlsx")))
{
try
{
Excel.Application excelApplication = new Excel.Application();
Workbooks workbooks = excelApplication.Workbooks;
// open book in any format
Workbook workbook = workbooks.Open(filepath, 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(filepath.Replace("xlsb", "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);
excelApplication.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workbooks);
System.Runtime.InteropServices.Marshal.ReleaseComObject(excelApplication);
strNewPath = filepath.Replace("xlsb", "xlsx");
}
catch (Exception ex)
{
}
finally
{
//foreach (System.Diagnostics.Process proc in System.Diagnostics.Process.GetProcessesByName("EXCEL"))
//{
// proc.Kill();
//}
}
}
else
{
strNewPath = filepath.Replace("xlsb", "xlsx");
}
return strNewPath;
}