Exemple #1
0
        public void SetCellBackgroundColor(Int32 rowIndex, Int32 columnIndex, String bgColor)
        {
            // ищем ячейку и её старый формат
            Row         row                = GetRow((UInt32)rowIndex);
            Cell        cell               = GetCell(row, (UInt32)columnIndex);
            CellFormats cellFormats        = stylesheet.GetFirstChild <CellFormats>();
            CellFormat  cellFormat         = cellFormats.Elements <CellFormat>().ElementAt <CellFormat>((Int32)cell.StyleIndex.Value);
            Int32       newCellFormatIndex = cellFormats.Elements <CellFormat>().Count <CellFormat>();
            CellFormat  newCellFormat      = (CellFormat)cellFormat.Clone();

            {
                // новый background ----------------------------------------- проверить существующий to do ...
                Fills fills     = stylesheet.GetFirstChild <Fills>();
                Int32 fillIndex = fills.Elements <Fill>().Count <Fill>();
                fills.Append(
                    new Fill
                {
                    PatternFill = new PatternFill
                    {
                        PatternType     = PatternValues.Solid,
                        ForegroundColor = new ForegroundColor()
                        {
                            Rgb = "ff" + bgColor
                        }
                    }
                }
                    );
                newCellFormat.FillId = (UInt32)fillIndex;
            }
            cellFormats.Append(newCellFormat);
            cell.StyleIndex = (UInt32)newCellFormatIndex;
        }
Exemple #2
0
        /// <summary>
        /// Import cell format
        /// </summary>
        /// <param name="sourceStyleSheet"></param>
        /// <param name="srcFormat"></param>
        /// <param name="targetStyleSheet"></param>
        /// <returns></returns>
        protected static uint ImportCellFormat(Stylesheet sourceStyleSheet, CellFormat srcFormat, Stylesheet targetStyleSheet)
        {
            var tgtCellFormats = targetStyleSheet.CellFormats ??
                                 targetStyleSheet.AppendChild(new CellFormats());
            var tgtCellFormat = tgtCellFormats.AppendChild(srcFormat.Clone() as CellFormat);

            tgtCellFormats.Count++;
            // Import Style
            if (srcFormat.FormatId != null)
            {
                var srcStyle = sourceStyleSheet.CellStyleFormats.ElementAt((int)srcFormat.FormatId.Value) as CellFormat;
                if (srcStyle == null)
                {
                    throw new InvalidOperationException(String.Format("Style {0} was not found in source document!",
                                                                      srcFormat.FormatId));
                }
                // Style is complex, so just clone it
                var tgtStyle = srcStyle.Clone() as CellFormat;
                // Add style to target
                if (targetStyleSheet.CellStyleFormats == null)
                {
                    targetStyleSheet.CellStyleFormats = new CellStyleFormats();
                }
                targetStyleSheet.CellStyleFormats.AppendChild(tgtStyle);
                tgtCellFormat.FormatId = targetStyleSheet.CellStyleFormats.Count - 1;
                // Import details
                ImportCellFormatDetails(sourceStyleSheet, tgtStyle, targetStyleSheet);
            }
            // Import details
            ImportCellFormatDetails(sourceStyleSheet, tgtCellFormat, targetStyleSheet);

            return(tgtCellFormats.Count - 1);
        }
Exemple #3
0
 private static CellFormat smethod_7(CellFormat A_0, bool A_1)
 {
     if (A_1)
     {
         CellFormat format = (CellFormat)A_0.Clone();
         format.AcceptFormatRevision();
         return(format);
     }
     return(A_0);
 }
