C#中如何把excel表格的数据导入到listview中
先不用导入到数据库,先导入到listview中,点击保存就保存到本地,后期经过点击提交才上传到数据库...
先不用导入到数据库,先导入到listview中,点击保存就保存到本地,后期经过点击提交才上传到数据库
展开
2个回答
展开全部
private void GetDataFromExcelWithAppointSheetName(string Path)
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
//返回Excel的架构,包括各个sheet表的名称,类型,创建时间和修改时间等
DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
//包含excel中表名的字符串数组
string[] strTableNames = new string[dtSheetName.Rows.Count];
for (int k = 0; k < dtSheetName.Rows.Count; k++)
{
strTableNames[k] = dtSheetName.Rows[k]["TABLE_NAME"].ToString();
}
OleDbDataAdapter myCommand = null;
DataTable dt = new DataTable();
//从指定的表明查询数据,可先把所有表明列出来供用户选择
string strExcel = "select * from [" + strTableNames[0] + "]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
dt = new DataTable();
myCommand.Fill(dt);
dataGridView2.DataSource = dt; //绑定到界面
}
其中,Path是Excel文件的路径
把dataGridView2换成listview试试
{
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + Path + ";" + "Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
//返回Excel的架构,包括各个sheet表的名称,类型,创建时间和修改时间等
DataTable dtSheetName = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "Table" });
//包含excel中表名的字符串数组
string[] strTableNames = new string[dtSheetName.Rows.Count];
for (int k = 0; k < dtSheetName.Rows.Count; k++)
{
strTableNames[k] = dtSheetName.Rows[k]["TABLE_NAME"].ToString();
}
OleDbDataAdapter myCommand = null;
DataTable dt = new DataTable();
//从指定的表明查询数据,可先把所有表明列出来供用户选择
string strExcel = "select * from [" + strTableNames[0] + "]";
myCommand = new OleDbDataAdapter(strExcel, strConn);
dt = new DataTable();
myCommand.Fill(dt);
dataGridView2.DataSource = dt; //绑定到界面
}
其中,Path是Excel文件的路径
把dataGridView2换成listview试试
2015-07-23
展开全部
var baseText3=null
function srsd(){
var popUp3=document.getElementById("popupcontent3");
popUp3.style.top="";
popUp3.style.left="";
if (baseText3==null){
baseText3=popUp3.innerHTML;
popUp3.innerHTML=baseText3+"<div id=\"statusbar3\"><a onclick=\"hidePopup3();\">
</a></div>";
}
function srsd(){
var popUp3=document.getElementById("popupcontent3");
popUp3.style.top="";
popUp3.style.left="";
if (baseText3==null){
baseText3=popUp3.innerHTML;
popUp3.innerHTML=baseText3+"<div id=\"statusbar3\"><a onclick=\"hidePopup3();\">
</a></div>";
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询