INFRAGISTICS-如何复制 Excel 工作表

为您正在使用的每种格式或设置制作一份副本。

//代码示例
// 将信息从第一个参数 Worksheet 复制到第二个参数 Worksheet。
私人无效副本工作表,工作表到
{
// 显示设置
//复制边框
to.DisplayOptions.ShowGridlines = from.DisplayOptions.ShowGridlines ; _ _ _ _ _ _ _
//打印配置
//复制纸张大小
to.PrintOptions.PaperSize = from.PrintOptions.PaperSize ; _ _ _ _ _ _ _
// 复制打印的方向
to.PrintOptions.Orientation = from.PrintOptions.Orientation ; _ _ _ _ _ _ _
// 复制边距
to.PrintOptions.TopMargin = from.PrintOptions.TopMargin ; _ _ _ _ _ _ _
to.PrintOptions.BottomMargin = from.PrintOptions.BottomMargin ; _ _ _ _ _ _ _
to.PrintOptions.RightMargin = from.PrintOptions.RightMargin ; _ _ _ _ _ _ _
to.PrintOptions.LeftMargin = from.PrintOptions.LeftMargin ; _ _ _ _ _ _ _
to.PrintOptions.HeaderMargin = from.PrintOptions.HeaderMargin ; _ _ _ _ _ _ _
to.PrintOptions.FooterMargin = from.PrintOptions.FooterMargin ; _ _ _ _ _ _ _
//复制分页符
for ( int j = 0 ; j < from . PrintOptions . Horizo​​ntalPageBreaks . Count ; j++ )
{
to.PrintOptions.Horizo​​ntalPageBreaks.Add ( to.PrintOptions.Horizo​​ntalPageBreaks [ j ] ) ; _ _ _ _ _ _ _
}
for ( int k = 0 ; k < from . PrintOptions . VerticalPageBreaks . Count ; k++ )
{
to.PrintOptions.VerticalPageBreaks.Add ( to.PrintOptions.VerticalPageBreaks [ k ] ) ; _ _ _ _ _ _ _
}
foreach WorksheetRow.Rows _
{
//复制行高
to.Rows [ row.Index ] .Height = row.Height ; _ _ _
foreach row.Cells中的WorksheetCell单元格
{
//复制列宽
to.Columns [ cell.ColumnIndex ] .Width = from .Columns [ cell.ColumnIndex ] .Width ; _ _ _ _ _ _
if ( cell.Formula ! = null )
{
//复制函数
to.Rows[row.Index].Cells[cell.ColumnIndex].ApplyFormula(cell.Formula.ToString());
}
else
{
// セルの値をコピーします
to.Rows[row.Index].Cells[cell.ColumnIndex].Value = cell.Value;
}
// セルのフォーマットをコピーします
to.Rows[row.Index].Cells[cell.ColumnIndex].CellFormat.SetFormatting(cell.CellFormat);
to.Rows[row.Index].Cells[cell.ColumnIndex].CellFormat.TopBorderStyle = cell.GetResolvedCellFormat().TopBorderStyle;
to.Rows[row.Index].Cells[cell.ColumnIndex].CellFormat.BottomBorderStyle = cell.GetResolvedCellFormat().BottomBorderStyle;
to.Rows[row.Index].Cells[cell.ColumnIndex].CellFormat.LeftBorderStyle = cell.GetResolvedCellFormat().LeftBorderStyle;
to.Rows[row.Index].Cells[cell.ColumnIndex].CellFormat.RightBorderStyle = cell.GetResolvedCellFormat().RightBorderStyle;
}
}
//結合セルの情報をコピーします
foreach (var m in from.MergedCellsRegions)
{
to.MergedCellsRegions.Add(m.FirstRow, m.FirstColumn, m.LastRow, m.LastColumn);
to.MergedCellsRegions[to.MergedCellsRegions.Count - 1].CellFormat.SetFormatting(m.CellFormat);
}
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值