Пример #1
0
 private void GettingActualValueFromThemableColor(DocumentTheme theme, ThemableColor themableColor)
 {
     #region radwordsprocessing-concepts-document-themes_7
     Color actualColor = themableColor.GetActualValue(theme);
     // the actual color is the same as Accent1 color of the colorScheme
     #endregion
 }
Пример #2
0
 public void CreateForeColorFilter()
 {
     #region radspreadprocessing-features-filtering_4
     ThemableColor   color  = new ThemableColor(Colors.Red);
     ForeColorFilter filter = new ForeColorFilter(0, color);
     #endregion
 }
Пример #3
0
        public void CreateCellStyle()
        {
            #region radspreadprocessing-features-styling-cell-styles_1
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add();

            CellStyle cellStyle = workbook.Styles.Add("My style", CellStyleCategory.Custom);

            cellStyle.BeginUpdate();

            CellBorder border = new CellBorder(CellBorderStyle.DashDotDot, new ThemableColor(Colors.Red));
            cellStyle.LeftBorder   = border;
            cellStyle.TopBorder    = border;
            cellStyle.RightBorder  = border;
            cellStyle.BottomBorder = border;

            ThemableColor patternColor    = new ThemableColor(ThemeColorType.Accent1);
            ThemableColor backgroundColor = new ThemableColor(ThemeColorType.Accent5, ColorShadeType.Shade2);
            IFill         fill            = new PatternFill(PatternType.Gray75Percent, patternColor, backgroundColor);
            cellStyle.Fill = fill;

            cellStyle.HorizontalAlignment = RadHorizontalAlignment.Left;
            cellStyle.VerticalAlignment   = RadVerticalAlignment.Center;

            cellStyle.EndUpdate();

            workbook.ActiveWorksheet.Cells[0, 0].SetStyleName("My style");
            #endregion
        }
        private void AddDiscountRule(Worksheet sheet)
        {
            ConditionalFormattingDxfRule discountRule = null;

            switch (this.SelectedDiscountComparison)
            {
            case DiscountComparison.GreaterThan:
                discountRule = new GreaterThanRule(this.discountThreshold.ToString());
                break;

            case DiscountComparison.GreaterThanOrEqual:
                discountRule = new GreaterThanOrEqualToRule(this.discountThreshold.ToString());
                break;

            case DiscountComparison.LessThan:
                discountRule = new LessThanRule(this.discountThreshold.ToString());
                break;

            case DiscountComparison.LessThanOrEqual:
                discountRule = new LessThanOrEqualToRule(this.discountThreshold.ToString());
                break;
            }

            discountRule.Formatting = new DifferentialFormatting();
            ThemableColor fillColor = new ThemableColor(Telerik.Documents.Media.Color.FromArgb(255, 198, 239, 206));
            ThemableColor foreColor = new ThemableColor(Telerik.Documents.Media.Color.FromArgb(255, 0, 97, 0));

            discountRule.Formatting.ForeColor = foreColor;
            discountRule.Formatting.Fill      = new PatternFill(PatternType.Solid, fillColor, fillColor);

            sheet.Cells[3, 5, 48, 5].AddConditionalFormatting(new Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormatting(discountRule));
        }
Пример #5
0
        private void CreateTableWithContent()
        {
            #region radwordsprocessing-model-table_4
            RadFlowDocument document = new RadFlowDocument();

            Table table = document.Sections.AddSection().Blocks.AddTable();
            document.StyleRepository.AddBuiltInStyle(BuiltInStyleNames.TableGridStyleName);
            table.StyleId = BuiltInStyleNames.TableGridStyleName;

            ThemableColor cellBackground = new ThemableColor(Colors.Beige);

            for (int i = 0; i < 5; i++)
            {
                TableRow row = table.Rows.AddTableRow();

                for (int j = 0; j < 10; j++)
                {
                    TableCell cell = row.Cells.AddTableCell();
                    cell.Blocks.AddParagraph().Inlines.AddRun(string.Format("Cell {0}, {1}", i, j));
                    cell.Shading.BackgroundColor = cellBackground;
                    cell.PreferredWidth          = new TableWidthUnit(50);
                }
            }
            #endregion
        }
