|
<HTML><BODY>
<%
Function ExcelTest( strUrl )
Dim strPath
Dim FileSystem
Dim ExcelSheet,Cur
Dim OraDatabase,SqlQuery,OraDynaset,Columns
Dim nIdx
' 物理パスを取得
strPath = Server.MapPath( strUrl )
' 無条件削除
Set FileSystem = Server.CreateObject( "Scripting.FileSystemObject" )
On Error Resume Next
FileSystem.DeleteFile strPath
On Error Goto 0
set ExcelSheet = Server.CreateObject( "Excel.Sheet" )
Set Cur = ExcelSheet.ActiveSheet
Set OraDatabase = OraSession.GetDatabaseFromPool(10)
SqlQuery = "select * from H1.MS04 where 商品コード >= 12"
Set OraDynaset = OraDatabase.CreateDynaset(SqlQuery,2)
Set Columns = OraDynaset.Fields
' シート名
Cur.Name = "商品"
' 列幅
Cur.Columns(1).ColumnWidth = 9
Cur.Columns(2).ColumnWidth = 31
Cur.Columns(3).ColumnWidth = 13
' タイトル
Cur.Cells(1,1).Value = "商品コード"
Cur.Cells(1,2).Value = "全角品名"
Cur.Cells(1,3).Value = "在庫評価単価"
nIdx = 2
Do while not OraDynaset.EOF
Cur.Cells(nIdx,1).Value = Columns( "商品コード" ).Value
Cur.Cells(nIdx,2).Value = Columns( "全角品名" ).Value
Cur.Cells(nIdx,3).Value = Columns( "在庫評価単価" ).Value
OraDynaset.MoveNext
nIdx = nIdx + 1
Loop
' 保存
ExcelSheet.SaveAs( strPath )
Set cn = Server.CreateObject("ADODB.Connection")
' strConnection = "Driver={Microsoft Excel Driver (*.xls)}; DBQ=" & strPath & ";"
strConnection = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strPath & ";" & _
"Extended Properties=""Excel 8.0;"""
cn.Open strConnection
Set rs = Server.CreateObject( "ADODB.Recordset" )
' 更新する為に必要
rs.LockType = 2
' "商品" はシート名
SqlQuery = "select * from [商品$]"
rs.Open SqlQuery, cn
Do while not rs.EOF
Response.Write rs.Fields( 0 ).Value
Response.Write "," & rs.Fields( 1 ).Value
Response.Write "," & rs.Fields( 2 ).Value & "<br>"
rs.MoveNext
Loop
' 先頭行に移動
rs.MoveFirst
rs.Fields( 0 ).Value = "99999"
rs.Fields( 1 ).Value = "TEST"
rs.Fields( 2 ).Value = "12345"
' 更新 (タイトルの次の行が更新される)
rs.Update
rs.Close
cn.Close
End Function
Call ExcelTest( "data/TEST.XLS" )
%>
</BODY></HTML>
| |