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
60
Export to excel with hierarchila data
posted

Hi,

I have a XamDataGrid binded to hierarchial data with 2 different layouts. I am exporting this hierarchial data to excel using "DataPresenterExcelExporter". If I do export to excel without expanding any record then export to excel funtionality is working fine.

However when I expand some records and then do export to excel, in the generated excel file the child records are not aligned properly.  The columns of the child layout are indented by one column.

This is my XamDataGird with hierarchial data.

 When I do export to excel, the columns in the child layout are indented by one column.

 

In the above image "Creation Time" coumn is having "Name" column values for child records also there is a new column only for child records. Please let me know how to handle this.

  • 17559
    posted

    Hello bhanuprasadkota,

     

    It has been a while since you made this post and if you still need any assistance on the matter I will be glad to help. I was looking into your requirements and in order to align the cells from the inner level with these from the firs, I can suggest you handle the CellExporting and HeaderLabelExporting events and manually move the cells on the left.  To achieve this functionality you may try the following code snippet:

            void exporter_CellExporting(object sender, Infragistics.Windows.DataPresenter.ExcelExporter.CellExportingEventArgs e)

            {

              

                if (e.Record.RecordManager.ParentRecord!=null&& e.CurrentColumnIndex>=1)

                {             

                    e.Workbook.Worksheets[0].Rows[e.CurrentRowIndex].Cells[e.CurrentColumnIndex - 1].Value = (e.Record as DataRecord).Cells[e.Field].Value;

                    if (e.CurrentColumnIndex == (e.Record as DataRecord).Cells.Count)

                    {

                        e.Cancel = true;

                        return;

                    }

                }                       

            }

     For further reference, please have a look at the attached sample.

     If this doesn’t suit your scenario, please let me know.

    ExportHierarchyXDGaligned.zip