Пример #6
0
        private static void SetCellProperties(PivotExportCellInfo cellInfo, CellSelection cellSelection)
        {
            var fill = GenerateFill(cellInfo.Background);

            if (fill != null)
            {
                cellSelection.SetFill(fill);
            }

            SolidColorBrush solidBrush = cellInfo.Foreground as SolidColorBrush;

            if (solidBrush != null)
            {
                cellSelection.SetForeColor(new ThemableColor(solidBrush.Color));
            }

            if (cellInfo.FontWeight.HasValue && cellInfo.FontWeight.Value != FontWeights.Normal)
            {
                cellSelection.SetIsBold(true);
            }

            SolidColorBrush solidBorderBrush = cellInfo.BorderBrush as SolidColorBrush;

            if (solidBorderBrush != null && cellInfo.BorderThickness.HasValue)
            {
                var borderThickness = cellInfo.BorderThickness.Value;
                var color           = new ThemableColor(solidBorderBrush.Color);
                //var leftBorder = new CellBorder(GetBorderStyle(borderThickness.Left), color);
                //var topBorder = new CellBorder(GetBorderStyle(borderThickness.Top), color);
                var rightBorder  = new CellBorder(GetBorderStyle(borderThickness.Right), color);
                var bottomBorder = new CellBorder(GetBorderStyle(borderThickness.Bottom), color);
                var insideBorder = cellInfo.Background != null ? new CellBorder(CellBorderStyle.None, color) : null;
                cellSelection.SetBorders(new CellBorders(null, null, rightBorder, bottomBorder, insideBorder, insideBorder, null, null));
            }
        }
Пример #7
0
        public void Demo()
        {
            #region radspreadsheet-model-features-styling-document-themes_0
            ThemeColorScheme colorScheme = new ThemeColorScheme(
                "Mine",
                Colors.Black,     // background 1
                Colors.Blue,      // text 1
                Colors.Brown,     // background 2
                Colors.Cyan,      // text 2
                Colors.DarkGray,  // accent 1
                Colors.Gray,      // accent 2
                Colors.Green,     // accent 3
                Colors.LightGray, // accent 4
                Colors.Magenta,   // accent 5
                Colors.Orange,    // accent 6
                Colors.Purple,    // hyperlink
                Colors.Red);      // followedHyperlink
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_1
            ThemableColor themableColor = new ThemableColor(ThemeColorType.Accent1);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_2
            ThemeFontScheme fontScheme = new ThemeFontScheme(
                "Mine",
                "Times New Roman",  // latinMajor
                "Arial");           // latinMinor
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_3
            ThemableFontFamily themableFont = new ThemableFontFamily(ThemeFontType.Major);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_4
            DocumentTheme theme = new DocumentTheme("Mine", colorScheme, fontScheme);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_5
            DocumentTheme theme1 = new DocumentTheme("From Predefined schemes", PredefinedThemeSchemes.ColorSchemes[0], PredefinedThemeSchemes.FontSchemes[5]);
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_6
            Workbook workbook = new Workbook();
            workbook.Worksheets.Add();
            workbook.Theme = theme;
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_7
            Color actualColor = themableColor.GetActualValue(theme);
            // the actual color is the same as Accent1 color of the colorScheme
            #endregion

            #region radspreadsheet-model-features-styling-document-themes_8
            var actualFont = themableFont.GetActualValue(theme);
            // the actualFont is the same as the Major font of the fontScheme
            #endregion
        }
Пример #8
0
        public static Table CreateTableFrame(Table table)
        {
            ThemableColor bordersColor = new ThemableColor(Colors.Black);

            //Set table border
            table.Borders          = new TableBorders(new Border(3, BorderStyle.Single, bordersColor));
            table.TableCellPadding = new Basic.Primitives.Padding(6);

            TableRow row = table.Rows.AddTableRow();

            //Add a merged cell in 2x2
            TableCell cell = row.Cells.AddTableCell();

            cell.RowSpan    = 2;
            cell.ColumnSpan = 2;
            cell.Blocks.AddParagraph().Inlines.AddText("Text 1");

            //Add a single cell
            cell = row.Cells.AddTableCell();
            cell.Blocks.AddParagraph().Inlines.AddText("Text 2");

            row = table.Rows.AddTableRow();
            //Add a single cell
            cell = row.Cells.AddTableCell();
            cell.Blocks.AddParagraph().Inlines.AddText("Text 3");

            row = table.Rows.AddTableRow();
            //Add a single cell
            cell = row.Cells.AddTableCell();
            cell.Blocks.AddParagraph().Inlines.AddText("Text 4");

            //Add a merged cell in 1x2
            cell            = row.Cells.AddTableCell();
            cell.ColumnSpan = 2;
            cell.Blocks.AddParagraph().Inlines.AddText("Text 5");

            row = table.Rows.AddTableRow();
            //Add a single cell
            cell = row.Cells.AddTableCell();
            cell.Blocks.AddParagraph().Inlines.AddText("Text 6");

            //Add a single cell
            cell = row.Cells.AddTableCell();
            cell.Blocks.AddParagraph().Inlines.AddText("Text 7");

            //Add a single cell
            cell = row.Cells.AddTableCell();
            ImageInline imageCell = cell.Blocks.AddParagraph().Inlines.AddImageInline();

            using (Stream stream = File.OpenRead("watermark.png"))
            {
                imageCell.Image.ImageSource = new Basic.Media.ImageSource(stream, "png");
                imageCell.Image.Width       = 50;
                imageCell.Image.Height      = 50;
            }

            return(table);
        }
        private void AddShippingRule(Worksheet sheet)
        {
            ConditionalFormattingDxfRule shippingRule = null;

            shippingRule            = new ContainsRule(this.SelectedShippingTerm);
            shippingRule.Formatting = new DifferentialFormatting();
            ThemableColor color = new ThemableColor(Colors.Green);

            shippingRule.Formatting.ForeColor = color;
            shippingRule.Formatting.IsBold    = true;

            sheet.Cells[3, 3, 48, 3].AddConditionalFormatting(new ConditionalFormatting(shippingRule));
        }
        private void AddClientsRule(Worksheet sheet)
        {
            ConditionalFormattingDxfRule clientsFormatting;

            if (this.SelectedClientsRule == ClientsRule.Duplicate)
            {
                clientsFormatting = new DuplicateValuesRule();
            }
            else
            {
                clientsFormatting = new UniqueValuesRule();
            }

            clientsFormatting.Formatting = new DifferentialFormatting();
            ThemableColor color = new ThemableColor(ThemeColorType.Accent4, 0.6);

            clientsFormatting.Formatting.Fill = new PatternFill(PatternType.Solid, color, color);

            sheet.Cells[3, 1, 48, 1].AddConditionalFormatting(new Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormatting(clientsFormatting));
        }
