回复 7楼liuyong的帖子
你好,
思路为设置 临时 spread 读取当前 excel表格,再通过逐一单元格值对比实现“数据重复判断”。大体代码如下,具体还需要完善:
- protected void Button1_Click(object sender, EventArgs e)
- {
- this.spread.Reset();
- bool flag = false;
- dt.Columns.Add("col1");
- dt.Columns.Add("col2");
- dt.Rows.Add("1", "1");
- dt.Rows.Add("2", "2");
- dt.Rows.Add("2", "2");
- this.spread.OpenExcel(this.Server.MapPath("Book1.xlsx"));
- for (int i = 0; i < this.spread.Sheets[0].RowCount; i++)
- {
- for (int j = 0; j < this.spread.Sheets[0].ColumnCount; j++)
- {
- if (this.spread.Sheets[0].Cells[i, j].Text != dt.Rows[i][j].ToString())
- {
- }
- else
- {
- }
- }
- }
- if (flag)
- {
- this.Response.Write("<script>alert('有重复数据')</script>");
- }
- else
- {
- this.Response.Write("<script>alert('无重复数据')</script>");
- this.FpSpread1.OpenExcel(this.Server.MapPath("Book1.xlsx"));
- }
- }
复制代码 |