Search
English
TOLAPExport control FAQ

Export FAQ

Data received with the help of the RadarCubeLibrary components can be previewed and printed out, or exported to one of the common formats.
Most export functions are connected to the TOLAPExportBase type (or its heir TOLAPExport).

Setting the Visual Properties

You can find the visual properties in the Options property of the TOLAPExportBase export component. It contains a set of properties for setting all types of cell appearances, export parameters and printing.

Example:
Setting a few visual properties.

TExportOptions options = GridTable.OLAPExport.Options;
TFormatOptionsPDF optionspdf = GridTable.OLAPExport.OptionsPDF;

options.Title = "Sample";

options.Background = Color.LightSkyBlue;
options.CellGroupView.Background = Color.LightCyan;
options.CellDataTotalView.Background = Color.LightYellow;
options.CellMemberTotalView.Font = new Font("Arial", 20f, FontStyle.Italic);

optionspdf.Header.ForeColor = Color.Blue;

optionspdf.PageNumber.ForeColor = Color.Gray;
optionspdf.PageNumber.NumberFormat = "page {0} (Total {1})";
optionspdf.PageNumber.AlignText = StringAlignment.Center;
optionspdf.PageNumber.Font = new Font("Arial", 18f);
optionspdf.Indent = 20;

Note
In general, the visual settings of the exported elements do not directly depend on the corresponding Grid elements, only the basic properties are copied. To set a Grid-like skin, you need to assign the TOLAPExportBase.Skin property.

Using a Stand-Alone Component

TOLAPExport contains all the elements needed for exporting the Grid data. It is convenient to use if you have a number of Grids, whose data have to be exported with same settings.
To use a stand-alone mode, you need to assign the name of the Grid to its Grid property. After that, you can call the export procedures.

Example:
Exporting through a stand-alone component.

TOLAPExport export = new TOLAPExport();

// exporting data of Grid1
export.Grid = Grid1;
export.ExportTo("file1", TConvertType.ctTIFF);

// exported data of Grid2
export.Grid = Grid2;
export.ExportTo("file2", TConvertType.ctTIFF);

Note:
You don’t have to specify the file extension, it you’re exporting data into a file – it will be set automatically.

Using an In-built Component

The Grid has an in-built component for export. It allows exporting data, setting and saving export parameters right in the Grid. However, if there are a few Grids in your attachment, you’d better use a stand-alone component TOLAPExport (that means, you need to assign the TOLAPExport.Grid property before exporting).

Example:
Setting the parameters and exporting with the in-built component.

Grid.OLAPExport.OptionsPDF.Header.ForeColor = Color.Red;
Grid.OLAPExport.OptionsPDF.Header.Header = "My title";
Grid.OLAPExport.Options.CellDataTotalView.Background = Color.SkyBlue;
Grid.OLAPExport.Options.PageOrientation = TPageOrientation.poLandscape;
Grid.OLAPExport.ExportTo("file1", TConvertType.ctTIFF);

Note:
You can call the export methods by overriding the TOLAPControlGeneral.ExportTo method:

