如果fpSpread1.ActiveSheet.SetRowMerge()不能达到你的需求,只能使用fpSpread1.ActiveSheet.Models.Span.Add()来进行合并
我使用你的代码测试了,如果一个一个合并,总共耗时在2秒左右的时间,我的电脑是 i5 + 4g内存
- private void Form1_Load(object sender, EventArgs e)
- {
- dtData.Columns.Add(new DataColumn());
- dtData.Columns.Add(new DataColumn());
- dtData.Columns.Add(new DataColumn());
- dtData.Columns.Add(new DataColumn());
- dtData.Columns.Add(new DataColumn());
- dtData.Columns.Add(new DataColumn());
- dtData.Columns.Add(new DataColumn());
- dtData.Columns.Add(new DataColumn());
- for (int i = 0; i < 20000; i++)
- {
- DataRow drData = dtData.NewRow();
- drData[0] = "00" + i;
- drData[1] = "01";
- drData[2] = "02";
- drData[3] = "03";
- drData[4] = "04";
- drData[5] = "05";
- drData[6] = "06";
- drData[7] = "07";
- dtData.Rows.Add(drData);
- drData = dtData.NewRow();
- drData[0] = "00" + i;
- drData[1] = "11";
- drData[2] = "12";
- drData[3] = "13";
- drData[4] = "13";
- drData[5] = "13";
- drData[6] = "16";
- drData[7] = "07";
- dtData.Rows.Add(drData);
- }
- fpSpread1_Sheet1.RowCount = 0;
- fpSpread1_Sheet1.RowCount = 10;
- System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
- sw.Start();
- fpSpread1.SuspendLayout();
- fpSpread1.DataSource = dtData;
- for (int i = 0; i < dtData.Rows.Count / 2; i++)
- {
- fpSpread1.ActiveSheet.Models.Span.Add(i * 2, 0, 2, 1);
- fpSpread1.ActiveSheet.Models.Span.Add(i * 2 + 1, 3, 1, 3);
- }
- fpSpread1.ActiveSheet.Models.Span.Add(0, 7, fpSpread1.ActiveSheet.RowCount, 1);
- fpSpread1.ResumeLayout();
- sw.Stop();
- MessageBox.Show("合并单元格耗时:" + sw.ElapsedMilliseconds.ToString() + "毫秒");
- }
复制代码 |