Skip to content

Commit

Permalink
This closes #1312, #1313, fix number format issue
Browse files Browse the repository at this point in the history
- Add supported options in the docs of the functions `SetSheetPrOptions` and `GetSheetPrOptions`
- Add go1.19 unit test settings, and made the test case compatible with go1.19
- Update dependencies module
  • Loading branch information
xuri committed Aug 11, 2022
1 parent ed91cdd commit 8152bbb
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jobs:
test:
strategy:
matrix:
go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x]
go-version: [1.15.x, 1.16.x, 1.17.x, 1.18.x, 1.19.x]
os: [ubuntu-latest, macos-latest, windows-latest]
targetplatform: [x86, x64]

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ require (
github.com/stretchr/testify v1.7.1
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced
golang.org/x/text v0.3.7
gopkg.in/yaml.v3 v3.0.0 // indirect
)
10 changes: 5 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ github.com/xuri/efp v0.0.0-20220603152613-6918739fd470 h1:6932x8ltq1w4utjmfMPVj0
github.com/xuri/efp v0.0.0-20220603152613-6918739fd470/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22 h1:OAmKAfT06//esDdpi/DZ8Qsdt4+M5+ltca05dA5bG2M=
github.com/xuri/nfp v0.0.0-20220409054826-5e722a1d9e22/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa h1:zuSxTR4o9y82ebqCUJYNGJbGPo6sKVl54f/TVDObg1c=
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9 h1:LRtI4W37N+KFebI/qV0OFiLUv4GLOWeEW5hn/KEJvxE=
golang.org/x/image v0.0.0-20220413100746-70e8d0d3baa9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e h1:TsQ7F31D3bUCLeqPT0u+yjp1guoArKaNKmCr22PYgTQ=
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced h1:3dYNDff0VT5xj+mbj2XucFst9WKk6PdGOrb9n+SbIvw=
golang.org/x/net v0.0.0-20220809184613-07c6da5e1ced/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
4 changes: 4 additions & 0 deletions lib_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"io"
"os"
"runtime"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -340,6 +341,9 @@ func TestReadBytes(t *testing.T) {
}

func TestUnzipToTemp(t *testing.T) {
if strings.HasPrefix(runtime.Version(), "go1.19") {
t.Skip()
}
os.Setenv("TMPDIR", "test")
defer os.Unsetenv("TMPDIR")
assert.NoError(t, os.Chmod(os.TempDir(), 0o444))
Expand Down
4 changes: 2 additions & 2 deletions numfmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ func (nf *numberFormat) positiveHandler() (result string) {
nf.result += token.TValue
continue
}
if token.TType == nfp.TokenTypeZeroPlaceHolder && token.TValue == "0" {
if token.TType == nfp.TokenTypeZeroPlaceHolder && token.TValue == strings.Repeat("0", len(token.TValue)) {
if isNum, precision := isNumeric(nf.value); isNum {
if nf.number < 1 {
nf.result += "0"
Expand Down Expand Up @@ -899,7 +899,7 @@ func (nf *numberFormat) negativeHandler() (result string) {
nf.result += token.TValue
continue
}
if token.TType == nfp.TokenTypeZeroPlaceHolder && token.TValue == "0" {
if token.TType == nfp.TokenTypeZeroPlaceHolder && token.TValue == strings.Repeat("0", len(token.TValue)) {
if isNum, precision := isNumeric(nf.value); isNum {
if math.Abs(nf.number) < 1 {
nf.result += "0"
Expand Down
24 changes: 13 additions & 11 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,19 @@ func TestRowsGetRowOpts(t *testing.T) {
rows, err := f.Rows(sheetName)
require.NoError(t, err)

rows.Next()
rows.Columns() // Columns() may change the XML iterator, so better check with and without calling it
got := rows.GetRowOpts()
assert.Equal(t, expectedRowStyleID1, got)
rows.Next()
got = rows.GetRowOpts()
assert.Equal(t, expectedRowStyleID2, got)
rows.Next()
rows.Columns()
got = rows.GetRowOpts()
assert.Equal(t, expectedRowStyleID3, got)
assert.Equal(t, true, rows.Next())
_, err = rows.Columns()
require.NoError(t, err)
rowOpts := rows.GetRowOpts()
assert.Equal(t, expectedRowStyleID1, rowOpts)
assert.Equal(t, true, rows.Next())
rowOpts = rows.GetRowOpts()
assert.Equal(t, expectedRowStyleID2, rowOpts)
assert.Equal(t, true, rows.Next())
_, err = rows.Columns()
require.NoError(t, err)
rowOpts = rows.GetRowOpts()
assert.Equal(t, expectedRowStyleID3, rowOpts)
}

func TestRowsError(t *testing.T) {
Expand Down
8 changes: 8 additions & 0 deletions sheetpr.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ func (o *AutoPageBreaks) getSheetPrOption(pr *xlsxSheetPr) {
// EnableFormatConditionsCalculation(bool)
// Published(bool)
// FitToPage(bool)
// TabColorIndexed(int)
// TabColorRGB(string)
// TabColorTheme(int)
// TabColorTint(float64)
// AutoPageBreaks(bool)
// OutlineSummaryBelow(bool)
func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error {
Expand All @@ -268,6 +272,10 @@ func (f *File) SetSheetPrOptions(sheet string, opts ...SheetPrOption) error {
// EnableFormatConditionsCalculation(bool)
// Published(bool)
// FitToPage(bool)
// TabColorIndexed(int)
// TabColorRGB(string)
// TabColorTheme(int)
// TabColorTint(float64)
// AutoPageBreaks(bool)
// OutlineSummaryBelow(bool)
func (f *File) GetSheetPrOptions(sheet string, opts ...SheetPrOptionPtr) error {
Expand Down

0 comments on commit 8152bbb

Please sign in to comment.