110,535
社区成员
发帖
与我相关
我的任务
分享
private string XmlChangeXls(string filename)
{
object missing = System.Reflection.Missing.Value;
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
excel.Visible = false;
Microsoft.Office.Interop.Excel.Workbooks oBooks = excel.Workbooks;
oBooks.Open(filename, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
Microsoft.Office.Interop.Excel.Workbook oBook = excel.ActiveWorkbook;
string newfilename = filename.Substring(0, filename.LastIndexOf('.')) + "-B.xls";
oBook.SaveAs(newfilename, XlFileFormat.xlExcel9795, missing, missing, missing, missing, XlSaveAsAccessMode.xlNoChange, missing, missing, missing, missing, missing);
excel.DisplayAlerts = false;
oBook.Close(false, missing, false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBook);
oBook = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(oBooks);
oBooks = null;
excel.Quit();
System.Runtime.InteropServices.Marshal.ReleaseComObject(excel);
excel = null;
System.GC.Collect();
return newfilename;
}