Пример #1
0
        /// <summary> A constructor used when creating a writable record
        ///
        /// </summary>
        /// <param name="fnt">the font
        /// </param>
        /// <param name="form">the format
        /// </param>
        public XFRecord(FontRecord fnt, DisplayFormat form) : base(NExcel.Biff.Type.XF)
        {
            initialized        = false;
            locked             = true;
            hidden             = false;
            align              = Alignment.GENERAL;
            valign             = VerticalAlignment.BOTTOM;
            orientation        = Orientation.HORIZONTAL;
            wrap               = false;
            leftBorder         = BorderLineStyle.NONE;
            rightBorder        = BorderLineStyle.NONE;
            topBorder          = BorderLineStyle.NONE;
            bottomBorder       = BorderLineStyle.NONE;
            leftBorderColour   = Colour.PALETTE_BLACK;
            rightBorderColour  = Colour.PALETTE_BLACK;
            topBorderColour    = Colour.PALETTE_BLACK;
            bottomBorderColour = Colour.PALETTE_BLACK;
            pattern            = Pattern.NONE;
            backgroundColour   = Colour.DEFAULT_BACKGROUND;
            shrinkToFit        = false;

            // This will be set by the initialize method and the subclass respectively
            parentFormat = 0;
            xfFormatType = null;

            font     = fnt;
            format   = form;
            biffType = biff8;
            read     = false;
            copied   = false;
            formatInfoInitialized = true;

            Assert.verify(font != null);
            Assert.verify(format != null);
        }
Пример #2
0
        /**
         * Constructs this object from the raw data.  Used when reading in a
         * format record
         *
         * @param t the raw data
         * @param ws the workbook settings
         * @param biffType biff type dummy overload
         */
        public FormatRecord(Record t, WorkbookSettings ws, BiffType biffType)
            : base(t)
        {
            byte[] data = getRecord().getData();
            indexCode   = IntegerHelper.getInt(data[0], data[1]);
            initialized = true;

            if (biffType == biff8)
            {
                int numchars = IntegerHelper.getInt(data[2], data[3]);
                if (data[4] == 0)
                {
                    formatString = StringHelper.getString(data, numchars, 5, ws);
                }
                else
                {
                    formatString = StringHelper.getUnicodeString(data, numchars, 5);
                }
            }
            else
            {
                int    numchars = data[2];
                byte[] chars    = new byte[numchars];
                System.Array.Copy(data, 3, chars, 0, chars.Length);

                UnicodeEncoding enc = new UnicodeEncoding();
                formatString = enc.GetString(chars);
//				formatString = new string(chars);		uses platform default charset -- should be unicode, right?
            }

            date   = false;
            number = false;

            // First see if this is a date format
            for (int i = 0; i < dateStrings.Length; i++)
            {
                string dateString = dateStrings[i];
                if (formatString.IndexOf(dateString) != -1 ||
                    formatString.IndexOf(dateString.ToUpper()) != -1)
                {
                    date = true;
                    break;
                }
            }

            // See if this is number format - look for the # or 0 characters
            if (!date)
            {
                if (formatString.IndexOf('#') != -1 ||
                    formatString.IndexOf('0') != -1)
                {
                    number = true;
                }
            }
        }
Пример #3
0
        /// <summary> Constructs this object from the raw data
        ///
        /// </summary>
        /// <param name="t">the raw data
        /// </param>
        /// <param name="bt">the biff type
        /// </param>
        public XFRecord(Record t, BiffType bt) : base(t)
        {
            biffType = bt;

            sbyte[] data = getRecord().Data;

            fontIndex   = IntegerHelper.getInt(data[0], data[1]);
            formatIndex = IntegerHelper.getInt(data[2], data[3]);
            date        = false;
            number      = false;

            // Compare against the date formats
            for (int i = 0; i < dateFormats.Length; i++)
            {
                if (formatIndex == dateFormats[i])
                {
                    date       = true;
                    dateFormat = langDateFormats[i];
                }
            }

            // Compare against the number formats
            for (int i = 0; i < numberFormats.Length; i++)
            {
                if (formatIndex == numberFormats[i])
                {
                    number       = true;
                    numberFormat = langNumberFormats[i];
                }
            }

            // Initialize the parent format and the type
            int cellAttributes = IntegerHelper.getInt(data[4], data[5]);

            parentFormat = (cellAttributes & 0xfff0) >> 4;

            int formatType = cellAttributes & 0x4;

            xfFormatType = formatType == 0?cell:style;
            locked       = ((cellAttributes & 0x1) != 0);
            hidden       = ((cellAttributes & 0x2) != 0);

            if (xfFormatType == cell && (parentFormat & 0xfff) == 0xfff)
            {
                // Something is screwy with the parent format - set to zero
                parentFormat = 0;
                logger.warn("Invalid parent format found - ignoring");
            }

            initialized           = false;
            read                  = true;
            formatInfoInitialized = false;
            copied                = false;
        }
