生成excel后加上
_Worksheet ActiveSheet;
//_Chart ActiveChart; _Workbook oBook; _Application oExcel = new ApplicationClass(); oExcel.Visible = false; oExcel.DisplayAlerts = false; oExcel.AutomationSecurity = Microsoft.Office.Core.MsoAutomationSecurity.msoAutomationSecurityLow; oExcel.AlertBeforeOverwriting = false; oExcel.AskToUpdateLinks = false;oBook = oExcel.Workbooks.Open(Server.MapPath(xlsUrl), Type.Missing, Type.Missing, Type.Missing, Type.Missing
, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing , Type.Missing, Type.Missing, Type.Missing);//这里会报一个错, 解决不了, 先这样应付一下吧.
System.Threading.Thread.Sleep(500); ActiveSheet = (_Worksheet)oBook.ActiveSheet; ActiveSheet.ListObjects.AddEx(XlListObjectSourceType.xlSrcRange, ActiveSheet.UsedRange, Type.Missing, XlYesNoGuess.xlYes , Type.Missing, "TableStyleMedium2"); oBook.Save(); oBook.Close(Type.Missing, Type.Missing, Type.Missing); //wb.Close(pnull, pnull, pnull); oExcel.Quit(); //Marshal.ReleaseComObject(ActiveSheet); //Marshal.ReleaseComObject(oBook); //Marshal.ReleaseComObject(oExcel);