Пример #11
0
        public void IterateWorksheets()
        {
            #region radspreadsheet-model-working-with-worksheets-iterate-through-worksheets_1
            Workbook workbook = new Workbook();

            workbook.Worksheets.Add();
            workbook.Worksheets.Add();
            workbook.Worksheets.Add();

            ThemableColor foregroundColor = new ThemableColor(Colors.Red);
            Color         backgroundColor = Colors.Green;
            IFill         backgroundFill  = new PatternFill(PatternType.Solid, backgroundColor, backgroundColor);

            foreach (Worksheet worksheet in workbook.Worksheets)
            {
                CellSelection cell = worksheet.Cells[0, 0];
                cell.SetValue("The name of this worksheet is: " + worksheet.Name);
                cell.SetForeColor(foregroundColor);
                cell.SetFill(backgroundFill);
            }
            #endregion
        }
Пример #12
0
        public void GetSetCellBorders()
        {
            #region radspreadsheet-features-formatting-cells_3
            Workbook      workbook  = new Workbook();
            Worksheet     worksheet = workbook.Worksheets.Add();
            ThemableColor purple    = new ThemableColor(Color.FromRgb(155, 89, 182));
            ThemableColor darkBlue  = new ThemableColor(Color.FromRgb(44, 62, 80));

            CellBorders purpleBorders = new CellBorders(new CellBorder(CellBorderStyle.Dotted, purple));
            worksheet.Cells[1, 1, 2, 2].SetBorders(purpleBorders);

            CellBorders darkBlueBorders = new CellBorders(
                new CellBorder(CellBorderStyle.Medium, darkBlue),   // Left border
                new CellBorder(CellBorderStyle.Medium, darkBlue),   // Top border
                new CellBorder(CellBorderStyle.Medium, darkBlue),   // Right border
                new CellBorder(CellBorderStyle.Medium, darkBlue),   // Bottom border
                new CellBorder(CellBorderStyle.Thin, purple),       // Inside horizontal border
                new CellBorder(CellBorderStyle.Thin, purple),       // Inside vertical border
                new CellBorder(CellBorderStyle.None, darkBlue),     // Diagonal up border
                new CellBorder(CellBorderStyle.None, darkBlue));    // Diagonal down border

            worksheet.Cells[1, 4, 2, 5].SetBorders(darkBlueBorders);
            #endregion
        }
        private void AddTotalPriceRule(Worksheet sheet)
        {
            ConditionalFormattingDxfRule totalPriceRule = null;

            switch (this.SelectedPriceFilter)
            {
            case PriceFilter.Bottom:
                totalPriceRule = new BottomRule(ConditionalFormattingUnit.Items, this.PriceRank);
                break;

            case PriceFilter.Top:
                totalPriceRule = new TopRule(ConditionalFormattingUnit.Items, this.PriceRank);
                break;
            }

            totalPriceRule.Formatting = new DifferentialFormatting();
            ThemableColor fillColor = new ThemableColor(Telerik.Documents.Media.Color.FromArgb(255, 255, 199, 206));
            ThemableColor foreColor = new ThemableColor(Telerik.Documents.Media.Color.FromArgb(255, 156, 0, 6));

            totalPriceRule.Formatting.ForeColor = foreColor;
            totalPriceRule.Formatting.Fill      = new PatternFill(PatternType.Solid, fillColor, fillColor);

            sheet.Cells[3, 4, 48, 4].AddConditionalFormatting(new Telerik.Windows.Documents.Spreadsheet.Model.ConditionalFormatting(totalPriceRule));
        }
 private void AddIndentCell(TableRow row, int indentColumns, ThemableColor background)
 {
     TableCell indentCell = row.Cells.AddTableCell();
     indentCell.PreferredWidth = new TableWidthUnit(indentColumns * WidthOfIndentColumns);
     indentCell.Shading.BackgroundColor = background;
     indentCell.Blocks.AddParagraph();
 }
