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
310
XamGrid Exporting to Excel (Grouping By) WITH columns Header...
posted

Hi,

I have found a lot of code that explain how to export XamGrid with Grouping-By but it doesn't export the columns header.

Do you have any sample that show the way to do it, Exporting XamGrid wiht columns header and grouping-by please?!?

Thanks.

Gilles P.

Parents
No Data
Reply
  • 310
    Verified Answer
    Offline posted

    Because I didn't have no answer, here is the solution I have found:

     

     private void IterateRow(Row row)

            {

                int columnIndex = currentMergedColumn;

                WorksheetCell worksheetCell;

     

                // loap for the header column always to the top of the excel grid

                foreach (Cell cell in row.Cells)

                {

                    sheet.Rows[0].Cells[columnIndex].Value = cell.Column.HeaderText;                

                    sheet.Columns[columnIndex].Width = (int)cell.Column.Width.Value.Value;

     

                    //Set header cell color and and borders

                    worksheetCell = sheet.Rows[0].Cells[columnIndex];

     

                    worksheetCell.CellFormat.FillPatternForegroundColor = Colors.LightGray;

                    worksheetCell.CellFormat.LeftBorderColor = Color.FromArgb(0, 178, 178, 178);

                    worksheetCell.CellFormat.RightBorderColor = Color.FromArgb(0, 178, 178, 178);

     

                    sheet.Columns[columnIndex].Width = 5000;

                    columnIndex++;

                }

                columnIndex = currentMergedColumn;

                foreach (Cell cell in row.Cells)

                {

                    sheet.Rows[currentMergedRow].Cells[columnIndex].Value = cell.Value;

                    sheet.Columns[columnIndex].Width = 5000;

     

                    columnIndex++;

                }

                currentMergedRow++;

            }

Children
No Data