@@ -752,7 +752,7 @@ func TestSetCellStyleNumberFormat(t *testing.T) {
752
752
expected := [][]string {
753
753
{"37947.7500001" , "37948" , "37947.75" , "37,948" , "37,947.75" , "3794775%" , "3794775.00%" , "3.79E+04" , "37947.7500001" , "37947.7500001" , "11-22-03" , "22-Nov-03" , "22-Nov" , "Nov-03" , "6:00 PM" , "6:00:00 PM" , "18:00" , "18:00:00" , "11/22/03 18:00" , "37,948 " , "37,948 " , "37,947.75 " , "37,947.75 " , "37947.7500001" , "37947.7500001" , "37947.7500001" , "37947.7500001" , "00:00" , "910746:00:00" , "00:00.0" , "37947.7500001" , "37947.7500001" },
754
754
{"-37947.7500001" , "-37948" , "-37947.75" , "-37,948" , "-37,947.75" , "-3794775%" , "-3794775.00%" , "-3.79E+04" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "(37,948)" , "(37,948)" , "(37,947.75)" , "(37,947.75)" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" , "-37947.7500001" },
755
- {"0.007" , "0" , "0.01" , "0" , "0.01" , "1%" , "0.70%" , "7.00E-03" , "0.007" , "0.007" , "12-30-99" , "30-Dec-99" , "30-Dec" , "Dec-99" , "0 :10 AM" , "0 :10:05 AM" , "00:10" , "00:10:05" , "12/30/99 00:10" , "0 " , "0 " , "0.01 " , "0.01 " , "0.007" , "0.007" , "0.007" , "0.007" , "10:05" , "0:10:05" , "10:04.8" , "0.007" , "0.007" },
755
+ {"0.007" , "0" , "0.01" , "0" , "0.01" , "1%" , "0.70%" , "7.00E-03" , "0.007" , "0.007" , "12-30-99" , "30-Dec-99" , "30-Dec" , "Dec-99" , "12 :10 AM" , "12 :10:05 AM" , "00:10" , "00:10:05" , "12/30/99 00:10" , "0 " , "0 " , "0.01 " , "0.01 " , "0.007" , "0.007" , "0.007" , "0.007" , "10:05" , "0:10:05" , "10:04.8" , "0.007" , "0.007" },
756
756
{"2.1" , "2" , "2.10" , "2" , "2.10" , "210%" , "210.00%" , "2.10E+00" , "2.1" , "2.1" , "01-01-00" , "1-Jan-00" , "1-Jan" , "Jan-00" , "2:24 AM" , "2:24:00 AM" , "02:24" , "02:24:00" , "1/1/00 02:24" , "2 " , "2 " , "2.10 " , "2.10 " , "2.1" , "2.1" , "2.1" , "2.1" , "24:00" , "50:24:00" , "24:00.0" , "2.1" , "2.1" },
757
757
{"String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" , "String" },
758
758
}
@@ -811,26 +811,61 @@ func TestSetCellStyleCurrencyNumberFormat(t *testing.T) {
811
811
assert .NoError (t , f .SetCellValue ("Sheet1" , "A1" , 42920.5 ))
812
812
assert .NoError (t , f .SetCellValue ("Sheet1" , "A2" , 42920.5 ))
813
813
814
- _ , err = f .NewStyle (& Style {NumFmt : 26 , Lang : "zh-tw" })
814
+ _ , err = f .NewStyle (& Style {NumFmt : 26 })
815
815
assert .NoError (t , err )
816
816
817
817
style , err := f .NewStyle (& Style {NumFmt : 27 })
818
818
assert .NoError (t , err )
819
819
820
820
assert .NoError (t , f .SetCellStyle ("Sheet1" , "A1" , "A1" , style ))
821
- style , err = f .NewStyle (& Style {NumFmt : 31 , Lang : "ko-kr" })
821
+ style , err = f .NewStyle (& Style {NumFmt : 31 })
822
822
assert .NoError (t , err )
823
823
824
824
assert .NoError (t , f .SetCellStyle ("Sheet1" , "A2" , "A2" , style ))
825
825
826
- style , err = f .NewStyle (& Style {NumFmt : 71 , Lang : "th-th" })
826
+ style , err = f .NewStyle (& Style {NumFmt : 71 })
827
827
assert .NoError (t , err )
828
828
assert .NoError (t , f .SetCellStyle ("Sheet1" , "A2" , "A2" , style ))
829
829
830
830
assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestSetCellStyleCurrencyNumberFormat.TestBook4.xlsx" )))
831
831
})
832
832
}
833
833
834
+ func TestSetCellStyleLangNumberFormat (t * testing.T ) {
835
+ rawCellValues := [][]string {{"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }}
836
+ for lang , expected := range map [CultureName ][][]string {
837
+ CultureNameUnknown : rawCellValues ,
838
+ CultureNameEnUS : {{"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"0:00:00" }, {"0:00:00" }, {"0:00:00" }, {"0:00:00" }, {"45162" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"8/24/23" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }},
839
+ CultureNameZhCN : {{"2023年8月" }, {"8月24日" }, {"8月24日" }, {"8/24/23" }, {"2023年8月24日" }, {"0时00分" }, {"0时00分00秒" }, {"上午12时00分" }, {"上午12时00分00秒" }, {"2023年8月" }, {"2023年8月" }, {"8月24日" }, {"2023年8月" }, {"8月24日" }, {"8月24日" }, {"上午12时00分" }, {"上午12时00分00秒" }, {"2023年8月" }, {"8月24日" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }},
840
+ } {
841
+ f , err := prepareTestBook5 (Options {CultureInfo : lang })
842
+ assert .NoError (t , err )
843
+ rows , err := f .GetRows ("Sheet1" )
844
+ assert .NoError (t , err )
845
+ assert .Equal (t , expected , rows )
846
+ assert .NoError (t , f .Close ())
847
+ }
848
+ // Test apply language number format code with date and time pattern
849
+ for lang , expected := range map [CultureName ][][]string {
850
+ CultureNameEnUS : {{"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"00:00:00" }, {"00:00:00" }, {"00:00:00" }, {"00:00:00" }, {"45162" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"2023-8-24" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }},
851
+ CultureNameZhCN : {{"2023年8月" }, {"8月24日" }, {"8月24日" }, {"2023-8-24" }, {"2023年8月24日" }, {"00:00:00" }, {"00:00:00" }, {"上午12时00分" }, {"上午12时00分00秒" }, {"2023年8月" }, {"2023年8月" }, {"8月24日" }, {"2023年8月" }, {"8月24日" }, {"8月24日" }, {"上午12时00分" }, {"上午12时00分00秒" }, {"2023年8月" }, {"8月24日" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }, {"45162" }},
852
+ } {
853
+ f , err := prepareTestBook5 (Options {CultureInfo : lang , ShortDatePattern : "yyyy-M-d" , LongTimePattern : "hh:mm:ss" })
854
+ assert .NoError (t , err )
855
+ rows , err := f .GetRows ("Sheet1" )
856
+ assert .NoError (t , err )
857
+ assert .Equal (t , expected , rows )
858
+ assert .NoError (t , f .Close ())
859
+ }
860
+ // Test open workbook with invalid date and time pattern options
861
+ _ , err := OpenFile (filepath .Join ("test" , "Book1.xlsx" ), Options {LongDatePattern : "0.00" })
862
+ assert .Equal (t , ErrUnsupportedNumberFormat , err )
863
+ _ , err = OpenFile (filepath .Join ("test" , "Book1.xlsx" ), Options {LongTimePattern : "0.00" })
864
+ assert .Equal (t , ErrUnsupportedNumberFormat , err )
865
+ _ , err = OpenFile (filepath .Join ("test" , "Book1.xlsx" ), Options {ShortDatePattern : "0.00" })
866
+ assert .Equal (t , ErrUnsupportedNumberFormat , err )
867
+ }
868
+
834
869
func TestSetCellStyleCustomNumberFormat (t * testing.T ) {
835
870
f := NewFile ()
836
871
assert .NoError (t , f .SetCellValue ("Sheet1" , "A1" , 42920.5 ))
@@ -1612,6 +1647,31 @@ func prepareTestBook4() (*File, error) {
1612
1647
return f , nil
1613
1648
}
1614
1649
1650
+ func prepareTestBook5 (opts Options ) (* File , error ) {
1651
+ f := NewFile (opts )
1652
+ var rowNum int
1653
+ for _ , idxRange := range [][]int {{27 , 36 }, {50 , 81 }} {
1654
+ for numFmtIdx := idxRange [0 ]; numFmtIdx <= idxRange [1 ]; numFmtIdx ++ {
1655
+ rowNum ++
1656
+ styleID , err := f .NewStyle (& Style {NumFmt : numFmtIdx })
1657
+ if err != nil {
1658
+ return f , err
1659
+ }
1660
+ cell , err := CoordinatesToCellName (1 , rowNum )
1661
+ if err != nil {
1662
+ return f , err
1663
+ }
1664
+ if err := f .SetCellValue ("Sheet1" , cell , 45162 ); err != nil {
1665
+ return f , err
1666
+ }
1667
+ if err := f .SetCellStyle ("Sheet1" , cell , cell , styleID ); err != nil {
1668
+ return f , err
1669
+ }
1670
+ }
1671
+ }
1672
+ return f , nil
1673
+ }
1674
+
1615
1675
func fillCells (f * File , sheet string , colCount , rowCount int ) error {
1616
1676
for col := 1 ; col <= colCount ; col ++ {
1617
1677
for row := 1 ; row <= rowCount ; row ++ {
0 commit comments