尝试检查excel中的单元格值是否为空。 如果它是空的我想写一个关闭单元格的值(例如,A25是空的。我想要B25值)。 我想浏览整个excel文件。 这是我现在的代码,我卡住了! (滚动到代码的底部。最后一部分很重要。)
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnReadExcel_Click(object sender, EventArgs e)
{
OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + txtFileName.Text + ";Extended Properties=Excel 12.0");
OleDbDataAdapter da = new OleDbDataAdapter("select * from[Sheet1$]", con);
da.Fill(dsContacts);
MessageBox.Show(dsContacts.Tables[0].Rows.Count.ToString());
dgContacts.DataSource = dsContacts.Tables[0];
}
private void tblContactsBindingNavigatorSaveItem_Click(object sender, EventArgs e)
{
this.Validate();
this.tblContactsBindingSource.EndEdit();
this.tableAdapterManager.UpdateAll(this.database11DataSet);
}
private void Form1_Load(object sender, EventArgs e)
{
this.tblContactsTableAdapter.Fill(this.database11DataSet.tblContacts);
}
private void button1_Click(object sender, EventArgs e)
{
foreach (DataRow r in dsContacts.Tables[0].Rows)
{
DataRow dr = database11DataSet.tblContacts.NewRow();
dr[0] = r[0];
dr[1] = r[1];
dr[2] = r[2];
database11DataSet.tblContacts.Rows.Add(dr);
}
}
}
}