Excel.Application xApp = new Excel.ApplicationClass();
Excel.Workbook xBook=xApp.Workbooks._Open(src,
Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value
,Missing.Value,Missing.Value,Missing.Value,Missing.Value);
Excel.Worksheet xSheet1=(Excel.Worksheet)xBook.Sheets[1]; //这里是第一个页面
Excel.Worksheet xSheet2=(Excel.Worksheet)xBook.Sheets[2]; //这里是第二个页面
System.IO.DirectoryInfo DirInfo = new DirectoryInfo(src);
DirInfo.Attributes = FileAttributes.Normal & FileAttributes.Directory;
xSheet1.SaveAs(@"D:\CData1.xls", //保存第一个页面
Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,xBook.Sheets[1],Missing.Value,Missing.Value);
xSheet2.SaveAs(@"D:\CData2.xls", //保存第二个页面
Missing.Value,Missing.Value,Missing.Value,Missing.Value,
Missing.Value,Missing.Value,xBook.Sheets[2],Missing.Value,Missing.Value);
xBook.Close(null,null,null);
xApp.Workbooks.Close();
xApp.Quit();
if(xSheet1 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSheet1);
xSheet1 = null;
}
if(xSheet2 != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xSheet2);
xSheet2 = null;
}
if(xBook != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xBook);
xBook = null;
}
if(xApp != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(xApp);
xApp = null;
}
GC.Collect();
2 个解决方案
#1
用farpoint每三方控件
#2
刚才调试了一下,的确是这样,不过只要删除不需要的页面再保存就可以实现你的目的了。
#1
用farpoint每三方控件
#2
刚才调试了一下,的确是这样,不过只要删除不需要的页面再保存就可以实现你的目的了。