Excel文件未保存在asp中 [英] Excel file not saving in asp
本文介绍了Excel文件未保存在asp中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
我正在从记录集中读取数据,并将其写入Excel文件中.问题是,当我尝试使用SaveAs方法保存工作簿时,不会保存文件,并且asp页会挂起,直到生成超时为止.代码如下所示:
Hi
I am reading data from a recordset and writing it into an excel file. The problem is when i try to save the workbook using the SaveAs method the file is not saved and the asp page hangs until it generates a timeout . The code is shown below:
Set SURVEY_APP_CONNECTION = Server.CreateObject("ADODB.Connection")
SURVEY_APP_CONNECTION= "DBQ=C:\Development\Websites\surveys.sawebdesign\db\SelectSurveyASPAdvanced.mdb;Driver={Microsoft Access Driver (*.mdb)};"
Set rsExport = Server.CreateObject("ADODB.Recordset")
dim strSQL
Set xl = CreateObject("Excel.Application")
''Set xlBk = xl.Workbooks.Add("C:\\template.xlsx")
xl.Visible=True
Set xlBk = xl.Workbooks.Add
stop
strSQL = "SELECT sur_response.response_id As ResponseID ,sur_item.item_alias As ItemAlias," & _
"sur_item.item_text As ItemText, sur_response_answer.other_text, sur_item.other_text As ItemOtherText," & _
"other_yn, sur_response_answer.answer_text As ResponseAnswerText, " & _
"sur_item_answer.answer_text As ItemAnswerText, subitem_text " & _
"FROM (((((sur_survey INNER JOIN sur_survey_to_item_mapping ON " & _
"sur_survey.survey_id = sur_survey_to_item_mapping.survey_id)" & _
" INNER JOIN sur_item ON sur_survey_to_item_mapping.item_id = sur_item.item_id)" & _
" INNER JOIN ((sur_response INNER JOIN sur_response_answer ON " & _
"sur_response.response_id = sur_response_answer.response_id)" & _
" LEFT JOIN sur_user ON sur_response.username = sur_user.username)" & _
" ON sur_item.item_id = sur_response_answer.item_id)" & _
" LEFT JOIN sur_item_answer ON sur_response_answer.answer_id = sur_item_answer.answer_id)" & _
" LEFT JOIN sur_subitem ON sur_response_answer.subitem_id = sur_subitem.subitem_id) " & _
" left JOIN sur_email_address ON sur_response.email_address_id = sur_email_address.email_address_id " & _
"WHERE sur_survey.survey_id = 154"
rsExport.activeconnection=SURVEY_APP_CONNECTION
rsExport.CursorType=2
rsExport.Locktype=3
rsExport.Open strSQL
If Not rsExport.EOF or rsExport.BOf Then
With xlbk.Worksheets(1)
For i = 4 To rsExport.Fields.Count - 1
.Cells(1, i +1) = rsExport.Fields(i).Name
Next
.Cells(i-2, 1).CopyFromRecordset rsExport
End With
dim filename
filename="C:\dump\template2.xlsx"
xl.Visible=True
'' xl.SaveWorkspace(filename)
xlBk.ActiveWorkbook.SaveAs filename
rsExport.close
xl.Quit
set xl= Nothing
set xlbk=nothing
set rsExport=nothing
stop
else
MsgBox "No Records"
end if
我已经更改了所有文件夹和文件的权限,以允许任何用户进行编辑,但仍然无法保存.请帮助
I have changed all the folder and file permissions to allow any user to edit but still its not saving . Please help
推荐答案
我必须添加以下行.
i had to add the the following line .
xl.ActiveWorkbook.Close savechanges=true
现在可以正常使用了
its now working
这篇关于Excel文件未保存在asp中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文