Geoffrey J. Teale 13 лет назад
Родитель
Сommit
18d5f1ea2b
6 измененных файлов с 75 добавлено и 106 удалено
  1. 33 39
      lib.go
  2. 25 41
      lib_test.go
  3. 4 7
      sharedstrings_test.go
  4. 7 10
      workbook.go
  5. 4 6
      workbook_test.go
  6. 2 3
      worksheet_test.go

+ 33 - 39
lib.go

@@ -2,28 +2,27 @@ package xlsx
 
 import (
 	"archive/zip"
+	"encoding/xml"
+	"errors"
 	"fmt"
 	"io"
 	"math"
-	"os"
 	"strconv"
 	"strings"
-	"xml"
 )
 
 // XLSXReaderError is the standard error type for otherwise undefined
 // errors in the XSLX reading process.
 type XLSXReaderError struct {
-	Error string
+	Err string
 }
 
 // String() returns a string value from an XLSXReaderError struct in
 // order that it might comply with the os.Error interface.
-func (e *XLSXReaderError) String() string {
-	return e.Error
+func (e *XLSXReaderError) Error() string {
+	return e.Err
 }
 
-
 // Cell is a high level structure intended to provide user access to
 // the contents of Cell within an xlsx.Row.
 type Cell struct {
@@ -59,26 +58,25 @@ type File struct {
 	Sheets         []*Sheet
 }
 
-
 // getRangeFromString is an internal helper function that converts
 // XLSX internal range syntax to a pair of integers.  For example,
 // the range string "1:3" yield the upper and lower intergers 1 and 3.
-func getRangeFromString(rangeString string) (lower int, upper int, error os.Error) {
+func getRangeFromString(rangeString string) (lower int, upper int, error error) {
 	var parts []string
 	parts = strings.SplitN(rangeString, ":", 2)
 	if parts[0] == "" {
-		error = os.NewError(fmt.Sprintf("Invalid range '%s'\n", rangeString))
+		error = errors.New(fmt.Sprintf("Invalid range '%s'\n", rangeString))
 	}
 	if parts[1] == "" {
-		error = os.NewError(fmt.Sprintf("Invalid range '%s'\n", rangeString))
+		error = errors.New(fmt.Sprintf("Invalid range '%s'\n", rangeString))
 	}
 	lower, error = strconv.Atoi(parts[0])
 	if error != nil {
-		error = os.NewError(fmt.Sprintf("Invalid range (not integer in lower bound) %s\n", rangeString))
+		error = errors.New(fmt.Sprintf("Invalid range (not integer in lower bound) %s\n", rangeString))
 	}
 	upper, error = strconv.Atoi(parts[1])
 	if error != nil {
-		error = os.NewError(fmt.Sprintf("Invalid range (not integer in upper bound) %s\n", rangeString))
+		error = errors.New(fmt.Sprintf("Invalid range (not integer in upper bound) %s\n", rangeString))
 	}
 	return lower, upper, error
 }
@@ -98,7 +96,6 @@ func positionalLetterMultiplier(extent, pos int) int {
 	return int(result)
 }
 
-
 // lettersToNumeric is used to convert a character based column
 // reference to a zero based numeric column identifier.
 func lettersToNumeric(letters string) int {
@@ -134,18 +131,17 @@ func lettersToNumeric(letters string) int {
 		multiplier := positionalLetterMultiplier(extent, i)
 		switch {
 		case 'A' <= c && c <= 'Z':
-			sum += multiplier * ((c - 'A') + shift)
+			sum += multiplier * (int((c - 'A')) + shift)
 		case 'a' <= c && c <= 'z':
-			sum += multiplier * ((c - 'a') + shift)
+			sum += multiplier * (int((c - 'a')) + shift)
 		}
 	}
 	return sum
 }
 
-
 // letterOnlyMapF is used in conjunction with strings.Map to return
 // only the characters A-Z and a-z in a string
-func letterOnlyMapF(rune int) int {
+func letterOnlyMapF(rune rune) rune {
 	switch {
 	case 'A' <= rune && rune <= 'Z':
 		return rune
@@ -155,21 +151,19 @@ func letterOnlyMapF(rune int) int {
 	return -1
 }
 
-
 // intOnlyMapF is used in conjunction with strings.Map to return only
 // the numeric portions of a string.
-func intOnlyMapF(rune int) int {
+func intOnlyMapF(rune rune) rune {
 	if rune >= 48 && rune < 58 {
 		return rune
 	}
 	return -1
 }
 
-
 // getCoordsFromCellIDString returns the zero based cartesian
 // coordinates from a cell name in Excel format, e.g. the cellIDString
 // "A1" returns 0, 0 and the "B3" return 1, 2.
-func getCoordsFromCellIDString(cellIDString string) (x, y int, error os.Error) {
+func getCoordsFromCellIDString(cellIDString string) (x, y int, error error) {
 	var letterPart string = strings.Map(letterOnlyMapF, cellIDString)
 	y, error = strconv.Atoi(strings.Map(intOnlyMapF, cellIDString))
 	if error != nil {
@@ -180,13 +174,12 @@ func getCoordsFromCellIDString(cellIDString string) (x, y int, error os.Error) {
 	return x, y, error
 }
 
-
 // makeRowFromSpan will, when given a span expressed as a string,
 // return an empty Row large enough to encompass that span and
 // populate it with empty cells.  All rows start from cell 1 -
 // regardless of the lower bound of the span.
 func makeRowFromSpan(spans string) *Row {
-	var error os.Error
+	var error error
 	var upper int
 	var row *Row
 	var cell *Cell
@@ -204,7 +197,7 @@ func makeRowFromSpan(spans string) *Row {
 		row.Cells[i] = cell
 	}
 	return row
-} 
+}
 
 // getValueFromCellData attempts to extract a valid value, usable in CSV form from the raw cell value.
 // Note - this is not actually general enough - we should support retaining tabs and newlines. 
@@ -221,12 +214,11 @@ func getValueFromCellData(rawcell XLSXC, reftable []string) string {
 			value = reftable[ref]
 		} else {
 			value = vval
-		}		
+		}
 	}
 	return value
 }
 
-
 // readRowsFromSheet is an internal helper function that extracts the
 // rows from a XSLXWorksheet, poulates them with Cells and resolves
 // the value references from the reference table and stores them in
@@ -249,26 +241,27 @@ func readRowsFromSheet(Worksheet *XLSXWorksheet, reftable []string) []*Row {
 	return rows
 }
 
-
 // readSheetsFromZipFile is an internal helper function that loops
 // over the Worksheets defined in the XSLXWorkbook and loads them into
 // Sheet objects stored in the Sheets slice of a xlsx.File struct.
-func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, os.Error) {
+func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, error) {
 	var workbook *XLSXWorkbook
-	var error os.Error
+	var error error
 	var rc io.ReadCloser
+	var decoder *xml.Decoder
 	workbook = new(XLSXWorkbook)
 	rc, error = f.Open()
 	if error != nil {
 		return nil, error
 	}
-	error = xml.Unmarshal(rc, workbook)
+	decoder = xml.NewDecoder(rc)
+	error = decoder.Decode(workbook)
 	if error != nil {
 		return nil, error
 	}
 	sheets := make([]*Sheet, len(workbook.Sheets.Sheet))
 	for i, rawsheet := range workbook.Sheets.Sheet {
-		worksheet, error := getWorksheetFromSheet(rawsheet, file.worksheets) // 
+		worksheet, error := getWorksheetFromSheet(rawsheet, file.worksheets)
 		if error != nil {
 			return nil, error
 		}
@@ -279,21 +272,22 @@ func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, os.Error) {
 	return sheets, nil
 }
 
-
 // readSharedStringsFromZipFile() is an internal helper function to
 // extract a reference table from the sharedStrings.xml file within
 // the XLSX zip file.
-func readSharedStringsFromZipFile(f *zip.File) ([]string, os.Error) {
+func readSharedStringsFromZipFile(f *zip.File) ([]string, error) {
 	var sst *XLSXSST
-	var error os.Error
+	var error error
 	var rc io.ReadCloser
+	var decoder *xml.Decoder
 	var reftable []string
 	rc, error = f.Open()
 	if error != nil {
 		return nil, error
 	}
 	sst = new(XLSXSST)
-	error = xml.Unmarshal(rc, sst)
+	decoder = xml.NewDecoder(rc)
+	error = decoder.Decode(sst)
 	if error != nil {
 		return nil, error
 	}
@@ -303,9 +297,9 @@ func readSharedStringsFromZipFile(f *zip.File) ([]string, os.Error) {
 
 // OpenFile() take the name of an XLSX file and returns a populated
 // xlsx.File struct for it.
-func OpenFile(filename string) (x *File, e os.Error) {
+func OpenFile(filename string) (x *File, e error) {
 	var f *zip.ReadCloser
-	var error os.Error
+	var error error
 	var file *File
 	var v *zip.File
 	var workbook *zip.File
@@ -339,7 +333,7 @@ func OpenFile(filename string) (x *File, e os.Error) {
 	}
 	if reftable == nil {
 		error := new(XLSXReaderError)
-		error.Error = "No valid sharedStrings.xml found in XLSX file"
+		error.Err = "No valid sharedStrings.xml found in XLSX file"
 		return nil, error
 	}
 	file.referenceTable = reftable
@@ -349,7 +343,7 @@ func OpenFile(filename string) (x *File, e os.Error) {
 	}
 	if sheets == nil {
 		error := new(XLSXReaderError)
-		error.Error = "No sheets found in XLSX File"
+		error.Err = "No sheets found in XLSX File"
 		return nil, error
 	}
 	file.Sheets = sheets

+ 25 - 41
lib_test.go

@@ -1,24 +1,21 @@
 package xlsx
 
-
 import (
 	"bytes"
-	"os"
+	"encoding/xml"
 	"strconv"
 	"strings"
 	"testing"
-	"xml"
 )
 
-
 // Test we can correctly open a XSLX file and return a xlsx.File
 // struct.
 func TestOpenFile(t *testing.T) {
 	var xlsxFile *File
-	var error os.Error
+	var error error
 	xlsxFile, error = OpenFile("testfile.xlsx")
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	if xlsxFile == nil {
@@ -33,12 +30,12 @@ func TestOpenFile(t *testing.T) {
 // themselves correct.
 func TestCreateSheet(t *testing.T) {
 	var xlsxFile *File
-	var error os.Error
+	var error error
 	var sheet *Sheet
 	var row *Row
 	xlsxFile, error = OpenFile("testfile.xlsx")
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	if xlsxFile == nil {
@@ -71,10 +68,10 @@ func TestCreateSheet(t *testing.T) {
 // reference table of string values from it.
 func TestReadSharedStringsFromZipFile(t *testing.T) {
 	var xlsxFile *File
-	var error os.Error
+	var error error
 	xlsxFile, error = OpenFile("testfile.xlsx")
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	if xlsxFile.referenceTable == nil {
@@ -83,9 +80,6 @@ func TestReadSharedStringsFromZipFile(t *testing.T) {
 	}
 }
 
-
-
-
 func TestLettersToNumeric(t *testing.T) {
 	var input string
 	var output int
@@ -126,10 +120,8 @@ func TestLettersToNumeric(t *testing.T) {
 		t.Error("Expected output 'AAA' == 676, but got ", strconv.Itoa(output))
 	}
 
-
 }
 
-
 func TestPositionalLetterMultiplier(t *testing.T) {
 	var output int
 	output = positionalLetterMultiplier(1, 0)
@@ -158,7 +150,6 @@ func TestPositionalLetterMultiplier(t *testing.T) {
 	}
 }
 
-
 func TestLetterOnlyMapFunction(t *testing.T) {
 	var input string = "ABC123"
 	var output string = strings.Map(letterOnlyMapF, input)
@@ -172,7 +163,6 @@ func TestLetterOnlyMapFunction(t *testing.T) {
 	}
 }
 
-
 func TestIntOnlyMapFunction(t *testing.T) {
 	var input string = "ABC123"
 	var output string = strings.Map(intOnlyMapF, input)
@@ -181,11 +171,10 @@ func TestIntOnlyMapFunction(t *testing.T) {
 	}
 }
 
-
 func TestGetCoordsFromCellIDString(t *testing.T) {
 	var cellIDString string = "A3"
 	var x, y int
-	var error os.Error
+	var error error
 	x, y, error = getCoordsFromCellIDString(cellIDString)
 	if error != nil {
 		t.Error(error)
@@ -201,7 +190,7 @@ func TestGetCoordsFromCellIDString(t *testing.T) {
 func TestGetRangeFromString(t *testing.T) {
 	var rangeString string
 	var lower, upper int
-	var error os.Error
+	var error error
 	rangeString = "1:3"
 	lower, upper, error = getRangeFromString(rangeString)
 	if error != nil {
@@ -215,18 +204,17 @@ func TestGetRangeFromString(t *testing.T) {
 	}
 }
 
-
 func TestMakeRowFromSpan(t *testing.T) {
 	var rangeString string
 	var row *Row
-	var length int 
+	var length int
 	rangeString = "1:3"
 	row = makeRowFromSpan(rangeString)
 	length = len(row.Cells)
 	if length != 3 {
 		t.Error("Expected a row with 3 cells, but got ", strconv.Itoa(length))
 	}
-	rangeString = "5:7"  	// Note - we ignore lower bound!
+	rangeString = "5:7" // Note - we ignore lower bound!
 	row = makeRowFromSpan(rangeString)
 	length = len(row.Cells)
 	if length != 7 {
@@ -293,15 +281,15 @@ func TestReadRowsFromSheet(t *testing.T) {
                footer="0.3"/>
 </worksheet>`)
 	worksheet := new(XLSXWorksheet)
-	error := xml.Unmarshal(sheetxml, worksheet)
+	error := xml.NewDecoder(sheetxml).Decode(worksheet)
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	sst := new(XLSXSST)
-	error = xml.Unmarshal(sharedstringsXML, sst)
+	error = xml.NewDecoder(sharedstringsXML).Decode(sst)
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	reftable := MakeSharedStringRefTable(sst)
@@ -321,10 +309,8 @@ func TestReadRowsFromSheet(t *testing.T) {
 	if cell2.String() != "Bar" {
 		t.Error("Expected cell2.String() == 'Bar', got ", cell2.String())
 	}
-	
-	
-}
 
+}
 
 func TestReadRowsFromSheetWithEmptyCells(t *testing.T) {
 	var sharedstringsXML = bytes.NewBufferString(`
@@ -386,15 +372,15 @@ func TestReadRowsFromSheetWithEmptyCells(t *testing.T) {
 
 `)
 	worksheet := new(XLSXWorksheet)
-	error := xml.Unmarshal(sheetxml, worksheet)
+	error := xml.NewDecoder(sheetxml).Decode(worksheet)
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	sst := new(XLSXSST)
-	error = xml.Unmarshal(sharedstringsXML, sst)
+	error = xml.NewDecoder(sharedstringsXML).Decode(sst)
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	reftable := MakeSharedStringRefTable(sst)
@@ -421,8 +407,6 @@ func TestReadRowsFromSheetWithEmptyCells(t *testing.T) {
 
 }
 
-
-
 func TestReadRowsFromSheetWithTrailingEmptyCells(t *testing.T) {
 	var row *Row
 	var cell1, cell2, cell3, cell4 *Cell
@@ -434,15 +418,15 @@ func TestReadRowsFromSheetWithTrailingEmptyCells(t *testing.T) {
 <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:D8"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="A7" sqref="A7"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/><sheetData><row r="1" spans="1:4"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c><c r="C1" t="s"><v>2</v></c><c r="D1" t="s"><v>3</v></c></row><row r="2" spans="1:4"><c r="A2"><v>1</v></c></row><row r="3" spans="1:4"><c r="B3"><v>1</v></c></row><row r="4" spans="1:4"><c r="C4"><v>1</v></c></row><row r="5" spans="1:4"><c r="D5"><v>1</v></c></row><row r="6" spans="1:4"><c r="C6"><v>1</v></c></row><row r="7" spans="1:4"><c r="B7"><v>1</v></c></row><row r="8" spans="1:4"><c r="A8"><v>1</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/></worksheet>
 `)
 	worksheet := new(XLSXWorksheet)
-	error := xml.Unmarshal(sheetxml, worksheet)
+	error := xml.NewDecoder(sheetxml).Decode(worksheet)
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	sst := new(XLSXSST)
-	error = xml.Unmarshal(sharedstringsXML, sst)
+	error = xml.NewDecoder(sharedstringsXML).Decode(sst)
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	reftable := MakeSharedStringRefTable(sst)
@@ -470,7 +454,7 @@ func TestReadRowsFromSheetWithTrailingEmptyCells(t *testing.T) {
 	if cell4.String() != "D" {
 		t.Error("Expected cell4.String() == 'D', got ", cell4.String())
 	}
-	
+
 	row = rows[1]
 	if len(row.Cells) != 4 {
 		t.Error("Expected len(row.Cells) == 4, got ", strconv.Itoa(len(row.Cells)))

+ 4 - 7
sharedstrings_test.go

@@ -1,10 +1,9 @@
 package xlsx
 
-
 import (
 	"bytes"
+	"encoding/xml"
 	"testing"
-	"xml"
 )
 
 // Test we can correctly convert a XLSXSST into a reference table using xlsx.MakeSharedStringRefTable().
@@ -12,7 +11,7 @@ func TestMakeSharedStringRefTable(t *testing.T) {
 	var 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>`)
 	sst := new(XLSXSST)
-	error := xml.Unmarshal(sharedstringsXML, sst)
+	error := xml.NewDecoder(sharedstringsXML).Decode(sst)
 	if error != nil {
 		t.Error(error.String())
 		return
@@ -31,13 +30,12 @@ func TestMakeSharedStringRefTable(t *testing.T) {
 
 }
 
-
 // Test we can correctly resolve a numeric reference in the reference table to a string value using xlsx.ResolveSharedString().
 func TestResolveSharedString(t *testing.T) {
 	var 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>`)
 	sst := new(XLSXSST)
-	error := xml.Unmarshal(sharedstringsXML, sst)
+	error := xml.NewDecoder(sharedstringsXML).Decode(sst)
 	if error != nil {
 		t.Error(error.String())
 		return
@@ -48,14 +46,13 @@ func TestResolveSharedString(t *testing.T) {
 	}
 }
 
-
 // Test we can correctly unmarshal an the sharedstrings.xml file into
 // an xlsx.XLSXSST struct and it's associated children.
 func TestUnmarshallSharedStrings(t *testing.T) {
 	var 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>`)
 	sst := new(XLSXSST)
-	error := xml.Unmarshal(sharedstringsXML, sst)
+	error := xml.NewDecoder(sharedstringsXML).Decode(sst)
 	if error != nil {
 		t.Error(error.String())
 		return

+ 7 - 10
workbook.go

@@ -2,10 +2,9 @@ package xlsx
 
 import (
 	"archive/zip"
+	"encoding/xml"
 	"fmt"
 	"io"
-	"os"
-	"xml"
 )
 
 // XLSXWorkbook directly maps the workbook element from the namespace
@@ -85,7 +84,6 @@ type XLSXDefinedNames struct {
 	DefinedName []XLSXDefinedName
 }
 
-
 // XLSXDefinedName directly maps the definedName element from the
 // namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
 // - currently I have not checked it for completeness - it does as
@@ -96,7 +94,6 @@ type XLSXDefinedName struct {
 	LocalSheetID string `xml:"attr"`
 }
 
-
 // XLSXCalcPr directly maps the calcPr element from the namespace
 // http://schemas.openxmlformats.org/spreadsheetml/2006/main -
 // currently I have not checked it for completeness - it does as much
@@ -105,13 +102,12 @@ type XLSXCalcPr struct {
 	CalcId string `xml:"attr"`
 }
 
-
-
 // getWorksheetFromSheet() is an internal helper function to open a sheetN.xml file, refered to by an xlsx.XLSXSheet struct, from the XLSX file and unmarshal it an xlsx.XLSXWorksheet struct 
-func getWorksheetFromSheet(sheet XLSXSheet, worksheets map[string]*zip.File) (*XLSXWorksheet, os.Error) {
+func getWorksheetFromSheet(sheet XLSXSheet, worksheets map[string]*zip.File) (*XLSXWorksheet, error) {
 	var rc io.ReadCloser
+	var decoder *xml.Decoder
 	var worksheet *XLSXWorksheet
-	var error os.Error
+	var error error
 	worksheet = new(XLSXWorksheet)
 	sheetName := fmt.Sprintf("sheet%s", sheet.SheetId)
 	f := worksheets[sheetName]
@@ -119,9 +115,10 @@ func getWorksheetFromSheet(sheet XLSXSheet, worksheets map[string]*zip.File) (*X
 	if error != nil {
 		return nil, error
 	}
-	error = xml.Unmarshal(rc, worksheet)
+	decoder = xml.NewDecoder(rc)
+	error = decoder.Decode(worksheet)
 	if error != nil {
 		return nil, error
 	}
-	return worksheet, nil 
+	return worksheet, nil
 }

+ 4 - 6
workbook_test.go

@@ -2,22 +2,21 @@ package xlsx
 
 import (
 	"bytes"
-	"os"
+	"encoding/xml"
 	"testing"
-	"xml"
 )
 
 // Test we can succesfully unmarshal the workbook.xml file from within
 // an XLSX file and return a XLSXWorkbook struct (and associated
 // children).
 func TestUnmarshallWorkbookXML(t *testing.T) {
-	var error os.Error
+	var error error
 	var buf = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?><workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4506"/><workbookPr defaultThemeVersion="124226"/><bookViews><workbookView xWindow="120" yWindow="75" windowWidth="15135" windowHeight="7620"/></bookViews><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/><sheet name="Sheet2" sheetId="2" r:id="rId2"/><sheet name="Sheet3" sheetId="3" r:id="rId3"/></sheets><definedNames><definedName name="monitors" localSheetId="0">Sheet1!$A$1533</definedName></definedNames><calcPr calcId="125725"/></workbook>`)
 	var workbook *XLSXWorkbook
 	workbook = new(XLSXWorkbook)
-	error = xml.Unmarshal(buf, workbook)
+	error = xml.NewDecoder(buf).Decode(workbook)
 	if error != nil {
-		t.Error(error.String())
+		t.Error(error.Error())
 		return
 	}
 	if workbook.FileVersion.AppName != "xl" {
@@ -81,4 +80,3 @@ func TestUnmarshallWorkbookXML(t *testing.T) {
 		t.Error("workbook.CalcPr.CalcId != '125725'")
 	}
 }
-

+ 2 - 3
worksheet_test.go

@@ -2,9 +2,9 @@ package xlsx
 
 import (
 	"bytes"
+	"encoding/xml"
 	"fmt"
 	"testing"
-	"xml"
 )
 
 // Test we can succesfully unmarshal the sheetN.xml files within and
@@ -13,7 +13,7 @@ func TestUnmarshallWorksheet(t *testing.T) {
 	var sheetxml = bytes.NewBufferString(`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1:B2"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="C2" sqref="C2"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/><sheetData><row r="1" spans="1:2"><c r="A1" t="s"><v>0</v></c><c r="B1" t="s"><v>1</v></c></row><row r="2" spans="1:2"><c r="A2" t="s"><v>2</v></c><c r="B2" t="s"><v>3</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.78740157499999996" bottom="0.78740157499999996" header="0.3" footer="0.3"/></worksheet>`)
 	worksheet := new(XLSXWorksheet)
-	error := xml.Unmarshal(sheetxml, worksheet)
+	error := xml.NewDecoder(sheetxml).Decode(worksheet)
 	if error != nil {
 		t.Error(error.String())
 		return
@@ -68,4 +68,3 @@ func TestUnmarshallWorksheet(t *testing.T) {
 	}
 
 }
-