Grid.ExportTo("file1", TConvertType.ctTIFF);
Grid.ExportTo("file2”, TConvertType.ctXLS);

Changing Column Width

You can change the recommended column width through the OLAPExport.OnGetPreferredWidth event handler. The recommended and the minimal width are passed as parameters of the event argument. When you choose the desired width, note that you may allow the word hyphenation (the OLAPExport.Options.WordHyphenation property).

// init code
Grid.OLAPExport.OnGetPreferredWidth += OnGetPreferredWidthHandler;

void OnGetPreferredWidthHandler(object sender, TEventGetPreferredWidthArgs e)
{
    // decrease if possible to a half of the recommended width.
    e.Width = Math.Max(e.MinimumWidth, e.Width / 2);
}

Understanding Export into csv

When exporting into comma separated value” format, you can specify the separator symbol.

// specifying the tabulation symbol as separator
Grid.OLAPExport.OptionsCSV = '\t';

Understanding Export into html

When exporting into html format, you can set some parameters of the new file: cell padding, coding, document header. Note that exporting TOLAPChart component’s data into a stream is forbidden. Upon exporting into a file, the component creates a catalogue <FileName>.files with the images of charts and axes, and places it to the catalogue, where the file is exported to.
The TOLAPGrid component supports exporting both into a stream and into a file.

Understanding Export into PDF

PDF format is the only one that supports page breaking. In the settings, you can specify the header, page number and the visual settings of these lines.

// Getting a reference to the “export into PDF” setting class
TFormatOptionsPDF optionspdf = Grid.OLAPExport.OptionsPDF;
  
// setting page header
optionspdf.Header.Header = "PDF Title";
optionspdf.Header.AlignText = StringAlignment.Far;
  
// setting page number format
optionspdf.PageNumber.NumberFormat = "PDF page{0} from {1}";
optionspdf.PageNumber.AlignText = StringAlignment.Center;
  
// indent for atypical hierarchy
optionspdf.Indent = 20;

When exporting into PDF, the font file is built into the PDF file, but in some cases, a application may not be authorized to read this file (the SecurityException). Then you need to override the event, specifying the name of the needed font file in the event handler.

// init code
Grid.OLAPExport.OnGetFontFile += OnGetFontFileHandler;
  
void OnGetFontFileHandler(object sender, TEventGetFontFileArgs e)
{
    if (e.Font.Name.Contains("Arial"))
        e.FileName = @"C:\WINDOWS\Fonts\arial.ttf";
    else
        e.FileName = @"C:\WINDOWS\Fonts\comic.ttf";
}

Understanding Export into XLS

The settings of export into XLS allow you to make additional changes in formatting cell text.

Grid.OLAPExport.OnGetXlsFormat += OLAPExport_OnGetXlsFormat;
TFormatOptionsXLS optionsxls = GridTable.OLAPExport.OptionsXLS;
optionsxls.MergeCell = true;
optionsxls.NumberFormat = "#0,00";
optionsxls.PercentFormat = "#0,00%";
optionsxls.WorkSheetNameFormat = "Workbook {0}";
optionsxls.FormatData = "0.00";

void OnGetXlsFormatHandler(object sender, TEventGetXlsFormatArgs e)
{
    if (e.Cell == null)
        return;
    switch (e.Cell.CellType)
    {
        case TCellType.ctData:
            if (e.Value is double)
                e.Format = "0";
            else
                e.Format = string.Empty;
            break;
        case TCellType.ctMember:
            e.CellStyle.ShrinkToFit = true;
            e.CellStyle.HorizontalAlignment = HorizontalAlignmentStyle.CenterAcross;
            e.CellStyle.VerticalAlignment = VerticalAlignmentStyle.Center;
            e.CellStyle.NumberFormat = "0";

            break;
    }

Understanding Export Events

OnEventExportCell event handler allows you to re-define the properties of the exported cells. The OnExportEnd event is fired upon finishing export.

private void olapExport_OnEventExportCell(object sender, TEventExportCellArgs e)
{
    // if the cell is from data area
    if (e.Cell.CellType == TCellType.ctData)
    {
        // encircle it with brockets
        e.Text = "<" + e.Text + ">";
        // change the background color
        e.BackColor = Color.Aqua;
    }
}
private void olapExport_OnExportEnd(object sender, EventArgs e)
{
    MessageBox.Show("Export finished!");
}


Export Settings Window

If you need, you can call the Export Settings window programmatically. It’s a common window for export, print preview and print. Through it you can set cell appearance, print settings, page size and orientation, page header and page number format.

Example:
Calling the dialogue window for changing the settings

// using an in-built component Grid.OLAPExport.ShowSettings();

// Using a stand-alone component
TOLAPExport export = new TOLAPExport();
export.Grid = Grid;
export.ShowSettings();

Print Preview

In the component, there is an option to call print preview programmatically. So, you can see what the cells in your Grid look like and where the page breaks are. All the print and export options are available in the print preview window.

Example:
Calling the Grid’s print preview window

// using an in-built component Grid.OLAPExport.Preview(); // using a stand-alone component TOLAPExport export = new TOLAPExport(); export.Grid = Grid; export.Preview();

Print

The component provides you the options of program calling the Print window and export options of the Grid data into stream array.
When exporting into a stream array, a separate stream is created for every page, with the exception of PDF format, that supports multi-page documents, thus for PDF the result will be a single-stream array.
By default, all data are exported into GIF format with the resolution of 72 dpi. The resolution is taken into account only for graphic formats. To specify other types of formats and resolutions, use the overridden versions of the ToStreams function.

Example:
Calling the Print dialogue window

// using an in-built component
Grid.OLAPExport.Print();

// using a stand-alone component
TOLAPExport export = new TOLAPExport();
export.Grid = Grid;
export.Print();

Example:
Saving Grid data to a stream array into the specified format

TConvertType convert = TConvertType.ctBMP;
TOLAPExportBase export = Grid.OLAPExport;

// getting a stream array for the document, divided into pages
// with a 300 DPI resolution
MemoryStream[] ms = export.ToStreams(convert, TPrintResolution.pr300);

int index = 0;
foreach (MemoryStream memorystream in ms)
{
    // saving a stream into a file on C disk:
    FileStream fs = null;
    try
    {
        string nameonly = string.Format(
"C:\\Export part {0}.{1}",
Index++, convert.Extention);
        fs = new FileStream(nameonly, FileMode.Create);
        byte[] bytes = memorystream.ToArray();
        fs.Write(bytes, 0, bytes.Length);
    }
    finally
    {
        fs.Close();
    }
}

Related links

Download Radar-Soft products


Buy Radar-Soft products


Visit our support site


Hot news
Click to subscribe

 July 22, 2010

RadarCube for WPF beta is here

The new RadarCube for WPF version has started.

Details...

 

Latest versions
Click to subscribe

 July 14, 2010

RadarCube ASP.NET 2.44.3

Changes...Download...

 

 June 25, 2010

RadarCube WinForms Desktop 2.31.0

Changes...Download...

 

 June 25, 2010

RadarCube WinForms MSAS 2.31.0

Changes...Download...

 

 May 20, 2010

RadarCube VCL 1.18.0

Changes...Download...

 

 April 22, 2010

HierCube VCL 4.56.0

Changes...Download...

 

 July 15, 2009

Essential Pack Pro for ASP.NET 1.11.0

Changes...Download...

 

 July 15, 2009

Essential Pack for ASP.NET 1.11.0

Changes...Download...

 

 November 5, 2008

WinForms Chart 1.00.1

Changes...Download...

 

Related articles
Click to subscribe

 May 5, 2010

New Silverlight add-on for RadarCube ASP.NET

Details...

 

 March 30, 2010

Designing the Cube with the Cube Creation Wizard

Details...

 

 December 16, 2009

Creating custom Time Intelligence

Details...

 

 November 26, 2009

Creating the correct Cube structure

Details...

 

 September 30, 2009

RadarCube Request tracker

Details...

 

 August 24, 2009

Customizing the toolbox in Ria OLAP controls

Details...
More articles...
Support | Download | Purchase | Partners | Upgrade and Discount Policy | Contacts © 2005-2010 Radar-Soft, L.L.C. All rights reserved.