11package goxcel
22
33import (
4+ "fmt"
45 "os"
56 "path/filepath"
67 "testing"
@@ -9,6 +10,53 @@ import (
910 "github.com/devlights/goxcel/testutil"
1011)
1112
13+ func TestWorksheet_UsedRange (t * testing.T ) {
14+ f := MustInitGoxcel ()
15+ defer f ()
16+
17+ g , r := MustNewGoxcel ()
18+ defer r ()
19+
20+ g .MustSilent (true )
21+
22+ wbs := g .MustWorkbooks ()
23+ wb , wbr := wbs .MustAdd ()
24+ defer wbr ()
25+
26+ ws := wb .MustSheets (1 )
27+
28+ c := ws .MustCells (1 , 1 )
29+ c .MustSetValue (fmt .Sprintf ("%v_%v" , 1 , 1 ))
30+
31+ c = ws .MustCells (100 , 1 )
32+ c .MustSetValue (fmt .Sprintf ("%v_%v" , 100 , 1 ))
33+
34+ c = ws .MustCells (50 , 100 )
35+ c .MustSetValue (fmt .Sprintf ("%v_%v" , 50 , 100 ))
36+
37+ // UsedRange は、書式設定されているだけのセルも範囲に入る
38+ c = ws .MustCells (200 , 1 )
39+ interior , _ := c .Interior ()
40+ _ = interior .SetColor (constants .RgbGreen )
41+
42+ ra , err := ws .UsedRange ()
43+ if err != nil {
44+ t .Error (err )
45+ }
46+
47+ rows , _ := ra .Rows ()
48+ count , _ := rows .Count ()
49+ if count != 200 {
50+ t .Errorf ("[want] 200\t [got] %v" , count )
51+ }
52+
53+ cols , _ := ra .Columns ()
54+ count , _ = cols .Count ()
55+ if count != 100 {
56+ t .Errorf ("[want] 100\t [got] %v" , count )
57+ }
58+ }
59+
1260func TestWorksheet_MaxRowCol (t * testing.T ) {
1361 f := MustInitGoxcel ()
1462 defer f ()
@@ -30,6 +78,11 @@ func TestWorksheet_MaxRowCol(t *testing.T) {
3078 c = ws .MustCells (100 , 1 )
3179 c .MustSetValue ("world" )
3280
81+ // MaxRow, MaxCol, MaxRowCol は、書式設定されているだけのセルは範囲に入れない
82+ c = ws .MustCells (200 , 1 )
83+ interior , _ := c .Interior ()
84+ _ = interior .SetColor (constants .RgbGreen )
85+
3386 maxRow , maxCol , err := ws .MaxRowCol (1 , 1 )
3487 if err != nil {
3588 t .Error (err )
0 commit comments