欢迎来到天天文库
浏览记录
ID:8812116
大小:103.00 KB
页数:3页
时间:2018-04-08
《在excel中将连续多列相同数据项合并》由会员上传分享,免费在线阅读,更多相关内容在应用文档-天天文库。
1、在Excel中将连续多列相同数据项合并效果图如下:代码如下:/**//// /// 合并工作表中指定行数和列数数据相同的单元格 /// /// 工作表索引 /// 开始行索引 /// 开始列索引
2、ram> /// 要合并的行数 /// 要合并的列数 public void MergeWorkSheet(int sheetIndex,int beginRowIndex,int beginColumnIndex,int rowCount,int columnCount) { //检查参数
3、 if ( columnCount < 1
4、
5、 rowCount < 1) return ; for(int col=0;col6、 string text = ""; for(int row=0;row7、 { for(int n=0;n<=col;n++) { range = (Excel.Range)workSheet.Cells[row + beginRowIndex,n + beginColumnIndex]; range = (Excel.Range)ran8、ge.MergeArea.get_Item(1,1); text = range.Text.ToString(); prvName = prvName + text; range = (Excel.Range)workSheet.Cells[row + 1 + beginRowIndex,n + beginColumnIndex]; 9、 range = (Excel.Range)range.MergeArea.get_Item(1,1); nextName = nextName + range.Text.ToString(); } if(prvName == nextName) 10、 { mergeCount++; if(row == rowCount - 2) { this.MergeCells(sheetIndex,beginRowInd
6、 string text = ""; for(int row=0;row7、 { for(int n=0;n<=col;n++) { range = (Excel.Range)workSheet.Cells[row + beginRowIndex,n + beginColumnIndex]; range = (Excel.Range)ran8、ge.MergeArea.get_Item(1,1); text = range.Text.ToString(); prvName = prvName + text; range = (Excel.Range)workSheet.Cells[row + 1 + beginRowIndex,n + beginColumnIndex]; 9、 range = (Excel.Range)range.MergeArea.get_Item(1,1); nextName = nextName + range.Text.ToString(); } if(prvName == nextName) 10、 { mergeCount++; if(row == rowCount - 2) { this.MergeCells(sheetIndex,beginRowInd
7、 { for(int n=0;n<=col;n++) { range = (Excel.Range)workSheet.Cells[row + beginRowIndex,n + beginColumnIndex]; range = (Excel.Range)ran
8、ge.MergeArea.get_Item(1,1); text = range.Text.ToString(); prvName = prvName + text; range = (Excel.Range)workSheet.Cells[row + 1 + beginRowIndex,n + beginColumnIndex];
9、 range = (Excel.Range)range.MergeArea.get_Item(1,1); nextName = nextName + range.Text.ToString(); } if(prvName == nextName)
10、 { mergeCount++; if(row == rowCount - 2) { this.MergeCells(sheetIndex,beginRowInd
此文档下载收益归作者所有