void GenerateBillToRow(IXlSheet sheet, string name1, object value1, string name2, object value2, XlBorder specificBorder)
        {
            using (IXlRow row = sheet.CreateRow()) {
                // Set the cell font.
                row.ApplyFormatting(infoFont);
                // Skip the first cell in the row.
                row.SkipCells(1);

                // Create the empty cell with the specified formatting settings.
                using (IXlCell cell = row.CreateCell()) {
                    cell.ApplyFormatting(infoFormatting);
                    // Set the cell border.
                    cell.ApplyFormatting(specificBorder);
                }

                // Create the cell, assign its value and apply specific formatting settings to it.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = name1;
                    cell.ApplyFormatting(infoFormatting);
                    // Set the cell border.
                    cell.ApplyFormatting(specificBorder);
                    cell.Formatting.Font.Bold = true;
                }

                // Create the cell, assign its value converted from the custom object and apply specific formatting settings to it.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = XlVariantValue.FromObject(value1);
                    cell.ApplyFormatting(infoFormatting);
                    // Set the cell border.
                    cell.ApplyFormatting(specificBorder);
                }

                // Create the cell, assign its value and apply specific formatting settings to it.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = name2;
                    cell.ApplyFormatting(infoFormatting);
                    // Set the cell border.
                    cell.ApplyFormatting(specificBorder);
                    cell.Formatting.Font.Bold = true;
                }

                // Create the cell, assign its value converted from the custom object and apply specific formatting settings to it.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = XlVariantValue.FromObject(value2);
                    cell.ApplyFormatting(infoFormatting);
                    // Set the cell border.
                    cell.ApplyFormatting(specificBorder);
                }

                // Create three successive cells, apply specific formatting settings to them and set the cell borders.
                for (int i = 0; i < 3; i++)
                {
                    using (IXlCell cell = row.CreateCell()) {
                        cell.ApplyFormatting(infoFormatting);
                        cell.ApplyFormatting(specificBorder);
                    }
                }
            }
        }
        void GenerateTitleRow(IXlSheet sheet, string info, string name, object value, int rowHeight, XlFont font, XlNumberFormat specificFormat)
        {
            using (IXlRow row = sheet.CreateRow()) {
                // Set the row height.
                row.HeightInPixels = rowHeight;
                // Set the cell font.
                row.ApplyFormatting(font);

                // Create the first empty cell.
                row.SkipCells(1);

                // Create the blank cell with the specified formatting settings.
                row.BlankCells(1, leftPanelFormatting);

                // Create the third cell, assign its value and apply specific formatting settings to it.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = info;
                    cell.ApplyFormatting(leftPanelFormatting);
                }

                // Create two blank cells with the specified formatting settings.
                row.BlankCells(2, leftPanelFormatting);

                // Create the cell, apply specific formatting settings to it and set the cell right border.
                using (IXlCell cell = row.CreateCell()) {
                    cell.ApplyFormatting(leftPanelFormatting);
                    cell.ApplyFormatting(leftPanelBorder);
                }

                // Create the cell, assign its value and apply specific formatting settings to it.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = name;
                    cell.ApplyFormatting(rightPanelFormatting);
                    cell.Formatting.Alignment.Indent = 1;
                }

                // Create the cell, assign its value converted from the custom object and apply specific formatting settings to it.
                using (IXlCell cell = row.CreateCell()) {
                    cell.Value = XlVariantValue.FromObject(value);
                    cell.ApplyFormatting(rightPanelFormatting);
                    if (specificFormat != null)
                    {
                        cell.ApplyFormatting(specificFormat);
                    }
                }

                // Create one blank cell with the specified formatting settings.
                row.BlankCells(1, rightPanelFormatting);
            }
        }
Esempio n. 3
0
        void ExportCell(IXlRow row, int gridRowHandle, GridColumn gridColumn)
        {
            using (IXlCell cell = row.CreateCell()) {
                // Set cell value
                cell.Value = XlVariantValue.FromObject(this.view.GetRowCellValue(gridRowHandle, gridColumn));

                // Get cell appearance
                AppearanceObject appearance = GetCellAppearance(gridRowHandle, gridColumn);

                // Apply alignment
                XlCellAlignment alignment = new XlCellAlignment()
                {
                    WrapText            = appearance.TextOptions.WordWrap.HasFlag(WordWrap.Wrap),
                    VerticalAlignment   = ConvertAlignment(appearance.TextOptions.VAlignment),
                    HorizontalAlignment = ConvertAlignment(appearance.TextOptions.HAlignment)
                };
                cell.ApplyFormatting(alignment);

                // Apply borders
                Color borderColor = appearance.GetBorderColor();
                if (!DXColor.IsTransparentOrEmpty(borderColor))
                {
                    cell.ApplyFormatting(XlBorder.OutlineBorders(borderColor));
                }

                // Apply fill
                if (appearance.Options.UseBackColor)
                {
                    cell.ApplyFormatting(XlFill.SolidFill(appearance.BackColor));
                }

                // Apply font
                Font   appearanceFont = appearance.Font;
                XlFont font           = XlFont.CustomFont(appearanceFont.Name);
                font.Size          = appearanceFont.SizeInPoints;
                font.Bold          = appearanceFont.Bold;
                font.Italic        = appearanceFont.Italic;
                font.StrikeThrough = appearanceFont.Strikeout;
                font.Underline     = appearanceFont.Underline ? XlUnderlineType.Single : XlUnderlineType.None;
                if (appearance.Options.UseForeColor)
                {
                    font.Color = appearance.ForeColor;
                }
                cell.ApplyFormatting(font);
            }
        }