創(chuàng)新互聯(lián)專注于企業(yè)網(wǎng)絡營銷推廣、網(wǎng)站重做改版、中衛(wèi)網(wǎng)站定制設計、自適應品牌網(wǎng)站建設、H5頁面制作、商城網(wǎng)站建設、集團公司官網(wǎng)建設、外貿網(wǎng)站制作、高端網(wǎng)站制作、響應式網(wǎng)頁設計等建站業(yè)務,價格優(yōu)惠性價比高,為中衛(wèi)等各大城市提供網(wǎng)站開發(fā)制作服務。>using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data; using System.Data.OleDb; namespace WindowsFormsApplication7 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public static DataSet GetExcelData(string str) { string strCon = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + str + ";Extended Properties='Excel 12.0;HDR=YES;IMEX=1;'"; OleDbConnection myConn = new OleDbConnection(strCon); string strCom = " SELECT * FROM [Sheet1$]"; myConn.Open(); OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn); DataSet myDataSet = new DataSet(); myCommand.Fill(myDataSet, "[Sheet1$]"); myConn.Close(); return myDataSet; } private void button1_Click(object sender, EventArgs e) { OpenFileDialog filedialog = new OpenFileDialog(); string FileName = ""; if (filedialog.ShowDialog() == DialogResult.OK) { FileName = filedialog.FileName; dGViewExcel.DataSource = GetExcelData(FileName); dGViewExcel.DataMember = "[Sheet1$]"; for (int count = 0; (count <= (dGViewExcel.Rows.Count - 1)); count++) { dGViewExcel.Rows[count].HeaderCell.Value = (count + 1).ToString(); } } } } }
網(wǎng)站欄目:C#讀取excel文件到DATAVIEW-創(chuàng)新互聯(lián)
網(wǎng)頁鏈接:http://jinyejixie.com/article28/ccsjjp.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供用戶體驗、ChatGPT、小程序開發(fā)、網(wǎng)站營銷、Google、自適應網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經(jīng)允許不得轉載,或轉載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內容