-
Notifications
You must be signed in to change notification settings - Fork 818
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split sharedstrings.go and renamed to reftable.go and xmlSharedString…
…s.go
- Loading branch information
Showing
4 changed files
with
92 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package xlsx | ||
|
||
import ( | ||
"encoding/xml" | ||
) | ||
|
||
// xlsxSST directly maps the sst element from the namespace | ||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main currently | ||
// I have not checked this for completeness - it does as much as I need. | ||
type xlsxSST struct { | ||
XMLName xml.Name `xml:"http://schemas.openxmlformats.org/spreadsheetml/2006/main sst"` | ||
Count int `xml:"count,attr"` | ||
UniqueCount int `xml:"uniqueCount,attr"` | ||
SI []xlsxSI `xml:"si"` | ||
} | ||
|
||
// xlsxSI directly maps the si element from the namespace | ||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - | ||
// currently I have not checked this for completeness - it does as | ||
// much as I need. | ||
type xlsxSI struct { | ||
T string `xml:"t"` | ||
R []xlsxR `xml:"r"` | ||
} | ||
|
||
// xlsxR directly maps the r element from the namespace | ||
// http://schemas.openxmlformats.org/spreadsheetml/2006/main - | ||
// currently I have not checked this for completeness - it does as | ||
// much as I need. | ||
type xlsxR struct { | ||
T string `xml:"t"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package xlsx | ||
|
||
import ( | ||
"bytes" | ||
"encoding/xml" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
||
type SharedStringsSuite struct { | ||
SharedStringsXML *bytes.Buffer | ||
} | ||
|
||
var _ = Suite(&SharedStringsSuite{}) | ||
|
||
func (s *SharedStringsSuite) SetUpTest(c *C) { | ||
s.SharedStringsXML = bytes.NewBufferString( | ||
`<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" | ||
count="4" | ||
uniqueCount="4"> | ||
<si> | ||
<t>Foo</t> | ||
</si> | ||
<si> | ||
<t>Bar</t> | ||
</si> | ||
<si> | ||
<t xml:space="preserve">Baz </t> | ||
</si> | ||
<si> | ||
<t>Quuk</t> | ||
</si> | ||
</sst>`) | ||
} | ||
|
||
// Test we can correctly unmarshal an the sharedstrings.xml file into | ||
// an xlsx.xlsxSST struct and it's associated children. | ||
func (s *SharedStringsSuite) TestUnmarshallSharedStrings(c *C) { | ||
sst := new(xlsxSST) | ||
err := xml.NewDecoder(s.SharedStringsXML).Decode(sst) | ||
c.Assert(err, IsNil) | ||
c.Assert(sst.Count, Equals, 4) | ||
c.Assert(sst.UniqueCount, Equals, 4) | ||
c.Assert(sst.SI, HasLen, 4) | ||
si := sst.SI[0] | ||
c.Assert(si.T, Equals, "Foo") | ||
} |