请参考如下代码
- var sheet1 = fpSpread1.Sheets[0];
- var sheet2 = fpSpread1.Sheets[1];
- int startRow = 10, copyRowCount = 20, copyColumnCount = 10 ;
- sheet2.AddRows(0, startRow);
- for(int i = startRow; i < startRow + copyRowCount; i++)
- {
- for (int j = 0; j < copyColumnCount; j++)
- {
- // copy span;
- var spans = sheet2.GetSpanCell(i, j);
- if (spans != null && spans.Row == i && spans.Column == j)
- {
- sheet1.AddSpanCell(i, j, spans.RowCount, spans.ColumnCount);
- }
- var cell = sheet2.Cells[i, j];
- //copy formula and value
- if (!String.IsNullOrEmpty(cell.Formula))
- {
- sheet1.SetFormula(i, j, cell.Formula);
- }
- else
- {
- sheet1.SetValue(i, j, cell.Value);
- }
- var style2 = sheet2.GetStyleInfo(i, j);
- if (style2 != null)
- {
- style2 = sheet2.GetStyleInfo(i, j, new StyleInfo());
- sheet1.SetStyleInfo(i, j, style2);
- }
- }
- }
复制代码 |