آموزش: طريقه اتصال صفحات ASP به فايل اكسل (Excel):

pirooz

Member
طريقه اتصال صفحات 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)
  %>
 

pirooz

Member
حيفه ها! از دستتون ميره
برين امتحان كنين
من فكر مي‌كنم با قدرت محاسبه‌اي كه اكسل داره، استفاده از اين اتصال به فايل اكسل، بعضي جاها خيلي به درد بخوره.
موفق باشيد.
 

rahincom

Member
سلام

آقا دست شما درد نكنه.
به درد من كه خيلي مي خوره
باز هم مرسي

باي
 

جدیدترین ارسال ها

بالا