Пример #15
0
 private void CreateThemableColor()
 {
     #region radwordsprocessing-concepts-document-themes_1
     ThemableColor themableColor = new ThemableColor(ThemeColorType.Accent1);
     #endregion
 }
Пример #16
0
        public static Table CreateSimpleTable(Table table)
        {
            ThemableColor bordersColor    = new ThemableColor(Color.FromRgb(73, 90, 128));
            ThemableColor headerColor     = new ThemableColor(Color.FromRgb(34, 143, 189));
            ThemableColor defaultRowColor = new ThemableColor(Color.FromRgb(176, 224, 230));

            Border border = new Border(1, BorderStyle.Single, bordersColor);

            table.Borders          = new TableBorders(border);
            table.TableCellPadding = new Basic.Primitives.Padding(5);

            //Add table header
            TableRow headerRow = table.Rows.AddTableRow();

            headerRow.RepeatOnEveryPage = true;
            //Add first column
            TableCell column1 = headerRow.Cells.AddTableCell();

            column1.State.BackgroundColor.LocalValue = headerColor;
            column1.Borders        = new TableCellBorders(border, border, border, border, null, null, border, null);
            column1.PreferredWidth = new TableWidthUnit(50);
            //Add second column
            TableCell column2 = headerRow.Cells.AddTableCell();

            column2.State.BackgroundColor.LocalValue = headerColor;
            column2.PreferredWidth    = new TableWidthUnit(150);
            column2.VerticalAlignment = VerticalAlignment.Center;
            Paragraph column2Para = column2.Blocks.AddParagraph();

            column2Para.TextAlignment     = Alignment.Center;
            column2Para.State.LineSpacing = 1;
            TextInline column2Text = column2Para.Inlines.AddText("Product");

            column2Text.State.ForegroundColor = new ThemableColor(Colors.White);
            column2Text.FontSize = 20;
            //Add third column
            TableCell column3 = headerRow.Cells.AddTableCell();

            column3.State.BackgroundColor.LocalValue = headerColor;
            column3.PreferredWidth = new TableWidthUnit(250);
            column3.Padding        = new Basic.Primitives.Padding(20, 0, 0, 0);
            Paragraph column3Para = column3.Blocks.AddParagraph();

            column3Para.State.LineSpacing = 1;
            TextInline column3Text = column3Para.Inlines.AddText("Price");

            column3Text.State.ForegroundColor = new ThemableColor(Colors.White);
            column3Text.FontSize = 20;

            //Add table rows
            Random r = new Random();

            for (int i = 0; i < 50; i++)
            {
                ThemableColor rowColor = i % 2 == 0 ? defaultRowColor : new ThemableColor(Colors.White);

                TableRow row = table.Rows.AddTableRow();
                row.Height = new TableRowHeight(HeightType.Exact, 20);

                TableCell idCell = row.Cells.AddTableCell();
                idCell.State.BackgroundColor.LocalValue = rowColor;
                idCell.Blocks.AddParagraph().Inlines.AddText(i.ToString());

                TableCell productCell = row.Cells.AddTableCell();
                productCell.State.BackgroundColor.LocalValue = rowColor;
                Paragraph productPara = productCell.Blocks.AddParagraph();
                productPara.TextAlignment = Alignment.Center;
                productPara.Inlines.AddText(String.Format("Product{0}", i));

                TableCell priceCell = row.Cells.AddTableCell();
                priceCell.Padding = new Basic.Primitives.Padding(20, 0, 0, 0);
                priceCell.State.BackgroundColor.LocalValue = rowColor;
                priceCell.Blocks.AddParagraph().Inlines.AddText(r.Next(10, 1000).ToString());
            }

            return(table);
        }
        protected void btnPrint_Click(object sender, EventArgs e)
        {
            try {
                DocumentReplacemetsController cont = new DocumentReplacemetsController();
                List <DocumentReplacemetB>    reps = new List <DocumentReplacemetB>();
                reps = cont.GetDocumentReplacemets(sqlUniqueName);
                string imgFolderPath = Server.MapPath(fileUploadFolder);
                DocumentReplacemetB curRep;
                BookmarkRangeStart  bookmarkRangeStart;
                RadFlowDocument     curDoc = LoadSampleDocument(sqlUniqueName);

                RadFlowDocumentEditor editor = new RadFlowDocumentEditor(curDoc);
                //System.Text.RegularExpressions.Regex textRegex = new System.Text.RegularExpressions.Regex("ΣΑΟΥΣΟΠΟΥΛΟΥ ΑΝΝΑ");
                //editor.ReplaceText("ΣΑΟΥΣΟΠΟΥΛΟΥ ΑΝΝΑ", txtNew.Text, true, true);
                List <BookmarkRangeStart> test = editor.Document.EnumerateChildrenOfType <BookmarkRangeStart>().ToList();
                Telerik.Windows.Documents.Flow.Model.TableCell currCell;
                Run currRun;

                Header defaultHeader = editor.Document.Sections.First().Headers.Default;
                Footer defaultFooter = editor.Document.Sections.First().Footers.Default;
                //Telerik.Windows.Documents.Flow.Model.Table headerTable = defaultHeader.Blocks.OfType<Telerik.Windows.Documents.Flow.Model.Table>().First();
                //Telerik.Windows.Documents.Flow.Model.TableCell firstCell = headerTable.Rows[0].Cells[0];

                Telerik.Windows.Documents.Flow.Model.Styles.Style tableStyle = new Telerik.Windows.Documents.Flow.Model.Styles.Style("TableStyle", StyleType.Table);
                tableStyle.Name = "Table Style";
                tableStyle.TableProperties.Borders.LocalValue               = new TableBorders(new Border(1, Telerik.Windows.Documents.Flow.Model.Styles.BorderStyle.Single, new ThemableColor(System.Windows.Media.Colors.Black)));
                tableStyle.TableProperties.Alignment.LocalValue             = Alignment.Left;
                tableStyle.TableCellProperties.VerticalAlignment.LocalValue = VerticalAlignment.Center;
                tableStyle.TableCellProperties.PreferredWidth.LocalValue    = new TableWidthUnit(TableWidthUnitType.Percent, 100);
                tableStyle.TableCellProperties.Padding.LocalValue           = new Telerik.Windows.Documents.Primitives.Padding(8);
                editor.Document.StyleRepository.Add(tableStyle);

                curRep   = reps.Find(o => o.UniqueName == "KET_Header_OTELogo");
                currCell = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                using (Stream firstImage = File.OpenRead(imgFolderPath + curRep.Text)) {
                    var inImage = ((Paragraph)currCell.Blocks.First()).Inlines.AddImageInline();
                    inImage.Image.ImageSource = new Telerik.Windows.Documents.Media.ImageSource(firstImage, curRep.Text.Split('.').Last());
                    if (curRep.ImageHeight != null && curRep.ImageWidth != null)
                    {
                        inImage.Image.Height = curRep.ImageHeight.Value;
                        inImage.Image.Width  = curRep.ImageWidth.Value;
                    }
                }

                curRep       = reps.Find(o => o.UniqueName == "KET_Header_OTEMoto");
                currCell     = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                currRun      = ((Paragraph)currCell.Blocks.First()).Inlines.AddRun();
                currRun.Text = curRep.Text;
                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                currRun.Properties.FontSize.LocalValue   = 13.0;
                currRun.Properties.FontWeight.LocalValue = FontWeights.Normal;
                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;

                curRep       = reps.Find(o => o.UniqueName == "KET_Header_Title");
                currCell     = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                currRun      = ((Paragraph)currCell.Blocks.First()).Inlines.AddRun();
                currRun.Text = curRep.Text;
                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                currRun.Properties.FontSize.LocalValue   = 15.0;
                currRun.Properties.FontWeight.LocalValue = FontWeights.Bold;
                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;

                curRep   = reps.Find(o => o.UniqueName == "KET_Header_Department");
                currCell = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                string[]  arrText = curRep.Text.Replace("\r\n", "#").Replace("\n", "#").Split(new char[] { '#' });
                Paragraph newPar  = (Paragraph)currCell.Blocks.First();
                newPar.Properties.TextAlignment.LocalValue = Alignment.Center;
                editor.MoveToInlineStart(((Paragraph)currCell.Blocks.First()).Inlines.First());
                for (int i = 0; i < arrText.Length; i++)
                {
                    currRun = editor.InsertLine(arrText[i]);
                    currRun.Paragraph.Properties.TextAlignment.LocalValue = Alignment.Center;
                    currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Times New Roman");
                    currRun.Properties.FontSize.LocalValue   = 15.0;
                    currRun.Properties.FontWeight.LocalValue = FontWeights.Normal;
                    currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;
                }
                currCell.Blocks.Remove(currCell.Blocks.Last());

                curRep       = reps.Find(o => o.UniqueName == "KET_Header_EDEPPOI");
                currCell     = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                currRun      = ((Paragraph)currCell.Blocks.First()).Inlines.AddRun();
                currRun.Text = curRep.Text;
                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                currRun.Properties.FontSize.LocalValue   = 15.0;
                currRun.Properties.FontWeight.LocalValue = FontWeights.Normal;
                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;

                curRep   = reps.Find(o => o.UniqueName == "KET_Header_PageNo");
                currCell = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                editor.MoveToParagraphStart((Paragraph)currCell.Blocks.First());
                editor.InsertText("ΣΕΛΙΔΑ ");
                editor.InsertField("PAGE", "3");
                if (curRep.Text == "Σελίδα Χ από Υ")
                {
                    editor.InsertText(" ΑΠΟ ");
                    editor.InsertField("NUMPAGES", "5");
                }

                curRep             = reps.Find(o => o.UniqueName == "KET_Header_Date");
                bookmarkRangeStart = defaultHeader.EnumerateChildrenOfType <BookmarkRangeStart>().Where(rangeStart => rangeStart.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault();
                editor.MoveToInlineEnd(bookmarkRangeStart);
                editor.InsertText(DateTime.Now.ToString(curRep.Text, new System.Globalization.CultureInfo("el-GR")));

                curRep             = reps.Find(o => o.UniqueName == "KET_Header_To");
                bookmarkRangeStart = defaultHeader.EnumerateChildrenOfType <BookmarkRangeStart>().Where(rangeStart => rangeStart.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault();
                editor.MoveToInlineEnd(bookmarkRangeStart);
                editor.InsertText(curRep.Text);

                curRep   = reps.Find(o => o.UniqueName == "KET_Footer_OTELogo");
                currCell = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                using (Stream firstImage = File.OpenRead(imgFolderPath + curRep.Text)) {
                    var inImage = ((Paragraph)currCell.Blocks.First()).Inlines.AddImageInline();
                    inImage.Image.ImageSource = new Telerik.Windows.Documents.Media.ImageSource(firstImage, curRep.Text.Split('.').Last());
                    if (curRep.ImageHeight != null && curRep.ImageWidth != null)
                    {
                        inImage.Image.Height = curRep.ImageHeight.Value;
                        inImage.Image.Width  = curRep.ImageWidth.Value;
                    }
                }

                curRep   = reps.Find(o => o.UniqueName == "KET_Footer_ELOT");
                currCell = (Telerik.Windows.Documents.Flow.Model.TableCell)test.Where(o => o.Bookmark.Name == curRep.BookmarkTitle).FirstOrDefault().Paragraph.BlockContainer;
                using (Stream firstImage = File.OpenRead(imgFolderPath + curRep.Text)) {
                    var inImage = ((Paragraph)currCell.Blocks.First()).Inlines.AddImageInline();
                    inImage.Image.ImageSource = new Telerik.Windows.Documents.Media.ImageSource(firstImage, curRep.Text.Split('.').Last());
                    if (curRep.ImageHeight != null && curRep.ImageWidth != null)
                    {
                        inImage.Image.Height = curRep.ImageHeight.Value;
                        inImage.Image.Width  = curRep.ImageWidth.Value;
                    }
                }

                List <TaskForH> lstDummy = createDummyList();
                bookmarkRangeStart = editor.Document.EnumerateChildrenOfType <BookmarkRangeStart>().Where(rangeStart => rangeStart.Bookmark.Name == "Body_Main").FirstOrDefault();
                editor.MoveToInlineEnd(bookmarkRangeStart);
                Telerik.Windows.Documents.Flow.Model.Table tblContent = editor.InsertTable();
                tblContent.StyleId    = "TableStyle";
                tblContent.LayoutType = TableLayoutType.AutoFit;
                ThemableColor cellBackground = new ThemableColor(System.Windows.Media.Colors.Beige);
                for (int i = 0; i < lstDummy.Count; i++)
                {
                    Telerik.Windows.Documents.Flow.Model.TableRow row = tblContent.Rows.AddTableRow();
                    for (int j = 0; j < 5; j++)
                    {
                        Telerik.Windows.Documents.Flow.Model.TableCell cell = row.Cells.AddTableCell();
                        if (i == 0)
                        {
                            if (j == 0)
                            {
                                currRun = cell.Blocks.AddParagraph().Inlines.AddRun("A/A");
                                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                                currRun.Properties.FontSize.LocalValue   = 15.0;
                                currRun.Properties.FontWeight.LocalValue = FontWeights.Bold;
                                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;
                                cell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 5);
                            }
                            else if (j == 1)
                            {
                                currRun = cell.Blocks.AddParagraph().Inlines.AddRun("ΑΙΤΩΝ");
                                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                                currRun.Properties.FontSize.LocalValue   = 15.0;
                                currRun.Properties.FontWeight.LocalValue = FontWeights.Bold;
                                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;
                                cell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 20);
                            }
                            else if (j == 2)
                            {
                                currRun = cell.Blocks.AddParagraph().Inlines.AddRun("ΑΠΟ");
                                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                                currRun.Properties.FontSize.LocalValue   = 15.0;
                                currRun.Properties.FontWeight.LocalValue = FontWeights.Bold;
                                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;
                                cell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 20);
                            }
                            else if (j == 3)
                            {
                                currRun = cell.Blocks.AddParagraph().Inlines.AddRun("ΩΡΑ");
                                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                                currRun.Properties.FontSize.LocalValue   = 15.0;
                                currRun.Properties.FontWeight.LocalValue = FontWeights.Bold;
                                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;
                                cell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 20);
                            }
                            else if (j == 4)
                            {
                                currRun = cell.Blocks.AddParagraph().Inlines.AddRun("ΠΑΡΑΤΗΡΗΣΕΙΣ");
                                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                                currRun.Properties.FontSize.LocalValue   = 15.0;
                                currRun.Properties.FontWeight.LocalValue = FontWeights.Bold;
                                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;
                                cell.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 35);
                            }
                        }
                        else
                        {
                            if (j == 0)
                            {
                                currRun = cell.Blocks.AddParagraph().Inlines.AddRun(lstDummy.Where(o => o.Count == i).FirstOrDefault().Count.ToString());
                                currRun.Properties.FontFamily.LocalValue = new ThemableFontFamily("Arial");
                                currRun.Properties.FontSize.LocalValue   = 15.0;
                                currRun.Properties.FontWeight.LocalValue = FontWeights.Bold;
                                currRun.Properties.FontStyle.LocalValue  = FontStyles.Normal;
                            }
                            else if (j == 1)
                            {
                                cell.Blocks.AddParagraph().Inlines.AddRun(lstDummy.Where(o => o.Count == i).FirstOrDefault().Customer);
                            }
                            else if (j == 2)
                            {
                                cell.Blocks.AddParagraph().Inlines.AddRun(lstDummy.Where(o => o.Count == i).FirstOrDefault().FromPlace);
                            }
                            else if (j == 3)
                            {
                                cell.Blocks.AddParagraph().Inlines.AddRun(lstDummy.Where(o => o.Count == i).FirstOrDefault().FromTime + " - " + lstDummy.Where(o => o.Count == i).FirstOrDefault().ToTime);
                            }
                            else if (j == 4)
                            {
                                cell.Blocks.AddParagraph().Inlines.AddRun(lstDummy.Where(o => o.Count == i).FirstOrDefault().Comments);
                            }
                        }
                    }
                }
                curDoc.UpdateFields();
                exportDOCX(curDoc);
            }
            catch (Exception ex) { }
        }
        private RadFlowDocument CreateDocument(RadGridView grid)
        {
            List<GridViewBoundColumnBase> columns = (from c in grid.Columns.OfType<GridViewBoundColumnBase>()
                                                     orderby c.DisplayIndex
                                                     select c).ToList();

            RadFlowDocument document = new RadFlowDocument();
            Table table = document.Sections.AddSection().Blocks.AddTable();
            document.StyleRepository.AddBuiltInStyle(BuiltInStyleNames.TableGridStyleId);
            table.StyleId = BuiltInStyleNames.TableGridStyleId;

            int indentColumns = grid.GroupDescriptors.Count;

            // Export header row
            if (grid.ShowColumnHeaders)
            {
                TableRow headerRow = table.Rows.AddTableRow();
                headerRow.RepeatOnEveryPage = this.RepeatHeaderRowOnEveryPage;
                ThemableColor headerBackground = new ThemableColor(this.HeaderRowColor);

                if (grid.GroupDescriptors.Count > 0)
                {
                    this.AddIndentCell(headerRow, indentColumns, headerBackground);
                }

                for (int i = 0; i < columns.Count; i++)
                {
                    TableCell cell = headerRow.Cells.AddTableCell();
                    cell.Shading.BackgroundColor = headerBackground;
                    cell.PreferredWidth = new TableWidthUnit(columns[i].ActualWidth);
                    Run headerRun = cell.Blocks.AddParagraph().Inlines.AddRun(columns[i].UniqueName);
                    headerRun.FontWeight = FontWeights.Bold;
                }
            }

            if (grid.Items.Groups != null)
            {
                int groupDescriptorsCount = grid.GroupDescriptors.Count;
                for (int i = 0; i < grid.Items.Groups.Count; i++)
                {
                    this.AddGroupRow(table, (QueryableCollectionViewGroup)grid.Items.Groups[i], columns, groupDescriptorsCount);
                }
            }
            else
            {
                this.AddDataRows(table, grid.Items, columns, indentColumns);
            }

            document.Sections.First().Blocks.AddParagraph();
            return document;
        }
        private void AddDataRows(Table table, IList items, IList<GridViewBoundColumnBase> columns, int indentColumns)
        {
            ThemableColor background = new ThemableColor(this.DataRowColor);

            for (int i = 0; i < items.Count; i++)
            {
                TableRow row = table.Rows.AddTableRow();

                if (indentColumns > 0)
                {
                    this.AddIndentCell(row, indentColumns, background);
                }

                for (int j = 0; j < columns.Count; j++)
                {
                    TableCell cell = row.Cells.AddTableCell();
                    this.AddCellValue(cell, columns[j].GetValueForItem(items[i]));
                    cell.Shading.BackgroundColor = background;
                    cell.PreferredWidth = new TableWidthUnit(columns[j].ActualWidth);
                }
            }
        }
