在前台页面有一个导出按钮btn2 在后台页面给它填充方法 protected void btn2_Click(object sender, EventArgs e) { int j = 0; ds = SqlHelper.ExecuteDataset(this.connStr, CommandType.Text, "select count(nf),nf from Table_1 group by nf;select * from Table_1 order by nf "); helper = new ExcelHelper(); if (ds != null) { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (i == 0) { helper.MergeCells(1,1, 1, Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString()), 1, ds.Tables[0].Rows[i][1].ToString()); } else if (Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString()) != 1) { helper.MergeCells(1, j + 1, 1, j + Convert.ToInt32(ds.Tables[0].Rows[i][0].ToString()), 1, ds.Tables[0].Rows[i][1].ToString()); }