????? ????????? ???? ???????? ?? Excel ???????? ASP.NET ? ADO.NET Visual C# .NET

?????? ????????? ?????? ?????????
???? ???????: 306572 - ??? ???????? ???? ????? ????? ??? ???????.
????? ???? | ?? ????

?? ??? ??????

??????

???? ??? ??????? ???? ????? ??? ????? ??? ?????? ?? ???? ??? Excel ??? ???? ????? ASP.NET (.aspx) ???????? Visual C# .NET.


????? ????? ???? ??? Excel

  1. ??? ????? Microsoft Excel ?? ?? ?????? ???? ??? ?????.
  2. ????? ????????? ??????? ??? ???? ????? ?????? ????? ?????? Excel ?????:
    ?? ??? ??????????? ??? ??????
    Ab
    1????? ???????? ???????
    2????Bishop
    3????????????
    ??????: ????? ???????? "???? ?? ?????? A1 ?? ??? ?????? ????? ????? ??? ???????? ??? ?? ????? ??????? ??? ???? ?????.
  3. ????? ?????? ???????? ??? ???? ????????.
  4. ?? ??????? ????? ? ??? ??? ??? ? ?? ???? ??? ?????.
  5. ?? ???? ???? ??????? ?? ?????? ? ???? myRange1 ??? ?? ???? ??? ?????.
  6. ?? ??????? ???? ???? ??? ???. ?? ??????? ??? ?? ? ??? ??? ???? ??? (??? ????? C:\InetPub\Wwwroot\). ?? ???? ???? ??? ????? ? ???? ExcelData.xls. ???? ??? ?????.
  7. ?? ??????? ???? ???? ??? "?????".

????? ????? ASP.NET ??????? Visual C# .NET

???? ????? ????????? ???????? ??? ????? ????????? ???? ????????? ?? ???? ??? Excel. ?????? ???????? ???????? ??????? ???? ????? ???? ??? ???????? ?? ?????? ??????.
  1. ???? Microsoft Visual Studio .NET. ??? ??? ?? Visual Studio .NET Integrated ????? ???? (IDE).
  2. ?? ??????? ???? ??? ??? ???? ?? ???? ??? ???????.
  3. ?? ???? ?????? ????? ???? ??? ????? Project ? ???? ??? Visual C# ????????. ??? ????? ? ???? ??? ????? ??? ASP.NET.
  4. ?? ???? ?????? "????? ????" ? ??? ???? ?????? ???? ????? ???????. ???? ?? ???? ???? ????? ??? ????? (???? ????? ?????? ?? ???? ????). ???? ?? ?????? ????? ??? ???? ?????? (?? ??????):
    http://localhost/WebApplication1
    ??????? ???? ??????? ?? ???? ???? ??????http://localhost/ExcelCSTest ?? ???? ??? ?????. ??? ????? ????? ???? ???? ????? "????? ???" ???? WebForm1.aspx.
  5. ?? IDE .NET Visual Studio ? ??? ???? ???? "?????? ??????". ??? ?? ???? ????, ???? ??? ?????? ?????? ?? ??????? ???.
  6. ?? "?????? ??????" ???? ??? ?????? ?????? ??? WebForm1.aspx ??? ?? ???? ??? ??? ???? ???? ???? ???? ??????. ?????? ???? ?? ?????? ????? ???? ???? ?????? ?????????.
  7. ??? ???? ???? ???????. ???????? ??? ??????? ???? IDE ???? ?? ???? ???? ??????? ??? ???? ?? ?? (???? ?????? ?? ???? ??? ?????? ?????? ?? IDE). ??? ?? ????? ?? ?????? ??? ???? ??????? ???? ??? ???? ??????? ?? ??????? ???.

    ??? ??? ???? ??????? ??? ? ??? ?????? ??? ???? ???? ??? ??? ??????? ???? ???????.
  8. ??? ????? ??? ?????? "????? ???" ????? ???? ??????? ??? ?????? ??? ?? ??? ????? ??? ???????? HTML ???????? ??????. ???? ??? ?????? "????? ???".
  9. ?? ?????? "????? ???" ?? ???? ??????? ???? ??? DataGrid ?? ?? ????? ??? ???? WebForm1.
  10. ???? ??? ?????? ?????? ??? WebForm1.aspx ??? ?? ???? ??? ??? ????????? ???????? ??? ??? ???? ?????? ??????? ????????? ????????.
  11. ?? ?????? ???????? ??????? ??? ???? ????????? ???????? - ??? ?????? ???? ?????? ????? ?????:
    using System.Data.OleDb;
    using System.Data;
    					
  12. ????? ???????? ???????? ??????? ???? ??? ?????? ?????? ??? ????? ??? ?? ???? ??? ???. ?? WebForm1.aspx.cs ? ?? ???? ???????? ???????? ?? ????? Page_Load:
    // Create connection string variable. Modify the "Data Source"
    // parameter as appropriate for your environment.
    String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
    	"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
    	"Extended Properties=Excel 8.0;";
    
    // Create connection object by using the preceding connection string.
    OleDbConnection objConn = new OleDbConnection(sConnectionString);
    
    // Open connection with the database.
    objConn.Open();
    
    // The code to follow uses a SQL SELECT command to display the data from the worksheet.
    
    // Create new OleDbCommand to return data from worksheet.
    OleDbCommand objCmdSelect =new OleDbCommand("SELECT * FROM myRange1", objConn);
    
    // Create new OleDbDataAdapter that is used to build a DataSet
    // based on the preceding SQL SELECT statement.
    OleDbDataAdapter objAdapter1 = new OleDbDataAdapter();
    
    // Pass the Select command to the adapter.
    objAdapter1.SelectCommand = objCmdSelect;
    
    // Create new DataSet to hold information from the worksheet.
    DataSet objDataset1 = new DataSet();
    
    // Fill the DataSet with the information from the worksheet.
    objAdapter1.Fill(objDataset1, "XLData");
    
    // Bind data to DataGrid control.
    DataGrid1.DataSource = objDataset1.Tables[0].DefaultView;
    DataGrid1.DataBind();
    
    // Clean up objects.
    objConn.Close();
    					
  13. ?? ??????? ???? ???? ??? ??? ???? ???? ????? ???????.
  14. ?? ??????? ????? ? ???? ??? ????? ?????? ???????. ????? ??? ????????? ???????? ???????? ?? ???? ????????? ???????? ??????? ???? ???? ??????.
  15. ?? "?????? ??????" ???? ??? ?????? ?????? ??? WebForm1.aspx ??? ?? ???? ??? ??? ?? ?????? ?????? ????????? ????????.