Пример #20
0
        private static void SetCellProperties(PivotExportCellInfo cellInfo, CellSelection cellSelection)
        {
            var fill = GenerateFill(cellInfo.Background);
            if (fill != null)
            {
                cellSelection.SetFill(fill);
            }

            SolidColorBrush solidBrush = cellInfo.Foreground as SolidColorBrush;
            if (solidBrush != null)
            {
                cellSelection.SetForeColor(new ThemableColor(solidBrush.Color));
            }

            if (cellInfo.FontWeight.HasValue && cellInfo.FontWeight.Value != FontWeights.Normal)
            {
                cellSelection.SetIsBold(true);
            }

            SolidColorBrush solidBorderBrush = cellInfo.BorderBrush as SolidColorBrush;
            if (solidBorderBrush != null && cellInfo.BorderThickness.HasValue)
            {
                var borderThickness = cellInfo.BorderThickness.Value;
                var color = new ThemableColor(solidBorderBrush.Color);
                //var leftBorder = new CellBorder(GetBorderStyle(borderThickness.Left), color);
                //var topBorder = new CellBorder(GetBorderStyle(borderThickness.Top), color);
                var rightBorder = new CellBorder(GetBorderStyle(borderThickness.Right), color);
                var bottomBorder = new CellBorder(GetBorderStyle(borderThickness.Bottom), color);
                var insideBorder = cellInfo.Background != null ? new CellBorder(CellBorderStyle.None, color) : null;
                cellSelection.SetBorders(new CellBorders(null, null, rightBorder, bottomBorder, insideBorder, insideBorder, null, null));
            }
        }
