Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
920
exporting Record number to excel
posted

Hi,

I am using RecordSelectorNumberType="VisibleIndex" in the field settings to display record number in xamdatagrid. When I export to excel, I want to export the record number. How can I achieve this.

Thanks,

Lala

Parents
  • 6365
    Offline posted

    Hello Lala,
     
    In order to export the records' selectors in XamDataGrid to Excel, an approach I can suggest you is to  handle the RecordExporting, HeaderAreaExporting and the ExportEnding events of the DataPresenterExcelExporter instance.
     
    Inside the RecordExporting and the HeaderAreaExporting events, we can create an indentation for the records and the labels by incrementing the CurrentColumnIndex in order to make space for the record selector values in Excel. This way prior to ending the exporting operation, by handling the ExportEnding event, we can manually assign respective values for the cells in Excel, that act as record selectors.
     
    void exporter_RecordExporting(object sender, RecordExportingEventArgs e)
    {
                e.CurrentColumnIndex++;
    }
     
    void exporter_HeaderAreaExporting(object sender, HeaderAreaExportingEventArgs e)
    {
                e.CurrentColumnIndex++;
    }
     
    void exporter_ExportEnding(object sender, ExportEndingEventArgs e)
    {
                for (int i = 1; i <= XDG.Records.Count; ++i)
                {
                    e.CurrentWorksheet.GetCell("A" + (i + 1).ToString()).Value = i;
                }
    }
     
    I have prepared an application where this behavior has been implemented.
     
    If you require any further assistance on this matter, please do not hesitate to ask.

    XamDataGrid_Excel.zip
Reply Children