????? ??? ??????

?????? ????? ????????? ???????? ?? ??? ??????? Microsoft ???? Jet OLE DB ?????? ??? ???? ??? Excel. ?????? ??? ????? ????? ??????? ??????? ??????? ???? ?????:
// Create connection string variable. Modify the "Data Source"
// parameter as appropriate for your environment.
String sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
	"Data Source=" + Server.MapPath("../ExcelData.xls") + ";" +
	"Extended Properties=Excel 8.0;";
				
??? ???? ??? ????????? ??? ????? ??????? ???? ????? ???? ??? Excel. ???????? ??? ???? ??? ???? ????? ????? ???? ??????? ??????? ??????? ??????? ????? ???? ????.

???? ?? ????? ??????? ?????? ?????? Server.MapPath. ????? ??? ?????? ???? ???? ??? Microsoft ????? ??????? ?????? (IIS) ??? ??? ???? ????? ???? ??? ?????? ??? ??? ?????. ??? ???? ??????? ???? ExcelData.xls ?? ?????? ????? ??? ???? ????? ?? C:\Inetpub\Wwwroot ?? ?????? Create Sample Excel Spreadsheet. ???? ??? ??? ????? ????? ???? ???? ???? ExcelCSTest ??? ?????? Wwwroot ? ??? ???? WebForm1.aspx ??? ?????? ExcelCSTest.

?? ??? ?????? ???? ????? ??? ????? ?????? ??? ???:
     C drive
        - Inetpub
            - Wwwroot (which contains ExcelData.xls)
                - ExcelCSTest (which contains WebForm1.aspx)
				
???? IIS ??????? ??? ???:
     Web Root (which contains ExcelData.xls)
        - ExcelCSTest (which contains WebForm1.aspx)
				
?? ??? ??????? ???? ???? ?? ?????? WebForm1.aspx ??? ??? ExcelData.xls "../ ExcelData.xls ". "../ "????? ?????? IIS ???????? ????? ???? ???? ?????. ?????
Server.MapPath("../ExcelData.xls")
				
????? ??????? ???????:
C:\Inetpub\Wwwroot\ExcelData.xls
??? ?????? ???????? Server.MapPath. ???? ????? ??? ???? ????????? ???????? ??? ????????? ??? ???? ????? ?? ????? ??????? ?? ????? ????? ???? ??? Excel ??? ????? ??????.

?????

?????? ??? ??????? ?????? ??? ????? ?????? ??? ????? Excel ?? ASP.NET? ???? ??? ???? ????????? ????????? ??????? ?? "????? ??????? ?? Microsoft:
307029HOWTO: ??? ?????? XML ??? Microsoft Excel 2002 ???????? Visual C# .NET
306023HOW TO: ??? ???????? ??? ???? Excel ???????? Visual C# .NET
?????? ??? ??????? ?????? ??? ??????? ADO.NET ???? ??? ???? ????????? ????????? ??????? ?? "????? ??????? ?? Microsoft:
306636HOW TO: ??????? ?????? ?????? ? ????? ????? ???????? ADO.NET ? Visual C# .NET
314145HOW TO: ????? ???? DataSet ?? ????? ?????? ???????? Visual C# .NET
307587HOW TO: ????? ????? ?????? ?? ???? DataSet ???????? Visual C# .NET
??????: ??????? ? ???????? ? ?????? ? ????? ?????? ? ?????? ?????? ?????????? ? ???????? ? ???????, ? ???????? ?????? ????? ??? ?????? ?????. ?? ????? ?? ???? ? ??????? ? ??????, ??? ?????? ? ????? ?????? ?????????? ? ???? ? ????? ?? ????? ?? ????? ?? ??? ??? ??????? ??? ?????? ?? ??? ?????.

???????

???? ???????: 306572 - ????? ??? ??????: 10/????/1425 - ??????: 4.5
????? ???
  • Microsoft Excel 2002 Standard Edition
  • Microsoft Excel 2000 Standard Edition
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
  • Microsoft Visual C# .NET 2003 Standard Edition
  • Microsoft Visual C# .NET 2002 Standard Edition
  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET (included with the .NET Framework)
????? ??????: 
kbmt kbdatabase kbhowtomaster kbwebforms KB306572 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????306572

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com