Beispiel #1
0
        public static string GetExcelNumberFormat(string rsNumberFormat, string language, RPLFormat.Calendars rplCalendar, string numeralLanguage, int numeralVariant, TypeCode type, object originalValue, out string hexFormula, out bool invalidFormatCode)
        {
            hexFormula = null;
            string empty = string.Empty;
            string str   = string.Empty;

            invalidFormatCode = false;
            if (type != TypeCode.DateTime)
            {
                bool flag  = false;
                bool flag2 = default(bool);
                empty = FormatHandler.GetNumberFormat(rsNumberFormat, language, out flag2, type, originalValue, ref flag);
                if (string.IsNullOrEmpty(empty))
                {
                    invalidFormatCode = true;
                }
                else if (!flag2)
                {
                    if (empty != null && empty.Length > 0 && empty != "General")
                    {
                        str = FormatHandler.GetFormatStringPrefix(rplCalendar, numeralVariant, language, numeralLanguage);
                    }
                }
                else
                {
                    hexFormula = empty;
                }
            }
            else
            {
                empty = FormatHandler.GetDateTimeFormat(rsNumberFormat, language, rplCalendar);
                if (string.IsNullOrEmpty(empty))
                {
                    invalidFormatCode = true;
                }
                else
                {
                    str = FormatHandler.GetFormatStringPrefix(rplCalendar, numeralVariant, language, numeralLanguage);
                }
            }
            return(str + empty);
        }
Beispiel #2
0
        private static string GetNumberFormat(string format, string language, out bool isHex, TypeCode typeCode, object originalValue, ref bool isGeneral)
        {
            isHex = false;
            if (string.IsNullOrEmpty(format))
            {
                return("General");
            }
            CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(language);

            cultureInfo = new CultureInfo(cultureInfo.Name, false);
            NumberFormatInfo numberFormat = cultureInfo.NumberFormat;

            if (format.Length > 3)
            {
                return(FormatHandler.GetExcelPictureNumberFormat(format));
            }
            if (format.Length == 1)
            {
                switch (format[0])
                {
                case 'x':
                    switch (typeCode)
                    {
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                        isHex = true;
                        return("LOWER(DEC2HEX({0}))");

                    default:
                        return(string.Empty);
                    }

                case 'X':
                    switch (typeCode)
                    {
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                        isHex = true;
                        return("DEC2HEX({0})");

                    default:
                        return(string.Empty);
                    }

                case 'C':
                case 'c':
                    return(FormatHandler.GetCurrencyFormat(numberFormat, numberFormat.CurrencyDecimalDigits));

                case 'N':
                case 'n':
                    return(FormatHandler.GetNumberFormat(numberFormat, numberFormat.NumberDecimalDigits));

                case 'G':
                case 'g':
                    return("General");

                default:
                    return(FormatHandler.GetShortNumberFormat(format[0]));
                }
            }
            bool flag = false;
            int  num  = default(int);

            if (int.TryParse(format.Substring(1), out num))
            {
                switch (format[0])
                {
                case 'x':
                    switch (typeCode)
                    {
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                        isHex = true;
                        return("LOWER(DEC2HEX({0}, " + num + "))");

                    default:
                        return(string.Empty);
                    }

                case 'X':
                    switch (typeCode)
                    {
                    case TypeCode.SByte:
                    case TypeCode.Byte:
                    case TypeCode.Int16:
                    case TypeCode.UInt16:
                    case TypeCode.Int32:
                    case TypeCode.UInt32:
                    case TypeCode.Int64:
                    case TypeCode.UInt64:
                        isHex = true;
                        return("DEC2HEX({0}, " + num + ")");

                    default:
                        return(string.Empty);
                    }

                case 'C':
                case 'c':
                    return(FormatHandler.GetCurrencyFormat(numberFormat, num));

                case 'N':
                case 'n':
                    return(FormatHandler.GetNumberFormat(numberFormat, num));

                case 'G':
                case 'g':
                {
                    if (originalValue == null)
                    {
                        return(string.Empty);
                    }
                    char generalFormat = FormatHandler.GetGeneralFormat(typeCode, originalValue, num, cultureInfo);
                    isGeneral = true;
                    return(FormatHandler.GetLongNumberFormat(generalFormat, num));
                }

                default:
                    return(FormatHandler.GetLongNumberFormat(format[0], num));
                }
            }
            return(FormatHandler.GetExcelPictureNumberFormat(format));
        }