private void AddDataRows(IWorksheetExporter worksheet, int outlineLevel, int startColumnIndex, IList items, IList <GridViewBoundColumnBase> columns)
        {
            SpreadCellFormat format = new SpreadCellFormat();

            format.Fill = SpreadPatternFill.CreateSolidFill(ColorToSpreadColor(this.DataRowColor));

            SpreadCellFormat currencyFormat = new SpreadCellFormat();

            currencyFormat.Fill         = format.Fill;
            currencyFormat.NumberFormat = "$#,##0.00";

            for (int rowIndex = 0; rowIndex < items.Count; rowIndex++)
            {
                using (IRowExporter row = worksheet.CreateRowExporter())
                {
                    row.SetOutlineLevel(outlineLevel);

                    for (int i = 0; i < startColumnIndex; i++)
                    {
                        using (ICellExporter cell = row.CreateCellExporter())
                        {
                            cell.SetFormat(format);
                        }
                    }

                    for (int columnIndex = 0; columnIndex < columns.Count; columnIndex++)
                    {
                        using (ICellExporter cell = row.CreateCellExporter())
                        {
                            object value = columns[columnIndex].GetValueForItem(items[rowIndex]);

                            if (value is int)
                            {
                                cell.SetValue((int)value);
                                cell.SetFormat(format);
                            }
                            else
                            {
                                string stringValue = value.ToString();
                                if (stringValue.Contains('$'))
                                {
                                    stringValue = stringValue.Replace("$", string.Empty);
                                    double doubleValue = double.Parse(stringValue);
                                    cell.SetValue(doubleValue);
                                    cell.SetFormat(currencyFormat);
                                }
                                else
                                {
                                    cell.SetValue(stringValue);
                                    cell.SetFormat(format);
                                }
                            }
                        }
                    }
                }
            }
        }
        private int AddGroupRow(IWorksheetExporter worksheet, int outlineLevel, int rowIndex, int numberOfIndentCells,
                                QueryableCollectionViewGroup group, IList <GridViewBoundColumnBase> columns)
        {
            int startColumnIndex = this.GetGroupLevel(group);

            this.mergedCells.Add(new CellRange(rowIndex, startColumnIndex, rowIndex, numberOfIndentCells + columns.Count - 1));

            SpreadCellFormat format = new SpreadCellFormat();

            format.Fill = SpreadPatternFill.CreateSolidFill(ColorToSpreadColor(this.GroupHeaderRowColor));
            format.HorizontalAlignment = SpreadHorizontalAlignment.Left;

            using (IRowExporter row = worksheet.CreateRowExporter())
            {
                row.SetOutlineLevel(outlineLevel - 1);

                row.SkipCells(startColumnIndex);

                for (int i = startColumnIndex; i < numberOfIndentCells + columns.Count - 1; i++)
                {
                    using (ICellExporter cell = row.CreateCellExporter())
                    {
                        cell.SetFormat(format);

                        if (group.Key is int)
                        {
                            cell.SetValue((int)group.Key);
                        }
                        else if (group.Key is double)
                        {
                            cell.SetValue((double)group.Key);
                        }
                        else
                        {
                            string cellValue = group.Key != null?group.Key.ToString() : string.Empty;

                            cell.SetValue(cellValue);
                        }
                    }
                }
            }

            rowIndex++;
            startColumnIndex++;

            if (group.HasSubgroups)
            {
                foreach (IGroup subGroup in group.Subgroups)
                {
                    int newRowIndex = this.AddGroupRow(worksheet, outlineLevel + 1, rowIndex, numberOfIndentCells, subGroup as QueryableCollectionViewGroup, columns);
                    rowIndex = newRowIndex;
                }
            }
            else
            {
                this.AddDataRows(worksheet, outlineLevel, startColumnIndex, group.Items, columns);
                rowIndex += group.Items.Count;
            }

            return(rowIndex);
        }