CompletIT Community Server

Welcome to CompletIT Community Server Sign in | Join | Help

Code Sample: Exporting DataGridView control contents to MSExcel using the DGV Extension

  •  08-31-2007, 1:59 AM

    Code Sample: Exporting DataGridView control contents to MSExcel using the DGV Extension

    It is possible to use separately the export functionality to MSExcel provided by DataGridView Extension. There are some simple steps outlined below you have to follow.

    1. Add reference to the main assembly ‘DataGridViewExtension.dll’ and export dll ‘DGVEExcelExporting.dll’. The assemblies can be found in folder 'v1.1.1\Bin' in the installation\archive.


    2. First ensure you have the following imports:
    C#
    using CompletIT.Windows.Forms.Export.Excel;

    VB.NET
    Imports CompletIT.Windows.Forms.Export.Excel


    3. Then add the following code in the event handler that has to perform the export:
    C#
    DGVEExcelExportSettings exportSettings = new DGVEExcelExportSettings();
    exportSettings.ExportFileName = ...//Export file name
    exportSettings.OpenFileAfterGeneration =
    true; //Open generated file after export
    //Set other settings here...
    DGVEExcelExporter exporter = new DGVEExcelExporter();
    exporter.Export( dataGridView, exportSettings );

    VB.NET
    Dim ExportSettings As DGVEExcelExportSettings = New DGVEExcelExportSettings()
    ExportSettings.ExportFileName = ...'Export file name
    ExportSettings.OpenFileAfterGeneration = True 'Open generated file after export
    'Set other settings here...

    Dim Exporter As DGVEExcelExporter = New DGVEExcelExporter()
    Exporter.Export(Me.DataGridViewControl, ExportSettings)


    4. Run your application!

    Filed under: , ,
View Complete Thread
Powered by Community Server (Personal Edition), by Telligent Systems