ASP读取Excel文件的数据,按ASP网页的格式显示和传回更新。这种方法我在CSDN上已有帖子欢迎浏览:)
下面是第2种方法的要点供您参考
dim xlApp,myWorkbook,strFileName,strAppPath,strFilePath,strFullPath
dim myWorksheet1,myWorksheet2,myWorksheet3,myWorksheet4,myWorksheet5,myWorksheet6
set xlApp = Server.CreateObject("Excel.Application")
xlApp.Visible = false
set myWorkbook = xlApp.Workbooks.Add
'创建多个工作表在一个Excel文件里
set myWorksheet1 = myWorkbook.Worksheets(1)
set myWorksheet2=myWorkbook.Worksheets(2)
set myWorksheet3=myWorkbook.Worksheets(3)
set myWorksheet4=myWorkbook.Worksheets.Add'(4)'extension
set myWorksheet5=myWorkbook.Worksheets.Add'(5)
set myWorksheet6=myWorkbook.Worksheets.Add'(6)
...
'更新/赋值
myWorksheet1.Cells(1,1).Value="表1第1行第1列的值",也可以写成
myWorksheet1.Range("A1").Value="表1第1行第1列的值"
myWorksheet1.Cells(1,2).Value="表1第1行第2列的值"
myWorksheet1.Range("B1").Value="表1第1行第2列的值"
myWorksheet1.Cells(2,1).Value="表1第2行第1列的值"
...
myWorksheet3.Cells(3,2).Value="表3第3行第2列的值"
...
'保存文件
strFileName = Session.SessionID & ".xls"
strAppPath = Request.ServerVariables("PATH_TRANSLATED")
strAppPath = Left(strAppPath, InstrRev(strAppPath, "\"))
strFullPath = strAppPath & strFileName
myWorkbook.SaveAs(strFullPath)
'关闭
myWorkbook.Close
xlApp.Quit
set myWorksheet = Nothing
set myWorkbook = Nothing
set myxlApp = Nothing
了解更多请访问:
http://www.ndfweb.cn/news-445.html