Fork me on GitHub

c# 将xml格式的Excel文件转换为标准的Excel

public static void ConvertExcel(string savePath)
{
//将xml文件转换为标准的Excel格式
Object Nothing = Missing.Value;//由于yongCOM组件很多值需要用Missing.Value代替
Excel.Application ExclApp = new Excel.ApplicationClass();// 初始化
Excel.Workbook ExclDoc = ExclApp.Workbooks.Open(savePath, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing, Nothing);//打开Excl工作薄
try
{
Object format = Excel.XlFileFormat.xlWorkbookNormal;//获取Excl 2007文件格式
ExclApp.DisplayAlerts = false;
ExclDoc.SaveAs(savePath, format, Nothing, Nothing, Nothing, Nothing, Excel.XlSaveAsAccessMode.xlExclusive, Nothing, Nothing, Nothing, Nothing, Nothing);//保存为Excl 2007格式
}
catch (Exception ex) { }
ExclDoc.Close(Nothing, Nothing, Nothing);
ExclApp.Quit();
posted @ 2012-03-22 23:32  逍遥メ风  阅读(4910)  评论(1编辑  收藏  举报