Beispiel #1
0
        private PageSetup GetPageSetup()
        {
            PageSetup pageSetup = worksheet.GetFirstChild <PageSetup>();

            if (pageSetup == null)
            {
                pageSetup = new PageSetup();
                // ищем куда вставить
                ConditionalFormatting conditionalFormatting = null;
                var conditionalFormattings = worksheet.Elements <ConditionalFormatting>();
                if (conditionalFormattings != null && conditionalFormattings.Count <ConditionalFormatting>() > 0)
                {
                    conditionalFormatting = conditionalFormattings.Last <ConditionalFormatting>();
                }
                if (conditionalFormatting != null)
                {
                    conditionalFormatting.InsertAfterSelf <PageSetup>(pageSetup);
                }
                else
                {
                    MergeCells mergeCells = worksheet.GetFirstChild <MergeCells>();
                    if (mergeCells != null)
                    {
                        mergeCells.InsertAfterSelf <PageSetup>(pageSetup);
                    }
                    else
                    {
                        SheetData sheetData = worksheet.GetFirstChild <SheetData>();
                        if (sheetData != null)
                        {
                            sheetData.InsertAfterSelf <PageSetup>(pageSetup);
                        }
                    }
                }
            }
            return(pageSetup);
        }