Exporting in WPF Olap Client
6 May 202113 minutes to read
When creating an OLAP report in the OLAP client, the report will be visualized in the OLAP chart and OLAP grid. The OLAP client has an option to export the current view of the OLAP chart and OLAP grid to various forms.
Exporting OLAP chart
The current view of the OLAP chart can be exported to Microsoft Word, PDF, and image and printed as well.
You can perform these exports in two ways:
- Through OLAP chart toolbar.
- Through API’s.
Through OLAP chart toolbar menu
By clicking the respective icons in the OLAP chart toolbar, You can export the OLAP chart to the corresponding mode.
Icon | Name | Description |
---|---|---|
Export to Image | Export the current view of the OLAP chart as image | |
Export to Word | Export the current view of the OLAP chart to a Word document. | |
Export to PDF | Export the current view of the OLAP chart to PDF. | |
Print the current view of the OLAP chart. |
Through API
You can achieve the export feature of OLAP chart by using the following API’s. The following code sample illustrates exporting the OLAP chart into corresponding format.
Word export
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "OlapChart Report";
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "doc";
saveFileDialog.Filter = "Word (.doc)|*.doc";
if (saveFileDialog.ShowDialog() == true)
{
string fileName = saveFileDialog.FileName;
OlapChartWordExport olapChartWordExport = new OlapChartWordExport(this.olapChart);
olapChartWordExport.ExportintoNewDoc(fileName);
}
Dim saveFileDialog As SaveFileDialog()
saveFileDialog.FileName = "OlapChart Report"
saveFileDialog.AddExtension = True
saveFileDialog.DefaultExt = "doc"
saveFileDialog.Filter = "Word (.doc)|*.doc"
If saveFileDialog.ShowDialog() = True Then
Dim fileName As String = saveFileDialog.FileName
Dim olapChartWordExport As New OlapChartWordExport(Me.olapChart)
olapChartWordExport.ExportintoNewDoc(fileName)
End If
PDF export
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "OlapChart Report";
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "pdf";
saveFileDialog.Filter = "PDF (.pdf)|*.pdf";
if (saveFileDialog.ShowDialog() == true)
{
string fileName = saveFileDialog.FileName;
OlapChartPdfExport chartPdfExport = new OlapChartPdfExport(this.olapChart);
chartPdfExport.ExportIntoNewPdf(fileName);
}
Dim saveFileDialog As SaveFileDialog()
saveFileDialog.FileName = "OlapChart Report"
saveFileDialog.AddExtension = True
saveFileDialog.DefaultExt = "pdf"
saveFileDialog.Filter = "PDF (.pdf)|*.pdf"
If saveFileDialog.ShowDialog() = True Then
Dim fileName As String = saveFileDialog.FileName
Dim olapChartPdfExport As New OlapChartPdfExport(Me.olapChart)
olapChartPdfExport.ExportIntoNewPdf(fileName)
End If
Image export
private const string c_imageFilesFilter = "Bitmap(*.bmp)|*.bmp|JPEG(*.jpg,*.jpeg)|*.jpg;*.jpeg|GIF(*.gif)|*.gif|TIFF(*.tiff)|*.tiff|PNG(*.png)|*.png|WDP(*.wdp)|*.wdp|All files (*.*)|*.*";
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "OlapChart Report";
saveFileDialog.Filter = c_imageFilesFilter;
if (saveFileDialog.ShowDialog() == true)
{
string fileName = saveFileDialog.FileName;
string extension = new FileInfo(fileName).Extension.ToLower(CultureInfo.InvariantCulture);
if (c_imageFilesFilter.Contains(extension))
{
using (Stream stream = File.Create(saveFileDialog.FileName))
{
BitmapEncoder encoder = Chart.CreateBitmapEncoderByExtension(extension);
RenderTargetBitmap bmpSource = new RenderTargetBitmap((int)chart.ActualWidth, (int)chart.ActualHeight, 96, 96, PixelFormats.Default);
Rectangle backgroundRect = new Rectangle();
backgroundRect.Fill = Brushes.White;
backgroundRect.Arrange(new Rect(chart.RenderSize));
bmpSource.Render(backgroundRect);
bmpSource.Render(visual);
encoder.Frames.Add(BitmapFrame.Create(bmpSource));
encoder.Save(stream);
}
}
}
Dim c_imageFilesFilter As String = "Bitmap(*.bmp)|*.bmp|JPEG(*.jpg,*.jpeg)|*.jpg;*.jpeg|GIF(*.gif)|*.gif|TIFF(*.tiff)|*.tiff|PNG(*.png)|*.png|WDP(*.wdp)|*.wdp|All files (*.*)|*.*"
Dim saveFileDialog As SaveFileDialog()
saveFileDialog.FileName = "OlapChart Report"
saveFileDialog.Filter = c_imageFilesFilter;
If saveFileDialog.ShowDialog() = True Then
Dim extension As String = New FileInfo(fileName).Extension.ToLower(CultureInfo.InvariantCulture);
Dim fileName As String = saveFileDialog.FileName
If c_imageFilesFilter.Contains(extension) Then
Using stream As Stream = File.Create(saveFileDialog.FileName)
Dim encoder As BitmapEncoder = Chart.CreateBitmapEncoderByExtension(extension)
Dim bmpSource As New RenderTargetBitmap(CInt(chart.ActualWidth), CInt(chart.ActualHeight), 96, 96, PixelFormats.[Default])
Dim backgroundRect As New Rectangle()
backgroundRect.Fill = Brushes.White
backgroundRect.Arrange(New Rect(chart.RenderSize))
bmpSource.Render(backgroundRect);
bmpSource.Render(visual);
encoder.Frames.Add(BitmapFrame.Create(bmpSource));
encoder.Save(stream);
End Using
End If
End If
Exporting OLAP grid
The current view of the OLAP grid can be exported to the following forms:
- Microsoft Word
- Microsoft Excel
- CSV
The user can perform these exports in two ways:
- Through OLAP grid toolbar.
- Through API’s.
Through OLAP grid toolbar menu
By clicking the respective export buttons in the OLAP grid toolbar, the user can export OLAP grid to the corresponding format.
Icon | Name | Description |
---|---|---|
Export to Excel | Export the OLAP grid to an Excel document. | |
Export to Word | Export the OLAP grid to a Word document. | |
Export to PDF | Export the OLAP grid to a PDF document. | |
Export to CSV | Export the OLAP grid to a CSV document. |
Through API
You can achieve the export feature of OLAP grid by using the following API’s. The following code sample illustrates exporting the OLAP grid into corresponding format.
Excel export
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "OlapGrid Report";
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "xlsx";
saveFileDialog.Filter = "Excel (.xlsx)|*.xlsx";
if (saveFileDialog.ShowDialog() == true)
{
string fileName = saveFileDialog.FileName;
GridExcelExport excelExport = new GridExcelExport(this.olapGrid.InternalGrid.Engine, this.olapGrid.GridStyleInfo, this.olapGrid.InternalGrid.Layout, saveFileDialog.DefaultExt, this.olapGrid.OlapDataManager.ItemSource == null ? false : true);
excelExport.Export(fileName);
}
Dim saveFileDialog As SaveFileDialog()
saveFileDialog.FileName = "OlapGrid Report"
saveFileDialog.AddExtension = True
saveFileDialog.DefaultExt = "xlsx"
saveFileDialog.Filter = "Excel (.xlsx)|*.xlsx"
If saveFileDialog.ShowDialog() = True Then
Dim fileName As String = saveFileDialog.FileName
Dim excelExport As New GridExcelExport(Me.olapGrid.InternalGrid.Engine, Me.olapGrid.GridStyleInfo, Me.olapGrid.InternalGrid.Layout, saveFileDialog.DefaultExt, Me.olapGrid.OlapDataManager.ItemSource == null ? False : True)
excelExport.Export(fileName)
End If
Word export
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "OlapGrid Report";
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "doc";
saveFileDialog.Filter = "Word (.doc)|*.doc";
if (saveFileDialog.ShowDialog() == true)
{
string fileName = saveFileDialog.FileName;
GridWordExport gridWordExport = new GridWordExport(this.olapGrid.InternalGrid.Engine, this.olapGrid.InternalGrid.Layout);
gridWordExport.Export(fileName, this.olapGrid.GridStyleInfo);
}
Dim saveFileDialog As SaveFileDialog()
saveFileDialog.FileName = "OlapGrid Report"
saveFileDialog.AddExtension = True
saveFileDialog.DefaultExt = "doc"
saveFileDialog.Filter = "Word (.doc)|*.doc"
If saveFileDialog.ShowDialog() = True Then
Dim fileName As String = saveFileDialog.FileName
Dim gridWordExport As New GridWordExport(Me.olapGrid.InternalGrid.Engine, Me.olapGrid.InternalGrid.Layout)
gridWordExport.Export(fileName, Me.olapGrid.GridStyleInfo)
End If
PDF export
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "OlapGrid Report";
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "pdf";
saveFileDialog.Filter = "PDF (.pdf)|*.pdf";
if (saveFileDialog.ShowDialog() == true)
{
string fileName = saveFileDialog.FileName;
GridPdfExport gridPdfExport = new GridPdfExport(this.olapGrid.InternalGrid.Engine, this.olapGrid.GridStyleInfo);
gridPdfExport.Export(fileName);
}
Dim saveFileDialog As SaveFileDialog()
saveFileDialog.FileName = "OlapGrid Report"
saveFileDialog.AddExtension = True
saveFileDialog.DefaultExt = "pdf"
saveFileDialog.Filter = "PDF (.pdf)|*.pdf"
If saveFileDialog.ShowDialog() = True Then
Dim fileName As String = saveFileDialog.FileName
Dim gridPdfExport As New GridPdfExport(Me.olapGrid.InternalGrid.Engine, Me.olapGrid.GridStyleInfo)
gridPdfExport.Export(fileName)
End If
CSV export
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = "OlapGrid Report";
saveFileDialog.AddExtension = true;
saveFileDialog.DefaultExt = "csv";
saveFileDialog.Filter = "CSV (.csv)|*.csv";
if (saveFileDialog.ShowDialog() == true)
{
string fileName = saveFileDialog.FileName;
GridCsvExport gridCsvExport = new GridCsvExport(this.olapGrid.InternalGrid.Engine);
gridCsvExport.Export(fileName);
}
Dim saveFileDialog As SaveFileDialog()
saveFileDialog.FileName = "OlapGrid Report"
saveFileDialog.AddExtension = True
saveFileDialog.DefaultExt = "csv"
saveFileDialog.Filter = "CSV (.csv)|*.csv"
If saveFileDialog.ShowDialog() = True Then
Dim fileName As String = saveFileDialog.FileName
Dim gridCsvExport As New GridCsvExport(Me.olapGrid.InternalGrid.Engine)
gridCsvExport.Export(fileName)
End If