Пример #1
0
        /// <summary> A public copy constructor which can be used for copy formats between
        /// different sheets.  Unlike the the other copy constructor, this
        /// version does a deep copy
        ///
        /// </summary>
        /// <param name="cellFormat">the format to copy
        /// </param>
        protected internal XFRecord(CellFormat cellFormat) : base(NExcel.Biff.Type.XF)
        {
            Assert.verify(cellFormat is XFRecord);
            XFRecord fmt = (XFRecord)cellFormat;

            if (!fmt.formatInfoInitialized)
            {
                fmt.initializeFormatInformation();
            }

            locked             = fmt.locked;
            hidden             = fmt.hidden;
            align              = fmt.align;
            valign             = fmt.valign;
            orientation        = fmt.orientation;
            wrap               = fmt.wrap;
            leftBorder         = fmt.leftBorder;
            rightBorder        = fmt.rightBorder;
            topBorder          = fmt.topBorder;
            bottomBorder       = fmt.bottomBorder;
            leftBorderColour   = fmt.leftBorderColour;
            rightBorderColour  = fmt.rightBorderColour;
            topBorderColour    = fmt.topBorderColour;
            bottomBorderColour = fmt.bottomBorderColour;
            pattern            = fmt.pattern;
            xfFormatType       = fmt.xfFormatType;
            parentFormat       = fmt.parentFormat;
            shrinkToFit        = fmt.shrinkToFit;
            backgroundColour   = fmt.backgroundColour;

            // Deep copy of the font
            font = new FontRecord(fmt.Font);

            // Copy the format
            if (fmt.Format == null)
            {
                // format is writable
                if (fmt.format.isBuiltIn())
                {
                    format = fmt.format;
                }
                else
                {
                    // Format is not built in, so do a deep copy
                    format = new FormatRecord((FormatRecord)fmt.format);
                }
            }
            else if (fmt.Format is BuiltInFormat)
            {
                // read excel format is built in
                excelFormat = (BuiltInFormat)fmt.excelFormat;
                format      = (BuiltInFormat)fmt.excelFormat;
            }
            else
            {
                // read excel format is user defined
                Assert.verify(fmt.formatInfoInitialized);

                // in this case FormattingRecords should initialize the excelFormat
                // field with an instance of FormatRecord
                Assert.verify(fmt.excelFormat is FormatRecord);

                // Format is not built in, so do a deep copy
                FormatRecord fr = new FormatRecord((FormatRecord)fmt.excelFormat);

                // Set both format fields to be the same object, since
                // FormatRecord implements all the necessary interfaces
                excelFormat = fr;
                format      = fr;
            }

            biffType = biff8;

            // The format info should be all OK by virtue of the deep copy
            formatInfoInitialized = true;


            // This format was not read in
            read = false;

            // Treat this as a new cell record, so set the copied flag to false
            copied = false;

            // The font or format indexes need to be set, so set initialized to false
            initialized = false;
        }
Пример #2
0
        /// <summary> Equals method.  This is called when comparing writable formats
        /// in order to prevent duplicate formats being added to the workbook
        ///
        /// </summary>
        /// <param name="o">object to compare
        /// </param>
        /// <returns> TRUE if the objects are equal, FALSE otherwise
        /// </returns>
        public override bool Equals(System.Object o)
        {
            if (o == this)
            {
                return(true);
            }

            if (!(o is XFRecord))
            {
                return(false);
            }

            XFRecord xfr = (XFRecord)o;

            // Both records must be writable and have their format info initialized
            if (!formatInfoInitialized)
            {
                initializeFormatInformation();
            }

            if (!xfr.formatInfoInitialized)
            {
                xfr.initializeFormatInformation();
            }

            if (xfFormatType != xfr.xfFormatType || parentFormat != xfr.parentFormat || locked != xfr.locked || hidden != xfr.hidden || usedAttributes != xfr.usedAttributes)
            {
                return(false);
            }

            if (align != xfr.align || valign != xfr.valign || orientation != xfr.orientation || wrap != xfr.wrap || shrinkToFit != xfr.shrinkToFit)
            {
                return(false);
            }

            if (leftBorder != xfr.leftBorder || rightBorder != xfr.rightBorder || topBorder != xfr.topBorder || bottomBorder != xfr.bottomBorder)
            {
                return(false);
            }

            if (leftBorderColour != xfr.leftBorderColour || rightBorderColour != xfr.rightBorderColour || topBorderColour != xfr.topBorderColour || bottomBorderColour != xfr.bottomBorderColour)
            {
                return(false);
            }

            if (backgroundColour != xfr.backgroundColour || pattern != xfr.pattern)
            {
                return(false);
            }

            // Sufficient to just do shallow equals on font, format objects,
            // since we are testing for the presence of clones anwyay
            // Use indices rather than objects because of the rationalization
            // process (which does not set the object on an XFRecord)
            if (fontIndex != xfr.fontIndex || formatIndex != xfr.formatIndex)
            {
                return(false);
            }

            return(true);
        }