コード例 #1
0
        public void TestThreePartComplexFormat1()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
            // verify a rather complex format found e.g. in http://wahl.land-oberoesterreich.gv.at/Downloads/bp10.xls
            CellFormatPart posPart = new CellFormatPart("[$-F400]h:mm:ss\\ AM/PM");

            Assert.IsNotNull(posPart);
            DateTime baseTime  = new DateTime(1970, 1, 1, 0, 0, 0);
            double   exceldata = DateUtil.GetExcelDate(baseTime.AddMilliseconds(12345));

            //format part 'h', means hour, using a 12-hour clock from 1 to 12.(in excel and .net framework)
            //so the excepted value should be 12:00:12 AM
            Assert.AreEqual("12:00:12 AM", posPart.Apply(baseTime.AddMilliseconds(12345)).Text);

            CellFormatPart negPart = new CellFormatPart("[$-F40]h:mm:ss\\ AM/PM");

            Assert.IsNotNull(negPart);
            Assert.AreEqual("12:00:12 AM", posPart.Apply(baseTime.AddMilliseconds(12345)).Text);
            //Assert.IsNotNull(new CellFormatPart("_-* \"\"??_-;_-@_-"));

            CellFormat instance = CellFormat.GetInstance("[$-F400]h:mm:ss\\ AM/PM;[$-F40]h:mm:ss\\ AM/PM;_-* \"\"??_-;_-@_-");

            Assert.IsNotNull(instance);
            Assert.AreEqual("12:00:12 AM", instance.Apply(baseTime.AddMilliseconds(12345)).Text);
        }
コード例 #2
0
ファイル: CellFormatTestBase.cs プロジェクト: IMULMUL/npoi
        private String tryColor(String desc, String cname, CellValue getter,
                                Object value, String expectedText, Color expectedColor)
        {
            if (cname != null)
            {
                desc = "[" + cname + "]" + desc;
            }
            Color            origColor = labelForeColor;
            CellFormatPart   format    = new CellFormatPart(desc);
            CellFormatResult result    = format.Apply(value);

            if (!result.Applies)
            {
                // If this doesn't Apply, no color change is expected
                expectedColor = origColor;
            }

            String actualText  = result.Text;
            Color  actualColor = labelForeColor;

            getter.Equivalent(expectedText, actualText, format);
            Assert.AreEqual(
                expectedColor, actualColor, cname == null ? "no color" : "color " + cname);
            return(actualText);
        }
コード例 #3
0
        public void TestThreePartComplexFormat2()
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("en-US");
            // verify a rather complex format found e.g. in http://wahl.land-oberoesterreich.gv.at/Downloads/bp10.xls
            CellFormatPart posPart = new CellFormatPart("dd/mm/yyyy");

            Assert.IsNotNull(posPart);
            DateTime baseTime = new DateTime(1970, 1, 1);

            Assert.AreEqual("01/01/1970", posPart.Apply(baseTime.AddMilliseconds(12345)).Text);

            CellFormatPart negPart = new CellFormatPart("dd/mm/yyyy");

            Assert.IsNotNull(negPart);
            Assert.AreEqual("01/01/1970", posPart.Apply(baseTime.AddMilliseconds(12345)).Text);
            //Assert.IsNotNull(new CellFormatPart("_-* \"\"??_-;_-@_-"));

            CellFormat instance = CellFormat.GetInstance("dd/mm/yyyy;dd/mm/yyyy;_-* \"\"??_-;_-@_-");

            Assert.IsNotNull(instance);
            Assert.AreEqual("01/01/1970", instance.Apply(baseTime.AddMilliseconds(12345)).Text);
        }
コード例 #4
0
ファイル: CellFormatTestBase.cs プロジェクト: ctddjyds/npoi
        private String tryColor(String desc, String cname, CellValue Getter,
                Object value, String expectedText, Color expectedColor)
        {

            if (cname != null)
                desc = "[" + cname + "]" + desc;
            Color origColor = label.ForeColor;
            CellFormatPart format = new CellFormatPart(desc);
            if (!format.Apply(label, value).Applies)
            {
                // If this doesn't Apply, no color change is expected
                expectedColor = origColor;
            }

            String actualText = label.Text;
            Color actualColor = label.ForeColor;
            Getter.Equivalent(expectedText, actualText, format);
            Assert.AreEqual(
                    expectedColor, actualColor,cname == null ? "no color" : "color " + cname);
            return actualText;
        }