Пример #21
0
        public async Task <byte[]> ExportPdf <T>(IQueryable <T> data, DataSourceRequest gridRequest)
        {
            var workbook = new Workbook();

            workbook.Name = "workbook-1";

            // performance
            workbook.History.IsEnabled = false;
            workbook.SuspendLayoutUpdate();

            workbook.Sheets.Add(SheetType.Worksheet);
            Worksheet worksheet = workbook.ActiveWorksheet;

            var dataResult = await data.ToDataSourceResultAsync(gridRequest);

            List <T> dataToExport = (dataResult.Data as IEnumerable <T>).ToList();

            int currRow = 0;

            Type typeParameterType = typeof(T);
            var  fieldsList        = typeParameterType.GetProperties();

            //some styling for the cells - borders in this example
            ThemableColor black          = new ThemableColor(Telerik.Documents.Media.Color.FromArgb(0, 0, 0, 0));
            CellBorders   desiredBorders = new CellBorders(
                new CellBorder(CellBorderStyle.Medium, black),     // Left border
                new CellBorder(CellBorderStyle.Medium, black),     // Top border
                new CellBorder(CellBorderStyle.Medium, black),     // Right border
                new CellBorder(CellBorderStyle.Medium, black),     // Bottom border
                new CellBorder(CellBorderStyle.Thin, black),       // Inside horizontal border
                new CellBorder(CellBorderStyle.Thin, black),       // Inside vertical border
                new CellBorder(CellBorderStyle.None, black),       // Diagonal up border
                new CellBorder(CellBorderStyle.None, black)        // Diagonal down border
                );

            //column sizes
            for (int i = 0; i < fieldsList.Length; i++)
            {
                worksheet.Columns[i].SetWidth(new ColumnWidth(120, true));
            }

            //automatic resizing is convenient, but comes with some performance hit
            //it would also have to be moved after setting the content
            //for (int i = 0; i < fieldsList.Length; i++)
            //{
            //    worksheet.Columns[i].AutoFitWidth();
            //}

            for (int i = 0; i < fieldsList.Length; i++)
            {
                CellSelection currCell = worksheet.Cells[0, i];
                currCell.SetValue(fieldsList[i].Name);
                currCell.SetBorders(desiredBorders);
            }

            currRow++;


            // content
            for (int i = 0; i < dataToExport.Count; i++)
            {
                for (int columnIndex = 0; columnIndex < fieldsList.Length; columnIndex++)
                {
                    var           cellValue = GetFieldValue(dataToExport[i], fieldsList[columnIndex].Name);
                    CellSelection currCell  = worksheet.Cells[currRow, columnIndex];
                    SetCellValue(currCell, cellValue);
                    currCell.SetBorders(desiredBorders);
                }
                currRow++;
            }

            // performance
            workbook.ResumeLayoutUpdate();

            //convert the excel workbook to a pdf
            var pdfFormatProvider = new Telerik.Windows.Documents.Spreadsheet.FormatProviders.Pdf.PdfFormatProvider();

            byte[] fileBytes = null;
            using (MemoryStream ms = new MemoryStream())
            {
                pdfFormatProvider.Export(workbook, ms);
                fileBytes = ms.ToArray();
            }

            return(await Task.FromResult(fileBytes));
        }