C# 导出Excel文件 所导出文件打开时提示“Excel文件格式与扩展名指定格式不一致”

                Microsoft.Office.Interop.Excel.Application xlApp = new Microsoft.Office.Interop.Excel.Application();
                if (xlApp == null)
                {
                    return false;
                }
                int FormatNum;//保存excel文件的格式
                string Version;//excel版本号
                Version = xlApp.Version;//获取你使用的excel 的版本号
                if (Convert.ToDouble(Version) < 12)//You use Excel 97-2003
                {
                    FormatNum = -4143;
                }
                else//you use excel 2007 or later
                {
                    FormatNum = 56;
                }

  

 workbook.SaveAs(filepath, FormatNum);

  

原文地址:https://www.cnblogs.com/dyfisgod/p/8072910.html