How to convert xlsb file to xlsx

Sudip Bhatt 2,271 Reputation points
2020-12-28T16:58:38.867+00:00

Please guide me how could i convert xlsb file to xlsx?

i used this code but did not worked.

private string ConvertXlsbToXlsx(string filepath)
        {
            string strfile = "";
            Excel.Application excelApplication = new Excel.Application();

            try
            {
                Excel.Workbook workbook = excelApplication.Workbooks.Open(filepath);
                workbook.SaveAs(filepath.Replace(".xlsb",".xlsx"), XlFileFormat.xlExcel12, Type.Missing, Type.Missing, Type.Missing, Type.Missing, XlSaveAsAccessMode.xlExclusive, 
                    Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                workbook.Close(false, Type.Missing, Type.Missing);
                workbook = null;
            }
            catch(Exception ex)
            {
                Logger.Write("Erro from excel convertion " + ex.Message, Logger.MsgType.Error);
            }
            finally
            {
                excelApplication.Quit();
                excelApplication = null;
            }
            return strfile;
        }

please help me with sample code. thanks

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,827 questions
{count} vote

Accepted answer
  1. Sudip Bhatt 2,271 Reputation points
    2020-12-28T17:37:54.793+00:00

    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;
    
            }
    
    0 comments No comments

0 additional answers

Sort by: Most helpful