XSSFSheet复制页面设置

XSSFSheet复制页面设置

  public  void CopyPrintSetup(XSSFSheet srcSheet, XSSFSheet tgtSheet, )
        {
            IPrintSetup srcSheetPs = srcSheet.PrintSetup;
            IPrintSetup tgtSheetPs = tgtSheet.PrintSetup;
            var properties = tgtSheetPs.GetType().GetProperties();
            foreach (var prop in properties)
            {
               object value = prop.GetValue(srcSheetPs, null);
               prop.SetValue(tgtSheetPs, value, null);
            }
            //适合页面设置,如果页面设置的宽和高非自动,则为true; 否则为false
            tgtSheet.FitToPage = srcSheet.FitToPage;
            tgtSheet.HorizontallyCenter = srcSheet.HorizontallyCenter;
            tgtSheet.VerticallyCenter = srcSheet.VerticallyCenter;
            tgtSheet.IsPrintGridlines = srcSheet.IsPrintGridlines;
            tgtSheet.SetMargin(MarginType.TopMargin, srcSheet.GetMargin(MarginType.TopMargin));
            tgtSheet.SetMargin(MarginType.BottomMargin, srcSheet.GetMargin(MarginType.BottomMargin));
            tgtSheet.SetMargin(MarginType.LeftMargin, srcSheet.GetMargin(MarginType.LeftMargin));
            tgtSheet.SetMargin(MarginType.RightMargin, srcSheet.GetMargin(MarginType.RightMargin));
            tgtSheet.SetMargin(MarginType.HeaderMargin, srcSheet.GetMargin(MarginType.HeaderMargin));
            tgtSheet.SetMargin(MarginType.FooterMargin, srcSheet.GetMargin(MarginType.FooterMargin));
            //复制打印标题参数
            tgtSheet.SetRepeatingColumns(srcSheet.RepeatingColumns);
            tgtSheet.SetRepeatingRows(srcSheet.RepeatingRows);
        }

 

posted @ 2024-12-03 13:50  寻天崖子  阅读(5)  评论(0编辑  收藏  举报