Excel.Application ThisApp = new Excel.ApplicationClass();
Excel.Workbooks ThisWbs = ThisApp.Workbooks;
Excel.Workbook ThisWb = ThisWbs.Open("G:/demo.xls",Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
ThisWb.SaveAs("G:/HelloExcel.xml",Excel.XlFileFormat.xlXMLSpreadsheet,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Excel.XlSaveAsAccessMode.xlNoChange,Missing.Value,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
//Excel.XlFileFormat.xlXMLSpreadsheet控制存储文件的类型
System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisWb);
ThisWb = null;
ThisWbs.Close();
System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisWbs);
ThisWbs = null;
System.Runtime.InteropServices.Marshal.ReleaseComObject(ThisApp);
ThisApp = null;
GC.Collect();
博客展示了一段代码,通过创建Excel应用程序对象,打开指定的Excel文件,将其另存为XML格式文件,同时控制存储文件的类型。最后释放相关对象并进行垃圾回收,实现Excel文件的存储转换。
3457

被折叠的 条评论
为什么被折叠?



