예제 #1
0
        /**
         * Creates a new object.
         *
         * @param format The format.
         */
        private CellFormat(String format)
        {
            this.format = format;
            MatchCollection       mc    = ONE_PART.Matches(format);
            List <CellFormatPart> parts = new List <CellFormatPart>();

            //while (m.Success)
            foreach (Match m in mc)
            {
                try
                {
                    String valueDesc = m.Groups[0].Value;

                    // Strip out the semicolon if it's there
                    if (valueDesc.EndsWith(";"))
                    {
                        valueDesc = valueDesc.Substring(0, valueDesc.Length - 1);
                    }

                    parts.Add(new CellFormatPart(valueDesc));
                }
                catch (Exception)
                {
                    //CellFormatter.logger.Log(Level.WARNING,
                    //        "Invalid format: " + CellFormatter.Quote(m.Group()), e);
                    parts.Add(null);
                }
            }

            switch (parts.Count)
            {
            case 1:
                posNumFmt = zeroNumFmt = negNumFmt = parts[(0)];
                textFmt   = DEFAULT_TEXT_FORMAT;
                break;

            case 2:
                posNumFmt = zeroNumFmt = parts[0];
                negNumFmt = parts[1];
                textFmt   = DEFAULT_TEXT_FORMAT;
                break;

            case 3:
                posNumFmt  = parts[0];
                zeroNumFmt = parts[1];
                negNumFmt  = parts[2];
                textFmt    = DEFAULT_TEXT_FORMAT;
                break;

            case 4:
            default:
                posNumFmt  = parts[0];
                zeroNumFmt = parts[1];
                negNumFmt  = parts[2];
                textFmt    = parts[3];
                break;
            }
        }
예제 #2
0
        /**
         * Creates a new date formatter with the given specification.
         *
         * @param format The format.
         */
        public CellDateFormatter(String format)
            : base(format)
        {
            ;
            DatePartHandler partHandler = new DatePartHandler(this);
            StringBuilder   descBuf     = CellFormatPart.ParseFormat(format,
                                                                     CellFormatType.DATE, partHandler);

            partHandler.Finish(descBuf);
            dateFmt = new SimpleDateFormat(descBuf.ToString());
        }
예제 #3
0
        public CellTextFormatter(String format)
            : base(format)
        {
            ;

            int[]       numPlaces = new int[1];
            PartHandler handler   = new PartHandler(numPlaces[0]);

            desc = CellFormatPart.ParseFormat(format, CellFormatType.TEXT, handler).ToString();

            // Remember the "@" positions in last-to-first order (to make insertion easier)
            textPos = new int[handler.NumPlace];
            int pos = desc.Length - 1;

            for (int i = 0; i < textPos.Length; i++)
            {
                textPos[i] = desc.LastIndexOf("\u0000", pos);
                pos        = textPos[i] - 1;
            }
        }