很多时候,我们会根据业务需要像Excel一样,对标题单元格进行自定义创建。当然,Spread中标题单元格可以有数目不等的行或列。下面就通过实例给大家介绍在Spread中如何创建一个有多行或多列的标题单元格。
        
效果截图:


参考代码:

1.列标题中创建多行

 
fpSpread1.Sheets[0].ColumnHeaderRowCount = 3;

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 0, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 2, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 4, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 6, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(0, 0, 1, 8);



fpSpread1.Sheets[0].ColumnHeader.Columns[0].Label = "成本金额";

fpSpread1.Sheets[0].ColumnHeader.Columns[1].Label = "销售金额";

fpSpread1.Sheets[0].ColumnHeader.Columns[2].Label = "成本金额";

fpSpread1.Sheets[0].ColumnHeader.Columns[3].Label = "销售金额";

fpSpread1.Sheets[0].ColumnHeader.Columns[4].Label = "成本金额";

fpSpread1.Sheets[0].ColumnHeader.Columns[5].Label = "销售金额";

fpSpread1.Sheets[0].ColumnHeader.Columns[6].Label = "成本金额";

fpSpread1.Sheets[0].ColumnHeader.Columns[7].Label = "销售金额";

fpSpread1.Sheets[0].ColumnHeader.Cells[0, 0].Text = "2012年";

fpSpread1.Sheets[0].ColumnHeader.Cells[1, 0].Text = "第一季度";

fpSpread1.Sheets[0].ColumnHeader.Cells[1, 2].Text = "第二季度";

fpSpread1.Sheets[0].ColumnHeader.Cells[1, 4].Text = "第三季度";

fpSpread1.Sheets[0].ColumnHeader.Cells[1, 6].Text = "第四季度";

复制代码

2.行标题中创建多列

 
fpSpread1.Sheets[0].RowHeaderColumnCount = 2;

fpSpread1.Sheets[0].AddRowHeaderSpanCell(0, 0, 10, 1);

fpSpread1.Sheets[0].RowHeader.Columns[0].Width = 45;

fpSpread1.Sheets[0].RowHeader.Cells[0, 0].Text = "Co. #"; 

复制代码

当然,我们也可以通过如下代码对标题上的行或列单元格进行相应的合并

1.标题上列单元格的合并

 
fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 0, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 2, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 4, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(1, 6, 1, 2);

fpSpread1.Sheets[0].AddColumnHeaderSpanCell(0, 0, 1, 8);

复制代码

2.标题上行单元格的合并

 
fpSpread1.Sheets[0].AddRowHeaderSpanCell(0, 0, 10, 1);

复制代码

环境:VS 2010 && Spread for WinForm 6.0

Demo.zip (45.83 K, 下载次数:17)