Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No longer exporting private types #6

Merged
merged 1 commit into from Apr 11, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 11 additions & 11 deletions lib.go
Expand Up @@ -109,20 +109,20 @@ func lettersToNumeric(letters string) int {
// 0s and therefore A can be both a 1 and a 0. The
// value range of a letter is different in the most
// significant position if (and only if) there is more
// than one positions. For example:
// "A" = 0
// than one positions. For example:
// "A" = 0
// 676 | 26 | 0
// ----+----+----
// 0 | 0 | 0
//
//
// "Z" = 25
// 676 | 26 | 0
// ----+----+----
// 0 | 0 | 25
// "AA" = 26
// 676 | 26 | 0
// ----+----+----
// 0 | 1 | 0 <--- note here - the value of "A" maps to both 1 and 0.
// 0 | 1 | 0 <--- note here - the value of "A" maps to both 1 and 0.
if i == 0 && extent > 1 {
shift = 1
} else {
Expand Down Expand Up @@ -200,8 +200,8 @@ func makeRowFromSpan(spans string) *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.
func getValueFromCellData(rawcell XLSXC, reftable []string) string {
// Note - this is not actually general enough - we should support retaining tabs and newlines.
func getValueFromCellData(rawcell xlsxC, reftable []string) string {
var value string = ""
var data string = rawcell.V
if len(data) > 0 {
Expand All @@ -222,7 +222,7 @@ func getValueFromCellData(rawcell XLSXC, reftable []string) string {
// 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
func readRowsFromSheet(Worksheet *XLSXWorksheet, reftable []string) []*Row {
func readRowsFromSheet(Worksheet *xlsxWorksheet, reftable []string) []*Row {
var rows []*Row
var row *Row

Expand All @@ -245,11 +245,11 @@ func readRowsFromSheet(Worksheet *XLSXWorksheet, reftable []string) []*Row {
// 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, error) {
var workbook *XLSXWorkbook
var workbook *xlsxWorkbook
var error error
var rc io.ReadCloser
var decoder *xml.Decoder
workbook = new(XLSXWorkbook)
workbook = new(xlsxWorkbook)
rc, error = f.Open()
if error != nil {
return nil, error
Expand All @@ -276,7 +276,7 @@ func readSheetsFromZipFile(f *zip.File, file *File) ([]*Sheet, error) {
// extract a reference table from the sharedStrings.xml file within
// the XLSX zip file.
func readSharedStringsFromZipFile(f *zip.File) ([]string, error) {
var sst *XLSXSST
var sst *xlsxSST
var error error
var rc io.ReadCloser
var decoder *xml.Decoder
Expand All @@ -285,7 +285,7 @@ func readSharedStringsFromZipFile(f *zip.File) ([]string, error) {
if error != nil {
return nil, error
}
sst = new(XLSXSST)
sst = new(xlsxSST)
decoder = xml.NewDecoder(rc)
error = decoder.Decode(sst)
if error != nil {
Expand Down
22 changes: 11 additions & 11 deletions lib_test.go
Expand Up @@ -249,7 +249,7 @@ func TestReadRowsFromSheet(t *testing.T) {
</sst>`)
var sheetxml = bytes.NewBufferString(`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"
xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
<dimension ref="A1:B2"/>
<sheetViews>
Expand All @@ -276,19 +276,19 @@ func TestReadRowsFromSheet(t *testing.T) {
</c>
</row>
</sheetData>
<pageMargins left="0.7" right="0.7"
top="0.78740157499999996"
bottom="0.78740157499999996"
header="0.3"
<pageMargins left="0.7" right="0.7"
top="0.78740157499999996"
bottom="0.78740157499999996"
header="0.3"
footer="0.3"/>
</worksheet>`)
worksheet := new(XLSXWorksheet)
worksheet := new(xlsxWorksheet)
error := xml.NewDecoder(sheetxml).Decode(worksheet)
if error != nil {
t.Error(error.Error())
return
}
sst := new(XLSXSST)
sst := new(xlsxSST)
error = xml.NewDecoder(sharedstringsXML).Decode(sst)
if error != nil {
t.Error(error.Error())
Expand Down Expand Up @@ -373,13 +373,13 @@ func TestReadRowsFromSheetWithEmptyCells(t *testing.T) {
</worksheet>

`)
worksheet := new(XLSXWorksheet)
worksheet := new(xlsxWorksheet)
error := xml.NewDecoder(sheetxml).Decode(worksheet)
if error != nil {
t.Error(error.Error())
return
}
sst := new(XLSXSST)
sst := new(xlsxSST)
error = xml.NewDecoder(sharedstringsXML).Decode(sst)
if error != nil {
t.Error(error.Error())
Expand Down Expand Up @@ -419,13 +419,13 @@ func TestReadRowsFromSheetWithTrailingEmptyCells(t *testing.T) {
<?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: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)
worksheet := new(xlsxWorksheet)
error := xml.NewDecoder(sheetxml).Decode(worksheet)
if error != nil {
t.Error(error.Error())
return
}
sst := new(XLSXSST)
sst := new(xlsxSST)
error = xml.NewDecoder(sharedstringsXML).Decode(sst)
if error != nil {
t.Error(error.Error())
Expand Down
18 changes: 9 additions & 9 deletions sharedstrings.go
@@ -1,38 +1,38 @@
package xlsx


// XLSXSST directly maps the sst element from the namespace
// 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 need.
type XLSXSST struct {
type xlsxSST struct {
Count string `xml:"count,attr"`
UniqueCount string `xml:"uniqueCount,attr"`
SI []XLSXSI `xml:"si"`
SI []xlsxSI `xml:"si"`
}


// XLSXSI directly maps the si element from the namespace
// 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 {
type xlsxSI struct {
T string `xml:"t"`
}

// // XLSXT directly maps the t element from the namespace
// // xlsxT directly maps the t 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 XLSXT struct {
// type xlsxT struct {
// Data string `xml:"chardata"`
// }


// MakeSharedStringRefTable() takes an XLSXSST struct and converts
// MakeSharedStringRefTable() takes an xlsxSST struct and converts
// it's contents to an slice of strings used to refer to string values
// by numeric index - this is the model used within XLSX worksheet (a
// numeric reference is stored to a shared cell value).
func MakeSharedStringRefTable(source *XLSXSST) []string {
func MakeSharedStringRefTable(source *xlsxSST) []string {
reftable := make([]string, len(source.SI))
for i, si := range source.SI {
reftable[i] = si.T
Expand Down
10 changes: 5 additions & 5 deletions sharedstrings_test.go
Expand Up @@ -6,11 +6,11 @@ import (
"testing"
)

// Test we can correctly convert a XLSXSST into a reference table using xlsx.MakeSharedStringRefTable().
// Test we can correctly convert a xlsxSST into a reference table using xlsx.MakeSharedStringRefTable().
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)
sst := new(xlsxSST)
error := xml.NewDecoder(sharedstringsXML).Decode(sst)
if error != nil {
t.Error(error.Error())
Expand All @@ -34,7 +34,7 @@ func TestMakeSharedStringRefTable(t *testing.T) {
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)
sst := new(xlsxSST)
error := xml.NewDecoder(sharedstringsXML).Decode(sst)
if error != nil {
t.Error(error.Error())
Expand All @@ -47,11 +47,11 @@ 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.
// 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)
sst := new(xlsxSST)
error := xml.NewDecoder(sharedstringsXML).Decode(sst)
if error != nil {
t.Error(error.Error())
Expand Down
66 changes: 33 additions & 33 deletions workbook.go
Expand Up @@ -7,108 +7,108 @@ import (
"io"
)

// XLSXWorkbook directly maps the workbook element from the namespace
// xlsxWorkbook directly maps the workbook element from the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main -
// currently I have not checked it for completeness - it does as much
// as I need.
type XLSXWorkbook struct {
FileVersion XLSXFileVersion `xml:"fileVersion"`
WorkbookPr XLSXWorkbookPr `xml:"workbookPr"`
BookViews XLSXBookViews `xml:"bookViews"`
Sheets XLSXSheets `xml:"sheets"`
DefinedNames XLSXDefinedNames `xml:"definedNames"`
CalcPr XLSXCalcPr `xml:"calcPr"`
type xlsxWorkbook struct {
FileVersion xlsxFileVersion `xml:"fileVersion"`
WorkbookPr xlsxWorkbookPr `xml:"workbookPr"`
BookViews xlsxBookViews `xml:"bookViews"`
Sheets xlsxSheets `xml:"sheets"`
DefinedNames xlsxDefinedNames `xml:"definedNames"`
CalcPr xlsxCalcPr `xml:"calcPr"`
}

// XLSXFileVersion directly maps the fileVersion element from the
// xlsxFileVersion directly maps the fileVersion element from the
// namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
// - currently I have not checked it for completeness - it does as
// much as I need.
type XLSXFileVersion struct {
type xlsxFileVersion struct {
AppName string `xml:"appName,attr"`
LastEdited string `xml:"lastEdited,attr"`
LowestEdited string `xml:"lowestEdited,attr"`
RupBuild string `xml:"rupBuild,attr"`
}

// XLSXWorkbookPr directly maps the workbookPr element from the
// xlsxWorkbookPr directly maps the workbookPr element from the
// namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
// - currently I have not checked it for completeness - it does as
// much as I need.
type XLSXWorkbookPr struct {
type xlsxWorkbookPr struct {
DefaultThemeVersion string `xml:"defaultThemeVersion,attr"`
}

// XLSXBookViews directly maps the bookViews element from the
// xlsxBookViews directly maps the bookViews element from the
// namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
// - currently I have not checked it for completeness - it does as
// much as I need.
type XLSXBookViews struct {
WorkBookView []XLSXWorkBookView `xml:"workbookView"`
type xlsxBookViews struct {
WorkBookView []xlsxWorkBookView `xml:"workbookView"`
}

// XLSXWorkBookView directly maps the workbookView element from the
// xlsxWorkBookView directly maps the workbookView element from the
// namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
// - currently I have not checked it for completeness - it does as
// much as I need.
type XLSXWorkBookView struct {
type xlsxWorkBookView struct {
XWindow string `xml:"xWindow,attr"`
YWindow string `xml:"yWindow,attr"`
WindowWidth string `xml:"windowWidth,attr"`
WindowHeight string `xml:"windowHeight,attr"`
}

// XLSXSheets directly maps the sheets element from the namespace
// xlsxSheets directly maps the sheets element from the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main -
// currently I have not checked it for completeness - it does as much
// as I need.
type XLSXSheets struct {
Sheet []XLSXSheet `xml:"sheet"`
type xlsxSheets struct {
Sheet []xlsxSheet `xml:"sheet"`
}

// XLSXSheet directly maps the sheet element from the namespace
// xlsxSheet directly maps the sheet element from the namespace
// http://schemas.openxmlformats.org/spreadsheetml/2006/main -
// currently I have not checked it for completeness - it does as much
// as I need.
type XLSXSheet struct {
type xlsxSheet struct {
Name string `xml:"name,attr"`
SheetId string `xml:"sheetId,attr"`
Id string `xml:"id,attr"`
}

// XLSXDefinedNames directly maps the definedNames element from the
// xlsxDefinedNames directly maps the definedNames element from the
// namespace http://schemas.openxmlformats.org/spreadsheetml/2006/main
// - currently I have not checked it for completeness - it does as
// much as I need.
type XLSXDefinedNames struct {
DefinedName []XLSXDefinedName `xml:"definedName"`
type xlsxDefinedNames struct {
DefinedName []xlsxDefinedName `xml:"definedName"`
}

// XLSXDefinedName directly maps the definedName element from the
// 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
// much as I need.
type XLSXDefinedName struct {
type xlsxDefinedName struct {
Data string `xml:",chardata"`
Name string `xml:"name,attr"`
LocalSheetID string `xml:"localSheetId,attr"`
}

// XLSXCalcPr directly maps the calcPr element from the namespace
// 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
// as I need.
type XLSXCalcPr struct {
type xlsxCalcPr struct {
CalcId string `xml:"calcId,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, error) {
// 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, error) {
var rc io.ReadCloser
var decoder *xml.Decoder
var worksheet *XLSXWorksheet
var worksheet *xlsxWorksheet
var error error
worksheet = new(XLSXWorksheet)
worksheet = new(xlsxWorksheet)
sheetName := fmt.Sprintf("sheet%s", sheet.SheetId)
f := worksheets[sheetName]
rc, error = f.Open()
Expand Down
6 changes: 3 additions & 3 deletions workbook_test.go
Expand Up @@ -7,13 +7,13 @@ import (
)

// Test we can succesfully unmarshal the workbook.xml file from within
// an XLSX file and return a XLSXWorkbook struct (and associated
// an XLSX file and return a xlsxWorkbook struct (and associated
// children).
func TestUnmarshallWorkbookXML(t *testing.T) {
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)
var workbook *xlsxWorkbook
workbook = new(xlsxWorkbook)
error = xml.NewDecoder(buf).Decode(workbook)
if error != nil {
t.Error(error.Error())
Expand Down