数据从EXCEL导入到DATAGRIDVIEW
锐宝宝 2009-11-12 10:12:34 OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
string Path = ofd.FileName;
object missing = System.Reflection.Missing.Value;
Excel.Application app = new Excel.ApplicationClass();
Excel.Workbook book = (Excel.Workbook)app.Workbooks.Open(Path, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing, missing);
MessageBox.Show( book.Sheets[1].ToString());
Excel.Worksheet sheets = (Excel.Worksheet)book.Sheets["AD"];
string mmm = Convert.ToString(sheets.Cells[1,1]);
DataGridView dgv = dataGridView1;
for (int i = 0; i < 10; i++)
{
for (int j = 0; j <10; j++)
{
dgv.Rows.Add();
if (sheets.Cells[i + 1, j + 1].ToString() != null)
{
dgv[j, i].Value = sheets.Cells[i + 1, j + 1].ToString();
}
else
{
dgv[j, i].Value = "";
}
}
}
}
导入全是System._Comobject,