Exemple #4
0
        /// <summary>
        /// Import cell format
        /// </summary>
        /// <param name="sourceStyleSheet"></param>
        /// <param name="srcFormat"></param>
        /// <param name="targetStyleSheet"></param>
        /// <returns></returns>
        protected static uint ImportCellFormat(Stylesheet sourceStyleSheet, CellFormat srcFormat, Stylesheet targetStyleSheet)
        {
            var tgtCellFormats = targetStyleSheet.CellFormats ??
                                 targetStyleSheet.AppendChild(new CellFormats());
            var tgtCellFormat = tgtCellFormats.AppendChild(srcFormat.Clone() as CellFormat);
            tgtCellFormats.Count ++;
            // Import Style
            if (srcFormat.FormatId != null)
            {
                var srcStyle = sourceStyleSheet.CellStyleFormats.ElementAt((int) srcFormat.FormatId.Value) as CellFormat;
                if (srcStyle == null)
                    throw new InvalidOperationException(String.Format("Style {0} was not found in source document!",
                        srcFormat.FormatId));
                // Style is complex, so just clone it
                var tgtStyle = srcStyle.Clone() as CellFormat;
                // Add style to target
                if (targetStyleSheet.CellStyleFormats == null)
                    targetStyleSheet.CellStyleFormats = new CellStyleFormats();
                targetStyleSheet.CellStyleFormats.AppendChild(tgtStyle);
                tgtCellFormat.FormatId = targetStyleSheet.CellStyleFormats.Count - 1;
                // Import details
                ImportCellFormatDetails(sourceStyleSheet, tgtStyle, targetStyleSheet);
            }
            // Import details
            ImportCellFormatDetails(sourceStyleSheet, tgtCellFormat, targetStyleSheet);

            return tgtCellFormats.Count - 1;
        }
        /// <summary>
        /// Обработка документа Excel.
        /// </summary>
        /// <param name="document">Документ Excel.</param>
        public void Process(ref SpreadsheetDocument document, IExportParams parameters = null, NameValueCollection queryParams = null)
        {
            var workbookPart = document.WorkbookPart;

            if (workbookPart != null)
            {
                WorkbookStylesPart styles = workbookPart.WorkbookStylesPart;
                if (styles != null)
                {
                    Stylesheet stylesheet = styles.Stylesheet;
                    if (stylesheet != null)
                    {
                        CellFormats cellformats = stylesheet.CellFormats;
                        Fonts       fonts       = stylesheet.Fonts;
                        UInt32      fontIndex   = fonts.Count;
                        UInt32      formatIndex = cellformats.Count;

                        var worksheetPart = workbookPart.GetPartsOfType <WorksheetPart>().First();
                        if (worksheetPart != null)
                        {
                            var sheetData = worksheetPart.Worksheet.GetFirstChild <SheetData>();
                            if (sheetData != null)
                            {
                                var headerRow = sheetData.GetFirstChild <Row>();
                                if (headerRow != null)
                                {
                                    Cell       cell    = headerRow.GetFirstChild <Cell>();
                                    CellFormat f       = (CellFormat)cellformats.ElementAt((int)cell.StyleIndex.Value);
                                    var        font    = (Font)fonts.ElementAt((int)f.FontId.Value);
                                    var        newfont = (Font)font.Clone();
                                    newfont.Bold = new Bold();
                                    fonts.Append(newfont);
                                    fonts.Count = UInt32Value.FromUInt32((uint)fonts.ChildElements.Count);
                                    CellFormat newformat = (CellFormat)f.Clone();
                                    newformat.FontId = fontIndex;
                                    Fill        fill        = new Fill();
                                    PatternFill patternFill = new PatternFill()
                                    {
                                        PatternType = PatternValues.Solid
                                    };
                                    patternFill.ForegroundColor = new ForegroundColor()
                                    {
                                        Rgb = "FFD0D0D0"
                                    };
                                    patternFill.BackgroundColor = new BackgroundColor()
                                    {
                                        Indexed = (UInt32Value)64U
                                    };
                                    fill.PatternFill = patternFill;
                                    Fills fills = new Fills();
                                    fills.Append(new Fill()
                                    {
                                        PatternFill = new PatternFill()
                                    });
                                    fills.Append(new Fill()
                                    {
                                        PatternFill = new PatternFill()
                                        {
                                            PatternType = PatternValues.Gray125
                                        }
                                    });
                                    fills.Append(fill);
                                    stylesheet.Fills       = fills;
                                    stylesheet.Fills.Count = UInt32Value.FromUInt32((uint)fills.ChildElements.Count);
                                    newformat.FillId       = stylesheet.Fills.Count - 1;
                                    cellformats.Append(newformat);
                                    cellformats.Count = UInt32Value.FromUInt32((uint)cellformats.ChildElements.Count);
                                    stylesheet.Save();
                                    foreach (OpenXmlElement el in headerRow.ChildElements)
                                    {
                                        (el as Cell).StyleIndex = formatIndex;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
 internal static Class925 smethod_0(CellFormat A_0, TableCell A_1)
 {
     return(new Class925(false, (CellFormat)A_0.Clone(), A_1));
 }