把Excel檔案的資料匯入到DataSet資料集中

2021-05-26 01:38:06 字數 1039 閱讀 3289

前幾天做了這樣的匯入,當時在網上找了很多例子,都不錯。但是由於本機的一些設定原因,有一些**不能執行,最後找到乙個可行性的方法來實現這個功能;

filepath為檔案的路徑

public static datatable import(string filepath)

catch

if (canopen)

}else//如何excel的格式不是標準的需要轉換一下( 只針對

)return rs;

}//此方法來處理excel的格式為**(有tr、td)

private static datatable getdatatablefromstring(string tmphtml)

//先根據「」分拆

string tmprow=tmpstr.replace("","^").split(separator);

for(int i=0;istring tmpstri=tmprow[i];

if(tmpstri.indexof("-1)

tb.columns.add(tmpfieldname);

}else

}//end of if(index>0)

}if(i>0)

tb.rows.add(newrow);}}

}tb.acceptchanges();

return tb;

}///

/// 從指定html字串中剔除指定的物件

///

/// html字串

/// 需要剔除的物件--例如輸入""則剔除""和">"

///

public static string removestring(string tmphtml, string remove)

return tmphtml;

}private static int getsheetindex(byte findtarget, byte finditem)

if (find == finditemlength)

}return index;

}

把Excel資料匯入到MySQL中

本文 未作修改。開啟excel,處理好你需要的列,把不需要的列都刪掉。把標題行也刪掉,只保留資料。另存為csv檔案。特別注意一點 如果你的mysql預設編碼方式是utf 8的話需要用editplus等軟體把csv檔案另存為utf 8編碼格式,因為excel預設編碼格式是ansi,mysql在匯入中文...

如何把excel資料匯入到mysql資料庫中

最近做的工作涉及到把excel資料匯入到mysql資料庫中,看來一些mysqlimport,phpmyadmin命令,但是不怎麼會用.就決定自己寫指令碼解決.先把excel資料檔案儲存成csv格式的檔案,然後寫了下面的簡單perl指令碼倒入mysql資料庫中.需要注意用你的mysql資料庫表的結構替...

如何把excel資料匯入到mysql資料庫中

最近做的工作涉及到把excel資料匯入到mysql資料庫中,看來一些mysqlimport,phpmyadmin命令,但是不怎麼會用.就決定自己寫指令碼解決.先把excel資料檔案儲存成csv格式的檔案,然後寫了下面的簡單perl指令碼倒入mysql資料庫中.需要注意用你的mysql資料庫表的結構替...