问题描述
在webservice中,可以实现导入数据集到excel中?我是这样实现的:[WebMethod]publicstringExportToExcel(DataSetds,stringxlFileName){System.Data.DataTabledt=ds.Tables[0];if(dt.Rows.Count==0)return"TheDataSetisnull";Applicationapp=newApplication();app.Application.Workbooks.Add(true);app.Cells[1,1]="aaa";//暂时代替数据集app.ActiveWorkbook.SaveAs(xlFileName,XlFileFormat.xlExcel12,null,null,false,false,XlSaveAsAccessMode.xlNoChange,null,null,null,null,null);app.Application.Workbooks.Close();app.Quit();app=null;returnxlFileName;}但是当在winform程序中调用这个webmethod的时候,当运行到app.ActiveWorkbook.SaveAs,报错timeout.也会出现这样的错误:TheCLRhasbeenunabletotransitionfromCOMcontext0x2294a0toCOMcontext0x229610for60seconds.Thethreadthatownsthedestinationcontext/apartmentismostlikelyeitherdoinganonpumpingwaitorprocessingaverylongrunningoperationwithoutpumpingWindowsmessages.Thissituationgenerallyhasanegativeperformanceimpactandmayevenleadtotheapplicationbecomingnonresponsiveormemoryusageaccumulatingcontinuallyovertime.Toavoidthisproblem,allsinglethreadedapartment(STA)threadsshouldusepumpingwaitprimitives(suchasCoWaitForMultipleHandles)androutinelypumpmessagesduringlongrunningoperations.哪位可以帮帮忙!先谢了!
解决方案
解决方案二:
应该不可以我去写份代码示例给你这就去了
解决方案三:
xlFileNameLZ把文件保存再哪了,客户端,服务器端?
解决方案四:
可以的,不过导入数据的execl必须在服务器上