C1Olap for Winforms has a C1OlapPrintDocument component that is used to create reports based on OLAP views. It extends the PrintDocument class and provides properties that allow you to specify content and formatting for showing OLAP grids, charts, and the raw data used to create the report. The C1OlapPanel toolstrip provides Report option to print and preview the reports and also specify options. Though the OlapPage toolstrip provides options for exporting but these options are limited to XLS, XLSX, CSV and TXT formats. Through this blog, we will discuss an approach to export the OlapChart and OlapGrid using C1OlapPrintDocument in following formats :

  1. Rich Text Format
  2. Microsoft Excel
  3. Emf Image
  4. Abode Pdf

Now to start with, we will add Export option in the C1OlapPage toolstrip using the following code. We will modify the Quickstart sample to explain the approach.

// build menu with Export Options  
var menuExport = new ToolStripDropDownButton("&Export", Properties.Resources.Views_small);  
foreach (XmlNode nd in doc.SelectNodes("OlapExport/Export"))  
{  
       var tsi = menuExport.DropDownItems.Add(nd.Attributes["name"].Value);  
       tsi.Tag = nd.Attributes["type"].Value;  
}  
menuExport.DropDownItemClicked += MenuExport_DropDownItemClicked;  

// add the new export menu to the toolstrip  
_c1OlapPage.ToolStrip.Items.Insert(11, menuExport);

The Document property of C1OlapPage provides the C1OlapPrintDocument object. To export both the olap grid and chart, we need to set the ShowChart and ShowGrid properties of OlapPage.Document to True. We can also specify PrinterSettings, Footer setting etc. To provide the exporting features, we need to add reference to C1.Report.x.dll reference to the project, where x is 2 or 4 depending on the framework version. When user selects any menu item from the Export menu, object of that C1.C1Preview.Export.Exporter class is created and the Olap Document object is passed to the Exporter.Document property. The C1.C1Preview.Export namespace provides different exporter classes that can be used to export olap document to different formats. For example, if Rich Text Format option is selected, following code is used :

RtfExporter rtfExporter = new C1.C1Preview.Export.RtfExporter();  
rtfExporter.Paginated = true;  
rtfExporter.Document = _c1OlapPage.Document;  
rtfExporter.ShowOptions = false;  
saveDialog.Filter = "RTF File (*.rtf)|*.rtf";  
if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)  
{  
       rtfExporter.Export(saveDialog.FileName);  
}

For more information, see the ComponentOne Reports for WinForms documentation. Download the sample for complete code. Download Sample