日期:2014-05-18 浏览次数:20848 次
for (int i = 0; i < table.Columns.Count; i++) { string ColumnName = table.Columns[i].Caption; for (int row = 0; row < table.Rows.Count; row++) { if ("ABCD".IndexOf(ColumnName) > -1) { if (!codeList.Contains(table.Rows[row][1].ToString())) codeList.Add(table.Rows[row][1].ToString()); //循环判断改行的后面行是否有相同的,,有则一行行合并 for (int r = row; r < table.Rows.Count; r++) { if (r != table.Rows.Count - 1 && table.Rows[r][i].ToString() == table.Rows[r + 1][i].ToString()) { rang = (_Excel.Range)sheet.get_Range(table.Columns[i].Caption + (r + 2), table.Columns[i].Caption + (r + 2 + 1)); rang.MergeCells = true; } } } sheet.Cells[row + 2, i + 1] = table.Rows[row][i].ToString(); } }