Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A tutorial on how to upload and read Excel File data in ASP.NET

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "ASP.NET upload and read Excel file data method tutorial," interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's take you to learn "ASP.NET upload and read Excel file data method tutorial" bar!

In CSDN, people often ask how to open Excel database files. This article through a simple example, realize reading Excel data file.

First, create a Web application project and add a DataGrid control, a file control, and a button control to the Web page.

The copy code is as follows:

First import the OleDb namespace in Code View:

using System.Data.OleDb;

Enter the following code in the button click event:

The copy code is as follows:

string strPath="c://test//" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls";

File1.PostedFile.SaveAs(strPath);

string mystring="Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source = '"+ strPath +"';Extended Properties=Excel 8.0";

OleDbConnection cnnxls = new OleDbConnection (mystring);

OleDbDataAdapter myDa =new OleDbDataAdapter("select * from [Sheet1$]",cnnxls);

DataSet myDs =new DataSet();

myDa.Fill(myDs);

DataGrid1.DataSource=myDs.Tables[0];

DataGrid1.DataBind();

C:/test must have read and write permissions for ASPNET users.

At this point, I believe that everyone on the "ASP.NET upload and read Excel file data method tutorial" has a deeper understanding, may wish to actually operate it! Here is the website, more related content can enter the relevant channels for inquiry, pay attention to us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report