本帖最后由 bingdaoice 于 2020-7-10 10:24 编辑
我目前使用的方法是这样的,但这个方法有一点小问题,就是有些数据的格式复制过去后,有细微的差别。例如在原表格中是换了行的,但是在复制之后的表格中却没有换行。
FpSpread Spread2 = new FpSpread();
Spread2.Open(p_certif.GetRecdTempFile(tpId, false));
sv.AddRows(RowIndex, Spread2.Sheets[0].RowCount);
for (int r = 0; r < Spread2.Sheets[0].RowCount; r++)
{
for (int c = 0; c < Spread2.Sheets[0].ColumnCount; c++)// copy span;
{
var spans = Spread2.Sheets[0].GetSpanCell(r, c);
if (spans != null && spans.Row == r && spans.Column == c)
{
sv.AddSpanCell(RowIndex + r, c, spans.RowCount, spans.ColumnCount);
}
var cell = Spread2.Sheets[0].Cells[r, c];
if (!String.IsNullOrEmpty(cell.Formula))//copy formula and value
{
sv.SetFormula(RowIndex + r, c, cell.Formula);
}
else
{
sv.SetValue(RowIndex + r, c, cell.Value);
}
sv.SetTag(RowIndex + r, c, cell.Tag);
var style2 = Spread2.Sheets[0].GetStyleInfo(r, c);
if (style2 != null)
{
style2 = Spread2.Sheets[0].GetStyleInfo(r, c, new StyleInfo());
sv.SetStyleInfo(RowIndex + r, c, style2);
}
}
}
if (AddPic == true)
{
foreach (FarPoint.Win.Spread.DrawingSpace.PSObject shape in Spread2.Sheets[0].DrawingContainer.ContainedObjects)
{
if (shape != null && shape.BackgroundImage != null)
{
var newshape = shape.Clone() as FarPoint.Win.Spread.DrawingSpace.PSShape;
sv.AddShape(newshape);
}
}
}
|