zoukankan
html css js c++ java
在Excel中将连续多列相同数据项合并
效果图如下:
代码如下:
/**/
///
<summary>
///
合并工作表中指定行数和列数数据相同的单元格
///
</summary>
///
<param name="sheetIndex">
工作表索引
</param>
///
<param name="beginRowIndex">
开始行索引
</param>
///
<param name="beginColumnIndex">
开始列索引
</param>
///
<param name="rowCount">
要合并的行数
</param>
///
<param name="columnCount">
要合并的列数
</param>
public
void
MergeWorkSheet(
int
sheetIndex,
int
beginRowIndex,
int
beginColumnIndex,
int
rowCount,
int
columnCount)
{
//
检查参数
if
( columnCount
<
1
||
rowCount
<
1
)
return
;
for
(
int
col
=
0
;col
<
columnCount;col
++
)
{
int
mark
=
0
;
//
标记比较数据中第一条记录位置
int
mergeCount
=
1
;
//
相同记录数,即要合并的行数
string
text
=
""
;
for
(
int
row
=
0
;row
<
rowCount;row
++
)
{
string
prvName
=
""
;
string
nextName
=
""
;
//
最后一行不用比较
if
( row
+
1
<
rowCount)
{
for
(
int
n
=
0
;n
<=
col;n
++
)
{
range
=
(Excel.Range)workSheet.Cells[row
+
beginRowIndex,n
+
beginColumnIndex];
range
=
(Excel.Range)range.MergeArea.get_Item(
1
,
1
);
text
=
range.Text.ToString();
prvName
=
prvName
+
text;
range
=
(Excel.Range)workSheet.Cells[row
+
1
+
beginRowIndex,n
+
beginColumnIndex];
range
=
(Excel.Range)range.MergeArea.get_Item(
1
,
1
);
nextName
=
nextName
+
range.Text.ToString();
}
if
(prvName
==
nextName)
{
mergeCount
++
;
if
(row
==
rowCount
-
2
)
{
this
.MergeCells(sheetIndex,beginRowIndex
+
mark,beginColumnIndex
+
col,beginRowIndex
+
mark
+
mergeCount
-
1
,beginColumnIndex
+
col,text);
}
}
else
{
this
.MergeCells(sheetIndex,beginRowIndex
+
mark,beginColumnIndex
+
col,beginRowIndex
+
mark
+
mergeCount
-
1
,beginColumnIndex
+
col,text);
mergeCount
=
1
;
mark
=
row
+
1
;
}
}
}
}
}
查看全文
相关阅读:
Kmeans中文聚类
第四周周总结
数据清洗第一天
第三周周总结
关于sqoop上传mysql数据到hive报错的问题
天津东软实训第十一天——Hive连接JDBC
天津东软实训第十天——Hive配置
天津东软实训第九天——MapReduce实战
天津东软实训第八天------倒排索引
Intellij IDEA 创建maven项目,利用API操作HDFS
原文地址:https://www.cnblogs.com/lingyun_k/p/415555.html
最新文章
Java连接并操作SQLServer数据库
JavaScript绑定事件方式小结
Three.js学习总结(一)
模拟时间滚动条
第二阶段冲刺团队绩效评估
项目总结
第二周冲刺总结
网站使用说明
第二周冲刺 第七天
第二周冲刺 第六天
热门文章
第二周冲刺 第五天
第二周冲刺 第四天
第二周冲刺 第三天
第二周冲刺 第二天
第十四周周总结
第十三周周总结
第十二周周总结
软件杯分析
周总结
一线架构师实践指南---总结
Copyright © 2011-2022 走看看