예제 #1
0
        /// <summary>
        /// Залить цветом ячейки в таблице
        /// </summary>
        /// <param name="progress"></param>
        /// <param name="worksheet">Страница</param>
        /// <param name="colors">Цвета</param>
        private void DecorateWorksheetCells(ExcelExportProgressCommand progress, dynamic worksheet, Color[,] colors)
        {
            var areas = new List <ColorArea>();

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Columns; j++)
                {
                    var c = colors[i, j];
                    if (c.R < 250 || c.B < 250 || c.G < 250)
                    {
                        var a = new ColorArea();
                        a.Fill(colors, j, i);
                        a.Bleach(colors);
                        areas.Add(a);
                    }
                }
            }

            foreach (var a in areas)
            {
                progress.Area = string.Format("{0}:{1:D2} - {2}:{3:D2}", a.Y + 2, a.X + 1, a.Y + 1 + a.Height,
                                              a.X + a.Width);
                var r1 = worksheet.Cells[a.Y + 2, a.X + 1];
                var r2 = worksheet.Cells[a.Y + 1 + a.Height, a.X + a.Width];
                var r  = worksheet.Range(r1, r2);
                r.Interior.Color = a.Color.ToOle();
            }
        }
예제 #2
0
        public void PrepareExport(GridControl grid, bool exportColors, HashSet <GridColumn> excludeColumn,
                                  Action <ExcelExportData, IDocumentPresenter, ExcelExportProgressCommand> afterExportComplete,
                                  ExcelExportProgressCommand progressCommand, IDocumentPresenter document)
        {
            Rows = grid.VisibleRowCount;
            progressCommand.Rows       = Rows;
            progressCommand.CurrentRow = 0;
            var tv = grid.View as TableView;
            var eo = new ExcelExportObject
            {
                VisibleColumns =
                    grid.Columns.Where(
                        c => !excludeColumn.Contains(c) && !(c is GridExpandColumn) && c.Visible)
                    .OrderBy(c => c.VisibleIndex)
                    .ToList(),
                RowBrushes          = new Brush[grid.VisibleRowCount],
                CurrentRow          = 0,
                PrevRow             = 0,
                ExportColors        = exportColors && tv != null,
                Grid                = grid,
                RowData             = new List <object>(),
                ProgressCommand     = progressCommand,
                AfterExportComplete = afterExportComplete,
                Document            = document
            };

            Headers = new RealColumnHeadersCollection(eo.VisibleColumns.Select(c => GetHeaderString(c.Header)).ToArray());
            Columns = eo.VisibleColumns.Count;
            NumberFormatting.ClearFormats();
            for (int i = 0; i < eo.VisibleColumns.Count; i++)
            {
                NumberFormatting.AddFormat(i, eo.VisibleColumns[i].FieldType);
            }
            eo.CellBrushes = new Brush[grid.VisibleRowCount, eo.VisibleColumns.Count];
            eo.Cells       = new string[grid.VisibleRowCount, eo.VisibleColumns.Count];
            if (eo.ExportColors)
            {
                eo.PhantomCells = new CellContentPresenter[32, Columns];
                eo.PhantomRows  = new GridRowContent[32];
                for (int i = 0; i < 32; i++)
                {
                    eo.PhantomRows[i] = new GridRowContent()
                    {
                        Style = tv.RowStyle
                    };
                    for (int j = 0; j < Columns; j++)
                    {
                        eo.PhantomCells[i, j] = new CellContentPresenter {
                            Style = eo.VisibleColumns[j].CellStyle
                        }
                    }
                    ;
                }
            }

            DoExport(eo);
        }
예제 #3
0
        /// <summary>
        /// Заполнить лист данными
        /// </summary>
        /// <param name="progress"></param>
        /// <param name="worksheet"></param>
        /// <param name="table"></param>
        private void FillWorksheet(ExcelExportProgressCommand progress, dynamic worksheet, object[,] table)
        {
            var rangeTo = string.Format("{0}:{1}", (table.GetLength(0) + 1), (table.GetLength(1) + 1));
            var r       = worksheet.Range["1:1", rangeTo];

            r.NumberFormat = "@";
            var colors = new Color[Rows, Columns];

            ThreadUtils.SafeCall(() => MixCellWithRowColors(colors));
            DecorateWorksheetCells(progress, worksheet, colors);
            progress.CurrentStep = 3;
            using (var context = new ExcelFileContext(worksheet))
                context.Sign();
        }
예제 #4
0
        public void GenerateExcelFile(ExcelExportProgressCommand progress)
        {
            var table = new object[Rows + 1, Columns];

            for (int j = 0; j < Columns; j++)
            {
                table[0, j] = Headers[j];
            }

            for (int i = 0; i < Rows; i++)
            {
                for (int j = 0; j < Columns; j++)
                {
                    table[i + 1, j] = Cells[i, j];
                }
            }

            ExcelOpener.OpenInExcel(table, SheetName, AfterExport,
                                    worksheet => FillWorksheet(progress, worksheet, table));
        }