Пример #4
0
        /// <summary> Constructs this object from the raw data.  Used when reading in a
        /// format record
        ///
        /// </summary>
        /// <param name="t">the raw data
        /// </param>
        /// <param name="ws">the workbook settings
        /// </param>
        /// <param name="biffType">biff type dummy overload
        /// </param>
        public FormatRecord(Record t, WorkbookSettings ws, BiffType biffType) : base(t)
        {
            sbyte[] data = getRecord().Data;
            indexCode   = IntegerHelper.getInt(data[0], data[1]);
            initialized = true;

            if (biffType == biff8)
            {
                int numchars = IntegerHelper.getInt(data[2], data[3]);
                if (data[4] == 0)
                {
                    formatString = StringHelper.getString(data, numchars, 5, ws);
                }
                else
                {
                    formatString = StringHelper.getUnicodeString(data, numchars, 5);
                }
            }
            else
            {
                int     numchars = data[2];
                sbyte[] chars    = new sbyte[numchars];
                Array.Copy(data, 3, chars, 0, chars.Length);
                formatString = new string(NExcelUtils.Byte.ToCharArray(NExcelUtils.Byte.ToByteArray(chars)));
            }

            date   = false;
            number = false;

            // First see if this is a date format
            for (int i = 0; i < dateStrings.Length; i++)
            {
                string dateString = dateStrings[i];
                if (formatString.IndexOf(dateString) != -1 || formatString.IndexOf(dateString.ToUpper()) != -1)
                {
                    date = true;
                    break;
                }
            }

            // See if this is number format - look for the # or 0 characters
            if (!date)
            {
                if (formatString.IndexOf((System.Char) '#') != -1 || formatString.IndexOf((System.Char) '0') != -1)
                {
                    number = true;
                }
            }
        }
Пример #5
0
        /// <summary> Copy constructor.  Used for copying writable formats, typically
        /// when duplicating formats to handle merged cells
        ///
        /// </summary>
        /// <param name="fmt">XFRecord
        /// </param>
        protected internal XFRecord(XFRecord fmt) : base(NExcel.Biff.Type.XF)
        {
            initialized        = false;
            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;
            shrinkToFit        = fmt.shrinkToFit;
            parentFormat       = fmt.parentFormat;
            backgroundColour   = fmt.backgroundColour;

            // Shallow copy is sufficient for these purposes
            font   = fmt.font;
            format = fmt.format;

            fontIndex   = fmt.fontIndex;
            formatIndex = fmt.formatIndex;

            formatInfoInitialized = fmt.formatInfoInitialized;

            biffType = biff8;
            read     = false;
            copied   = true;
        }
Пример #6
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;
        }
