请教aspose.cells或者npoi获取单元格的合并数目
1个回答
2016-07-08
展开全部
private void ReportExportMergedCells(NPOI.SS.UserModel.ISheet sheet, string strFields)
{
int iCol = 0, iR = 0, iR1 = 0;
string strValue1 = string.Empty;
if (strFields != "" && !strFields.StartsWith(",")) strFields = "," + strFields;
if (strFields != "" && !strFields.EndsWith(",")) strFields += ",";
foreach (NPOI.SS.UserModel.ICell cell in sheet.GetRow(0).Cells)
{
if (strFields != "" && !strFields.Contains("," + cell.ToString() + ","))
{
iCol++;
continue;
}
iR1 = iR = 0;
strValue1 = string.Empty;
foreach (NPOI.SS.UserModel.IRow irow in sheet)
{
if (iR1 == 0)
{
strValue1 = irow.Cells[iCol].ToString();
iR1 = iR;
}
else if (strValue1 != irow.Cells[iCol].ToString())
{
if ((iR - 1) >= iR1)
sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(iR1, iR - 1, iCol, iCol));
strValue1 = irow.Cells[iCol].ToString();
iR1 = iR;
}
else if (iR == (sheet.LastRowNum))//
{
if (strValue1 == irow.Cells[iCol].ToString())
{
if ((iR - 1) >= iR1)
sheet.AddMergedRegion(new NPOI.SS.Util.CellRangeAddress(iR1, iR, iCol, iCol));
}
}
iR++;
}
iCol++;
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |