#region 导入excel表格
private void btnToLead_Click(object sender, EventArgs e)
{
dgvLeadTo.Rows.Clear();
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.InitialDirectory = "d:\\";
openFileDialog.Filter = "All files(*.*)|*.*|All files(*.*)|*.*";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
if (!string.IsNullOrEmpty(openFileDialog.FileName))
{
// 打开文件
FileStream fileStream = new FileStream(openFileDialog.FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
// 读取文件的 byte[]
byte[] bytes = new byte[fileStream.Length];
fileStream.Read(bytes, 0, bytes.Length);
fileStream.Close();
// 把 byte[] 转换成 Stream
Stream stream = new MemoryStream(bytes);
System.Data.DataTable dt;
if (Path.GetExtension(openFileDialog.FileName) == ".xls") !!!!!
{
dt = ExcelRender.RenderFromExcel(stream, 0);
}
else
{
dt = ExcelRender.RenderFromExcelxlsx(stream, 0);
} !!!!
dgvLeadTo.Visible = true;
for (int i = 0; i < dt.Rows.Count; i++)
{
dgvLeadTo.Rows.Add(1);
dgvLeadTo.Rows[i].Cells["Name"].Value = Convert.ToString(dt.Rows[i][0]);
dgvLeadTo.Rows[i].Cells["Sex"].Value = Convert.ToString(dt.Rows[i][1]);
dgvLeadTo.Rows[i].Cells["IDCardNum"].Value = Convert.ToString(dt.Rows[i][2]);
dgvLeadTo.Rows[i].Cells["NativePlace"].Value = Convert.ToString(dt.Rows[i][3]);
dgvLeadTo.Rows[i].Cells["Nation"].Value = Convert.ToString(dt.Rows[i][4]);
dgvLeadTo.Rows[i].Cells["PoliticsStatus"].Value = Convert.ToString(dt.Rows[i][5]);
dgvLeadTo.Rows[i].Cells["Atdutytime"].Value = Convert.ToString(dt.Rows[i][6]);//dt.GetDateTimeFormats('g')[0].ToString();//2005-11-5 14:06
dgvLeadTo.Rows[i].Cells["ndunit"].Value = Convert.ToString(dt.Rows[i][7]);
dgvLeadTo.Rows[i].Cells["Duty"].Value = Convert.ToString(dt.Rows[i][8]);
dgvLeadTo.Rows[i].Cells["Beststu"].Value = Convert.ToString(dt.Rows[i][9]);
dgvLeadTo.Rows[i].Cells["School"].Value = Convert.ToString(dt.Rows[i][10]);
dgvLeadTo.Rows[i].Cells["Major"].Value = Convert.ToString(dt.Rows[i][11]);
dgvLeadTo.Rows[i].Cells["Photo"].Value = Convert.ToString(dt.Rows[i][12]);
dgvLeadTo.Rows[i].Cells["SexID"].Value = Convert.ToInt32(SelectDetailsID(Convert.ToString(dt.Rows[i][1])));
dgvLeadTo.Rows[i].Cells["NationID"].Value = Convert.ToInt32(SelectDetailsID(Convert.ToString(dt.Rows[i][4])));
dgvLeadTo.Rows[i].Cells["PoliticsStatusID"].Value = Convert.ToInt32(SelectDetailsID(Convert.ToString(dt.Rows[i][5])));
dgvLeadTo.Rows[i].Cells["NdunitID"].Value = Convert.ToInt32(SelectDetailsID(Convert.ToString(dt.Rows[i][7])));
dgvLeadTo.Rows[i].Cells["DutyID"].Value = Convert.ToInt32(SelectDetailsID(Convert.ToString(dt.Rows[i][8])));
dgvLeadTo.Rows[i].Cells["BeststuID"].Value = Convert.ToInt32(SelectDetailsID(Convert.ToString(dt.Rows[i][9])));
}
}
}
}
#endregion
未能加载文件或程序集"ICSharpCode.SharpZipLib,Bersion=0.86.0.518,Culure=neutral,
PublicKey=1b03e6acf1164f73"或它的某一个依赖项。系统找不到指定文件
缺少ICSharpCode.SharpZipLib的引用