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 office2003(*.xls)|*.xls|Excel office2010(*.xlsx)|*.xlsx|All files (*.*)|*.*";
//openFileDialog1.Filter = "图片文件(*.jpg)|*.jpg|(*.JPEG)|*.jpeg|(*.PNG)|*.png";
odXls.FilterIndex = 2;
C#开发——winform中将Excel数据导入DataGridView
最新推荐文章于 2025-06-05 12:35:40 发布