private static Workbook GenerateWorkbook(RadPivotGrid pivot) { var export = pivot.GenerateExport(); Workbook workbook = new Workbook(); workbook.History.IsEnabled = false; var worksheet = workbook.Worksheets.Add(); workbook.SuspendLayoutUpdate(); int rowCount = export.RowCount; int columnCount = export.ColumnCount; var allCells = worksheet.Cells[0, 0, rowCount - 1, columnCount - 1]; allCells.SetFontFamily(new ThemableFontFamily(pivot.FontFamily)); allCells.SetFontSize(12); allCells.SetFill(GenerateFill(pivot.Background)); foreach (var cellInfo in export.Cells) { int rowStartIndex = cellInfo.Row; int rowEndIndex = rowStartIndex + cellInfo.RowSpan - 1; int columnStartIndex = cellInfo.Column; int columnEndIndex = columnStartIndex + cellInfo.ColumnSpan - 1; CellSelection cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex]; var value = cellInfo.Value; if (value != null) { cellSelection.SetValue(Convert.ToString(value)); cellSelection.SetVerticalAlignment((Telerik.Windows.Documents.Spreadsheet.Model.RadVerticalAlignment)RadVerticalAlignment.Center); cellSelection.SetHorizontalAlignment(GetHorizontalAlignment(cellInfo.TextAlignment)); int indent = cellInfo.Indent; if (indent > 0) { cellSelection.SetIndent(indent); } } cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex, rowEndIndex, columnEndIndex]; SetCellProperties(cellInfo, cellSelection); } for (int i = 0; i < columnCount; i++) { var columnSelection = worksheet.Columns[i]; columnSelection.AutoFitWidth(); //NOTE: workaround for incorrect autofit. var newWidth = worksheet.Columns[i].GetWidth().Value.Value + 15; columnSelection.SetWidth(new ColumnWidth(newWidth, false)); } workbook.ResumeLayoutUpdate(); return(workbook); }
public static void ExportPivotToExcel(RadPivotGrid pivot) { SaveFileDialog dialog = new SaveFileDialog(); dialog.DefaultExt = "xlsx"; // dialog.Filter = "CSV files (*.csv)|*.csv |All Files (*.*) | *.*"; var result = dialog.ShowDialog(); if ((bool)result) { try { using (var stream = dialog.OpenFile()) { var workbook = GenerateWorkbook(pivot); // IWorkbookFormatProvider formatProvider = new CsvFormatProvider(); //formatProvider.Export(workbook, stream); XlsxFormatProvider provider = new XlsxFormatProvider(); provider.Export(workbook, stream); } } catch (IOException ex) { MessageBox.Show(ex.Message); } } }
public Form1() { this.InitializeComponent(); this.radPivotGrid1 = new RadPivotGrid(); this.radPivotGrid1.Dock = DockStyle.Fill; this.Controls.Add(this.radPivotGrid1); }
public Form1() { InitializeComponent(); this.pivot = new RadPivotGrid(); this.pivot.Dock = DockStyle.Fill; this.Controls.Add(this.pivot); }
private RadFixedDocument CreateDocument(RadPivotGrid element) { RadFixedDocument document = new RadFixedDocument(); RadFixedPage page = this.CreatePage(element); document.Pages.Add(page); return(document); }
private RadFixedPage CreatePage(RadPivotGrid element) { RadFixedPage page = new RadFixedPage(); page.Size = new Size(1000, 1000); FixedContentEditor editor = new FixedContentEditor(page, Telerik.Windows.Documents.Fixed.Model.Data.MatrixPosition.Default); ExportHelper.ExportToPdf(element, editor); return(page); }
public Form1() { InitializeComponent(); this.radPivotGrid1 = new RadPivotGrid(); this.radPivotGrid1.Dock = DockStyle.Fill; this.radPivotGrid1.PivotGridElement.ShowFilterArea = true; this.Controls.Add(this.radPivotGrid1); this.FillWithData(); }
public Form1() { InitializeComponent(); this.radPivotGrid1 = new RadPivotGrid(); this.radPivotGrid1.ColumnWidth = 110; this.radPivotGrid1.Dock = DockStyle.Fill; this.radPrintDocument1 = new RadPrintDocument(); this.radPrintDocument1.AssociatedObject = this.radPivotGrid1; this.Controls.Add(this.radPivotGrid1); }
public static void ExportPivotToPdf(RadPivotGrid pivot, params string[] titles) { var filePath = Path.GetTempFileName().Replace(".tmp", ".pdf"); RadDocument document = GenerateRadDocument(pivot); var documentHeader = CreateHeader(titles); document.Sections.First.Headers.Default = new Header() { Body = documentHeader }; var provider = new PdfFormatProvider(); using (Stream stream = new FileStream(filePath, FileMode.Create)) { provider.Export(document, stream); } Process.Start(filePath); }
private static Workbook GenerateWorkbook(RadPivotGrid pivot) { var export = pivot.GenerateExport(); Workbook workbook = new Workbook(); workbook.History.IsEnabled = false; var worksheet = workbook.Worksheets.Add(); workbook.SuspendLayoutUpdate(); int rowCount = export.RowCount; int columnCount = export.ColumnCount; var allCells = worksheet.Cells[0, 0, rowCount - 1, columnCount - 1]; allCells.SetFontFamily(new ThemableFontFamily(pivot.FontFamily)); allCells.SetFontSize(12); allCells.SetFill(GenerateFill(pivot.Background)); foreach (var cellInfo in export.Cells) { int rowStartIndex = cellInfo.Row; int rowEndIndex = rowStartIndex + cellInfo.RowSpan - 1; int columnStartIndex = cellInfo.Column; int columnEndIndex = columnStartIndex + cellInfo.ColumnSpan - 1; CellSelection cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex]; var value = cellInfo.Value; if (value != null) { cellSelection.SetValue(Convert.ToString(value)); cellSelection.SetVerticalAlignment((Telerik.Windows.Documents.Spreadsheet.Model.RadVerticalAlignment) RadVerticalAlignment.Center); cellSelection.SetHorizontalAlignment(GetHorizontalAlignment(cellInfo.TextAlignment)); int indent = cellInfo.Indent; if (indent > 0) { cellSelection.SetIndent(indent); } } cellSelection = worksheet.Cells[rowStartIndex, columnStartIndex, rowEndIndex, columnEndIndex]; SetCellProperties(cellInfo, cellSelection); } for (int i = 0; i < columnCount; i++) { var columnSelection = worksheet.Columns[i]; columnSelection.AutoFitWidth(); //NOTE: workaround for incorrect autofit. var newWidth = worksheet.Columns[i].GetWidth().Value.Value + 15; columnSelection.SetWidth(new ColumnWidth(newWidth, false)); } workbook.ResumeLayoutUpdate(); return workbook; }
private static RadDocument GenerateRadDocument(RadPivotGrid pivot) { var export = pivot.GenerateExport(); int rowCount = export.RowCount; int columnCount = export.ColumnCount; RadDocument document = new RadDocument(); document.SectionDefaultPageMargin = new Padding(10); document.LayoutMode = DocumentLayoutMode.Paged; document.SectionDefaultPageOrientation = PageOrientation.Landscape; document.Style.SpanProperties.FontFamily = pivot.FontFamily; document.Style.SpanProperties.FontSize = pivot.FontSize; document.Style.ParagraphProperties.SpacingAfter = 0; var section = new Section(); document.Sections.Add(section); section.Blocks.Add(new Paragraph()); var table = new Table(rowCount, columnCount); section.Blocks.Add(table); var tableRows = table.Rows.ToArray(); foreach (var cellInfo in export.Cells) { int rowStartIndex = cellInfo.Row; int rowEndIndex = rowStartIndex + cellInfo.RowSpan - 1; int columnStartIndex = cellInfo.Column; int columnEndIndex = columnStartIndex + cellInfo.ColumnSpan - 1; var value = cellInfo.Value; var text = Convert.ToString(value); if (!string.IsNullOrWhiteSpace(text)) { var cells = tableRows[rowStartIndex].Cells.ToArray(); var cell = cells[columnStartIndex]; Paragraph paragraph = new Paragraph(); cell.Blocks.Add(paragraph); var span = new Span(text); paragraph.Inlines.Add(span); paragraph.TextAlignment = GetTextAlignment(cellInfo.TextAlignment); if (cellInfo.FontWeight.HasValue) { span.FontWeight = cellInfo.FontWeight.Value; } Color foreColor; if (GetColor(cellInfo.Foreground, out foreColor)) { span.ForeColor = foreColor; } cell.VerticalAlignment = GetVerticalAlignment(cellInfo.VerticalAlignment); paragraph.LeftIndent = cellInfo.Indent * 20; } var borderThickness = cellInfo.BorderThickness; var borderBrush = cellInfo.BorderBrush; var background = cellInfo.Background; Color backColor; bool hasBackground = GetColor(cellInfo.Background, out backColor); if (cellInfo.RowSpan > 1 && cellInfo.ColumnSpan > 1) { for (int k = rowStartIndex; k <= rowEndIndex; k++) { var cells = tableRows[k].Cells.ToArray(); for (int j = columnStartIndex; j <= columnEndIndex; j++) { var cell = cells[j]; if (hasBackground) { cell.Background = backColor; } cell.Borders = GetCellBorders(borderThickness, borderBrush, cell.Borders, k, rowStartIndex, rowEndIndex, j, columnStartIndex, columnEndIndex, hasBackground); } } } else if (cellInfo.RowSpan > 1) { for (int j = rowStartIndex; j <= rowEndIndex; j++) { // TODO: check when ColumnSpan > 1; var cell = tableRows[j].Cells.ToArray()[columnStartIndex]; Position position = j == rowStartIndex ? Position.First : ((j == rowEndIndex) ? Position.Last : Position.Middle); cell.Borders = GetCellBorders(borderThickness, borderBrush, position, cell.Borders, true, cellInfo.Background != null); if (hasBackground) { cell.Background = backColor; } } } else if (cellInfo.ColumnSpan > 1) { var cells = tableRows[rowStartIndex].Cells.ToArray(); for (int j = columnStartIndex; j <= columnEndIndex; j++) { // TODO: check when RowSpan > 1; var cell = cells[j]; Position position = j == columnStartIndex ? Position.First : ((j == columnEndIndex) ? Position.Last : Position.Middle); if (hasBackground) { cell.Background = backColor; } cell.Borders = GetCellBorders(borderThickness, borderBrush, position, cell.Borders, false, hasBackground); } } } return(document); }
private static RadDocument GenerateRadDocument(RadPivotGrid pivot) { var export = pivot.GenerateExport(); int rowCount = export.RowCount; int columnCount = export.ColumnCount; RadDocument document = new RadDocument(); document.SectionDefaultPageMargin = new Padding(10); document.LayoutMode = DocumentLayoutMode.Paged; document.SectionDefaultPageOrientation = PageOrientation.Landscape; document.Style.SpanProperties.FontFamily = pivot.FontFamily; document.Style.SpanProperties.FontSize = pivot.FontSize; document.Style.ParagraphProperties.SpacingAfter = 0; var section = new Section(); document.Sections.Add(section); section.Blocks.Add(new Paragraph()); var table = new Table(rowCount, columnCount); section.Blocks.Add(table); var tableRows = table.Rows.ToArray(); foreach (var cellInfo in export.Cells) { int rowStartIndex = cellInfo.Row; int rowEndIndex = rowStartIndex + cellInfo.RowSpan - 1; int columnStartIndex = cellInfo.Column; int columnEndIndex = columnStartIndex + cellInfo.ColumnSpan - 1; var value = cellInfo.Value; var text = Convert.ToString(value); if (!string.IsNullOrWhiteSpace(text)) { var cells = tableRows[rowStartIndex].Cells.ToArray(); var cell = cells[columnStartIndex]; Paragraph paragraph = new Paragraph(); cell.Blocks.Add(paragraph); var span = new Span(text); paragraph.Inlines.Add(span); paragraph.TextAlignment = GetTextAlignment(cellInfo.TextAlignment); if (cellInfo.FontWeight.HasValue) { span.FontWeight = cellInfo.FontWeight.Value; } Color foreColor; if (GetColor(cellInfo.Foreground, out foreColor)) { span.ForeColor = foreColor; } cell.VerticalAlignment = GetVerticalAlignment(cellInfo.VerticalAlignment); paragraph.LeftIndent = cellInfo.Indent * 20; } var borderThickness = cellInfo.BorderThickness; var borderBrush = cellInfo.BorderBrush; var background = cellInfo.Background; Color backColor; bool hasBackground = GetColor(cellInfo.Background, out backColor); if (cellInfo.RowSpan > 1 && cellInfo.ColumnSpan > 1) { for (int k = rowStartIndex; k <= rowEndIndex; k++) { var cells = tableRows[k].Cells.ToArray(); for (int j = columnStartIndex; j <= columnEndIndex; j++) { var cell = cells[j]; if (hasBackground) { cell.Background = backColor; } cell.Borders = GetCellBorders(borderThickness, borderBrush, cell.Borders, k, rowStartIndex, rowEndIndex, j, columnStartIndex, columnEndIndex, hasBackground); } } } else if (cellInfo.RowSpan > 1) { for (int j = rowStartIndex; j <= rowEndIndex; j++) { // TODO: check when ColumnSpan > 1; var cell = tableRows[j].Cells.ToArray()[columnStartIndex]; Position position = j == rowStartIndex ? Position.First : ((j == rowEndIndex) ? Position.Last : Position.Middle); cell.Borders = GetCellBorders(borderThickness, borderBrush, position, cell.Borders, true, cellInfo.Background != null); if (hasBackground) { cell.Background = backColor; } } } else if (cellInfo.ColumnSpan > 1) { var cells = tableRows[rowStartIndex].Cells.ToArray(); for (int j = columnStartIndex; j <= columnEndIndex; j++) { // TODO: check when RowSpan > 1; var cell = cells[j]; Position position = j == columnStartIndex ? Position.First : ((j == columnEndIndex) ? Position.Last : Position.Middle); if (hasBackground) { cell.Background = backColor; } cell.Borders = GetCellBorders(borderThickness, borderBrush, position, cell.Borders, false, hasBackground); } } } return document; }