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

C # reads excel files to DATAVIEW

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

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; 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)

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

Internet Technology

Wechat

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

12
Report