Exemplo n.º 1
0
        public void TestTextWithDeciamlFormatSecondArg()
        {
            ValueEval numArg    = new NumberEval(321321.321);
            ValueEval formatArg = new StringEval("#,###.00000");

            ValueEval[] args   = { numArg, formatArg };
            ValueEval   result = TextFunction.TEXT.Evaluate(args, -1, (short)-1);

            //char groupSeparator = new DecimalFormatSymbols(Locale.GetDefault()).GetGroupingSeparator();
            //char decimalSeparator = new DecimalFormatSymbols(Locale.GetDefault()).GetDecimalSeparator();

            System.Globalization.CultureInfo ci = System.Globalization.CultureInfo.InstalledUICulture;
            string groupSeparator   = ci.NumberFormat.NumberGroupSeparator;
            string decimalSeparator = ci.NumberFormat.NumberDecimalSeparator;;

            ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");

            Assert.AreEqual(testResult.ToString(), result.ToString());
            numArg     = new NumberEval(321.321);
            formatArg  = new StringEval("00000.00000");
            args[0]    = numArg;
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval("00321" + decimalSeparator + "32100");
            Assert.AreEqual(testResult.ToString(), result.ToString());

            formatArg  = new StringEval("$#.#");
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval("$321" + decimalSeparator + "3");
            Assert.AreEqual(testResult.ToString(), result.ToString());
        }
Exemplo n.º 2
0
        public void TestTextWithDateFormatSecondArg()
        {
            System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.GetCultureInfo("en-US");
            ValueEval numArg    = new NumberEval(321.321);
            ValueEval formatArg = new StringEval("dd:MM:yyyy hh:mm:ss");

            ValueEval[] args       = { numArg, formatArg };
            ValueEval   result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            ValueEval   testResult = new StringEval("16:11:1900 07:42:14");

            Assert.AreEqual(testResult.ToString(), result.ToString());

            // this line is intended to compute how "November" would look like in the current locale
            String november = new SimpleDateFormat("MMMM").Format(new DateTime(2010, 11, 15));

            formatArg  = new StringEval("MMMM dd, yyyy");
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval(november + " 16, 1900");
            Assert.AreEqual(testResult.ToString(), result.ToString());
        }
Exemplo n.º 3
0
        public void TestTextWithDateFormatSecondArg()
        {
            // Test with Java style M=Month
            CultureShim.SetCurrentCulture("en-US");

            ValueEval numArg    = new NumberEval(321.321);
            ValueEval formatArg = new StringEval("dd:MM:yyyy hh:mm:ss");

            ValueEval[] args       = { numArg, formatArg };
            ValueEval   result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            ValueEval   testResult = new StringEval("16:11:1900 07:42:14");

            Assert.AreEqual(testResult.ToString(), result.ToString());

            // Excel also supports "m before h is month"
            formatArg  = new StringEval("dd:mm:yyyy hh:mm:ss");
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval("16:11:1900 07:42:14");
            //Assert.AreEqual(testResult.ToString(), result.ToString());

            // this line is intended to compute how "November" would look like in the current locale
            string november = new SimpleDateFormat("MMMM").Format(new DateTime(2010, 11, 15), CultureInfo.CurrentCulture);

            // Again with Java style
            formatArg = new StringEval("MMMM dd, yyyy");
            args[1]   = formatArg;
            //fix error in non-en Culture
            Npoi.Core.SS.Formula.Functions.Text.Formatter = new Npoi.Core.SS.UserModel.DataFormatter(CultureInfo.CurrentCulture);
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval(november + " 16, 1900");
            Assert.AreEqual(testResult.ToString(), result.ToString());

            // And Excel style
            formatArg  = new StringEval("mmmm dd, yyyy");
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval(november + " 16, 1900");
            Assert.AreEqual(testResult.ToString(), result.ToString());
        }
Exemplo n.º 4
0
        public void TestTextWithFractionFormatSecondArg()
        {
            ValueEval numArg    = new NumberEval(321.321);
            ValueEval formatArg = new StringEval("# #/#");

            ValueEval[] args       = { numArg, formatArg };
            ValueEval   result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            ValueEval   testResult = new StringEval("321 1/3");

            Assert.AreEqual(testResult.ToString(), result.ToString());  //this bug is caused by DecimalFormat

            formatArg  = new StringEval("# #/##");
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval("321 26/81");
            Assert.AreEqual(testResult.ToString(), result.ToString());

            formatArg  = new StringEval("#/##");
            args[1]    = formatArg;
            result     = TextFunction.TEXT.Evaluate(args, -1, (short)-1);
            testResult = new StringEval("26027/81");
            Assert.AreEqual(testResult.ToString(), result.ToString());
        }