/// <summary>
/// 读取Excel文档
/// </summary>
/// <param name=Path>文件名称</param>
/// <returns>返回一个数据集</returns>
public DataSet ExcelToDS(string Path)
{
string strConn = Provider=MicrosoftJetOLEDB; +Data Source=+ Path +;+Extended Properties=Excel ;;
OleDbConnection conn = new OleDbConnection(strConn);
connOpen();
string strExcel = ;
OleDbDataAdapter myCommand = null;
DataSet ds = null;
strExcel=select * from [sheet$];
myCommand = new OleDbDataAdapter(strExcel strConn);
ds = new DataSet();
myCommandFill(dstable);
return ds;
}
/// <summary>
/// 写入Excel文档
/// </summary>
/// <param name=Path>文件名称</param>
public bool SaveFPtoExcel(string Path)
{
try
{
string strConn = Provider=MicrosoftJetOLEDB; +Data Source=+ Path +;+Extended Properties=Excel ;;
OleDbConnection conn = new OleDbConnection(strConn);
connOpen();
SystemDataOleDbOleDbCommand cmd=new OleDbCommand ();
cmdConnection =conn;
//cmdCommandText =UPDATE [sheet$] SET 姓名= WHERE 工号=日期;
//cmdExecuteNonQuery ();
for(int i=;i<fpSheets []RowCount ;i++)
{
if(fpSheets []Cells[i]Text!=)
{
cmdCommandText =INSERT INTO [sheet$] (工号姓名部门职务日期时间) VALUES(+fpSheets []Cells[i]Text+ +
fpSheets []Cells[i]Text++fpSheets []Cells[i]Text++fpSheets []Cells[i]Text+
+fpSheets []Cells[i]Text++fpSheets []Cells[i]Text+);
cmdExecuteNonQuery ();
}
}
connClose ();
return true;
}
catch(SystemDataOleDbOleDbException ex)
{
SystemDiagnosticsDebugWriteLine (写入Excel发生错误+exMessage );
}
return false;
}