Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,921 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
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
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;
}