public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string str1,str2; string str0 = textBox1.Text.Trim(); //找出?所在位置 str1 = str0.Substring(0,str0.IndexOf('?')); str2 = str0.Substring(str0.IndexOf('?')+1); string[] strs = str2.Split('&'); //textBox2.Text = str0.Replace(rep1,"").Replace(rep2,","); textBox2.Text = str1 + " " + ff(strs); } string ff(string [] strs) { StringBuilder strSB = new StringBuilder(); //strSql.Append("select top "); for (int i=0; i<strs.Length;i++) { strSB.Append(strs[i]+" "); } return strSB.ToString(); } }
//读取EXCE转换为提交的带参的url地址
private void button1_Click(object sender, EventArgs e) { ReadExcelToDataGridView(@"C:UsersAdministratorDocumentsTencent Files372282126FileRecvxxx ets.xlsx", "Sheet2", dataGridView1); } #region //读取EXCEl到DataGridView1 void ReadExcelToDataGridView(string excelPath, string TableName, DataGridView dataGridView1) //Excel路径+表名+dataGridview { //读取Excel到dataGridview //string excelPath = "测试.xlsx"; //文件路径 string fileExt = Path.GetExtension(excelPath);//获得文件扩展名 string conn = ""; if (fileExt == ".xls") { conn = "Provider = Microsoft.Jet.OLEDB.4.0 ; Data Source =" + excelPath + ";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"; } else { conn = "Provider = Microsoft.ACE.OLEDB.12.0 ; Data Source =" + excelPath + ";Extended Properties='Excel 12.0;HDR=Yes;IMEX=1'"; } OleDbConnection con = new OleDbConnection(conn); DataTable dt = new DataTable(); //OleDbDataAdapter da = new OleDbDataAdapter("select * from [Admin$]", con); //查询表名文件Admin的数据表 OleDbDataAdapter da = new OleDbDataAdapter("select * from [" + TableName + "$]", con); //查询表名文件Admin的数据表 con.Open(); da.Fill(dt); //填充到dt con.Close(); dataGridView1.DataSource = dt; //foreach (DataRow dr in dt.Rows) //{ // MessageBox.Show(dr["管理员编号"].ToString()); //} MessageBox.Show("读取完成!"); } #endregion //输出到文本框 private void button2_Click(object sender, EventArgs e) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { string key = dataGridView1.Rows[i].Cells["KEY"].Value.ToString(); string value = dataGridView1.Rows[i].Cells["VALUE"].Value.ToString(); sb.Append("&"); sb.Append(key); sb.Append("="); sb.Append(value); } txtData.Text = sb.ToString(); }