导出excel
tempsql = insert into [sheet1$](打款日期,办事处,领款人,卡号,卡用户,金额,保证金,备注) values('{0}','{1}','{2}','{3}','{4}','{5}','','');//多条分号隔开(;)
View Code
/// <summary> /// /// </summary> /// <param name="OldPath">execl模板</param> /// <param name="NewPath">新的execl</param> /// <param name="tempsql">插入execl的sql语句</param> /// <returns></returns> public bool SaveFP2toExcel(string OldPath,string NewPath, string tempsql) { if (File.Exists(OldPath)) { File.Copy(OldPath, NewPath, false); } else { return false; } try { string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + OldPath + ";" + "Extended Properties=Excel 8.0;"; OleDbConnection conn = new OleDbConnection(strConn); conn.Open(); System.Data.OleDb.OleDbCommand cmd = new OleDbCommand(); cmd.Connection = conn; string[] _tempSql = tempsql.Split(';'); foreach (string s in _tempSql) { cmd.CommandText = s; cmd.ExecuteNonQuery(); } conn.Close(); return true; } catch { return false; } }

浙公网安备 33010602011771号