100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > C#开发——winform中将Excel数据导入DataGridView

C#开发——winform中将Excel数据导入DataGridView

时间:2022-09-15 08:59:54

相关推荐

C#开发——winform中将Excel数据导入DataGridView

using System;using System.Data;using System.Data.OleDb;using System.Windows.Forms;namespace ExcelToGridview{public partial class Form1 : Form{public Form1(){InitializeComponent();}private void btnopenfile_Click(object sender, EventArgs e){try{//获取Excel文件路径和名称OpenFileDialog odXls = new OpenFileDialog();//指定相应的打开文档的目录 AppDomain.CurrentDomain.BaseDirectory定位到Debug目录,再根据实际情况进行目录调整string folderPath = AppDomain.CurrentDomain.BaseDirectory + @"databackup\";odXls.InitialDirectory = folderPath;// 设置文件格式 odXls.Filter = "Excel files office(*.xls)|*.xls|Excel office(*.xlsx)|*.xlsx|All files (*.*)|*.*";//openFileDialog1.Filter = "图片文件(*.jpg)|*.jpg|(*.JPEG)|*.jpeg|(*.P

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。