Пример #7
0
        /**
         * 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
         *
         * @param cellFormat the format to copy
         */
        protected XFRecord(CellFormat cellFormat)
            : base(Type.XF)
        {
            Assert.verify(cellFormat != null);
            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;
            indentation = fmt.indentation;
            shrinkToFit = fmt.shrinkToFit;
            backgroundColour = fmt.backgroundColour;

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

            // Copy the format
            if (fmt.getFormat() == 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.getFormat() 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;
        }
Пример #8
0
        /**
         * Copy constructor.  Used for copying writable formats, typically
         * when duplicating formats to handle merged cells
         *
         * @param fmt XFRecord
         */
        protected XFRecord(XFRecord fmt)
            : base(Type.XF)
        {
            initialized = false;
            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;
            indentation = fmt.indentation;
            shrinkToFit = fmt.shrinkToFit;
            parentFormat = fmt.parentFormat;
            backgroundColour = fmt.backgroundColour;

            // Shallow copy is sufficient for these purposes
            font = fmt.font;
            format = fmt.format;

            fontIndex = fmt.fontIndex;
            formatIndex = fmt.formatIndex;

            formatInfoInitialized = fmt.formatInfoInitialized;

            biffType = biff8;
            read = false;
            copied = true;
        }
Пример #9
0
        /**
         * A constructor used when creating a writable record
         *
         * @param fnt the font
         * @param form the format
         */
        public XFRecord(FontRecord fnt,DisplayFormat form)
            : base(Type.XF)
        {
            initialized = false;
            locked = true;
            hidden = false;
            align = Alignment.GENERAL;
            valign = VerticalAlignment.BOTTOM;
            orientation = Orientation.HORIZONTAL;
            wrap = false;
            leftBorder = BorderLineStyle.NONE;
            rightBorder = BorderLineStyle.NONE;
            topBorder = BorderLineStyle.NONE;
            bottomBorder = BorderLineStyle.NONE;
            leftBorderColour = Colour.AUTOMATIC;
            rightBorderColour = Colour.AUTOMATIC;
            topBorderColour = Colour.AUTOMATIC;
            bottomBorderColour = Colour.AUTOMATIC;
            pattern = Pattern.NONE;
            backgroundColour = Colour.DEFAULT_BACKGROUND;
            indentation = 0;
            shrinkToFit = false;
            usedAttributes = (byte)(USE_FONT | USE_FORMAT |
                                 USE_BACKGROUND | USE_ALIGNMENT | USE_BORDER);

            // This will be set by the initialize method and the subclass respectively
            parentFormat = 0;
            xfFormatType = null;

            font = fnt;
            format = form;
            biffType = biff8;
            read = false;
            copied = false;
            formatInfoInitialized = true;

            Assert.verify(font != null);
            Assert.verify(format != null);
        }
Пример #10
0
        /**
         * Constructs this object from the raw data
         *
         * @param t the raw data
         * @param bt the biff type
         */
        public XFRecord(Record t,WorkbookSettings ws,BiffType bt)
            : base(t)
        {
            biffType = bt;

            byte[] data = getRecord().getData();

            fontIndex = IntegerHelper.getInt(data[0],data[1]);
            formatIndex = IntegerHelper.getInt(data[2],data[3]);
            date = false;
            number = false;

            // Compare against the date formats
            for (int i = 0; i < dateFormats.Length && date == false; i++)
                {
                if (formatIndex == dateFormats[i])
                    {
                    date = true;
                    dateFormat = javaDateFormats[i];
                    }
                }

            // Compare against the number formats
            for (int i = 0; i < numberFormats.Length && number == false; i++)
                {
                if (formatIndex == numberFormats[i])
                    {
                    number = true;
                    DecimalFormat df = new DecimalFormat((DecimalFormat)javaNumberFormats[i]);
            // TODO: CML - need to support DecimalFormatSymbols equivalent -- for now, we use the default from en-us
            //DecimalFormatSymbols symbols = new DecimalFormatSymbols(ws.getLocale());
            //df.setDecimalFormatSymbols(symbols);
                    numberFormat = df;
                    //numberFormat = javaNumberFormats[i];
                    }
                }

            // Initialize the parent format and the type
            int cellAttributes = IntegerHelper.getInt(data[4],data[5]);
            parentFormat = (cellAttributes & 0xfff0) >> 4;

            int formatType = cellAttributes & 0x4;
            xfFormatType = formatType == 0 ? cell : style;
            locked = ((cellAttributes & 0x1) != 0);
            hidden = ((cellAttributes & 0x2) != 0);

            if (xfFormatType == cell &&
                (parentFormat & 0xfff) == 0xfff)
                {
                // Something is screwy with the parent format - set to zero
                parentFormat = 0;
                //logger.warn("Invalid parent format found - ignoring");
                }

            initialized = false;
            read = true;
            formatInfoInitialized = false;
            copied = false;
        }