pirooz
Member
طريقه اتصال صفحات ASP به فايل اكسل (Excel):
1. يك صفحه گسترده در اكسل با نام ASPTOC.xls ايجاد كنيد و آن را در شاخه \c:\inetpub\wwwroot ذخيره نماييد.
توجه: هنگامي كه صفحه گسترده را ايجاد ميكنيد، هيچ فرمت خاصي از برچسبهاي ستون را وارد نكنيد.
2. رديفها و ستونهاي را كه ميخواهيد در صفحه وب شما نمايش داده شود، انتخاب كنيد.
3. در منوي Insert ، گزينه Name را انتخاب كنيد و سپس Define را انتخاب نماييد.
4. اگر در اينجا اسامياي فهرست شده بود، آنها را انتخاب كنيد و گزينه Delete را انتخاب نماييد.
5. يك نام براي منطقه انتخاب شده تعيين كنيد (مثلاً CellsToDisplay)، گزينه Add و سپس كليد OK را فشار دهيد.
در زير، كدهاي ASP براي نمايش محتويات فايل Excel در صفحه وب نمايش داده شده است:
1. يك صفحه گسترده در اكسل با نام ASPTOC.xls ايجاد كنيد و آن را در شاخه \c:\inetpub\wwwroot ذخيره نماييد.
توجه: هنگامي كه صفحه گسترده را ايجاد ميكنيد، هيچ فرمت خاصي از برچسبهاي ستون را وارد نكنيد.
2. رديفها و ستونهاي را كه ميخواهيد در صفحه وب شما نمايش داده شود، انتخاب كنيد.
3. در منوي Insert ، گزينه Name را انتخاب كنيد و سپس Define را انتخاب نماييد.
4. اگر در اينجا اسامياي فهرست شده بود، آنها را انتخاب كنيد و گزينه Delete را انتخاب نماييد.
5. يك نام براي منطقه انتخاب شده تعيين كنيد (مثلاً CellsToDisplay)، گزينه Add و سپس كليد OK را فشار دهيد.
در زير، كدهاي ASP براي نمايش محتويات فايل Excel در صفحه وب نمايش داده شده است:
کد:
<%
'Ensure that this page is not cached.
Response.Expires = 0
'Creates an instance of an Active Server Component
Set oConn = Server.CreateObject("ADODB.Connection")
'Connects to the Excel driver and the Excel spreadsheet
'in the directory where the spreadsheet was saved
strConn = "Driver={Microsoft Excel Driver (*.xls)}; DBQ=c:\inetpub\wwwroot\ASPTOC.xls;"
'Opens the connection to the data store
oConn.Open strConn
'Selects the records from the Excel spreadsheet
'CellsToDisplay is the name that was defined in the Excel worksheet
strCmd = "SELECT * from CellsToDisplay"
Set oRS = Server.CreateObject("ADODB.Recordset")
'Opens the recordset
oRS.Open strCmd, oConn
'Prints the cells and rows in the table
Response.Write ("<table border=1><tr><td>")
'Gets records in spreadsheet as a string and prints them in the table
Response.Write oRS.GetString (, 10, "</tr><td>", "</td></tr><tr><td>", NBSPACE)
%>