Browse Source

* lib.go: Added MakeSharedStringRefTable
* lib_test.go: Tested MakeSharedStringRefTable

Geoffrey J. Teale 14 years ago
parent
commit
4304de9880
2 changed files with 40 additions and 1 deletions
  1. 14 1
      lib.go
  2. 26 0
      lib_test.go

+ 14 - 1
lib.go

@@ -5,7 +5,6 @@ import (
 	"io"
 	"os"
 	"xml"
-
 )
 
 type XLSXV struct {
@@ -141,6 +140,15 @@ type XLSXFileInterface interface  {
 }
 
 
+func MakeSharedStringRefTable(source *XLSXSST) []string {
+	reftable := make([]string, len(source.SI))
+	for i, si := range source.SI {
+		reftable[i] = si.T.Data
+	}
+	return reftable
+}
+
+
 func readSheetsFromZipFile(f *zip.File) os.Error {
 	var workbook *XLSXWorkbook
 	var error os.Error
@@ -154,6 +162,11 @@ func readSheetsFromZipFile(f *zip.File) os.Error {
 	if error != nil {
 		return error
 	}
+	// for _, rawsheet := range workbook.Sheets.Sheet {
+	// 	sheet := new(XLSXSheetStruct)
+		
+		
+	// }
 	return nil
 }
 

+ 26 - 0
lib_test.go

@@ -37,6 +37,30 @@ func TestExtractSheets(t *testing.T) {
 }
 
 
+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)
+	if error != nil {
+		t.Error(error.String())
+		return
+	}
+	reftable := MakeSharedStringRefTable(sst)
+	if len(reftable) == 0 {
+		t.Error("Reftable is zero length.")
+		return
+	}
+	if reftable[0] != "Foo" {
+		t.Error("RefTable lookup failed, expected reftable[0] == 'Foo'")
+	}
+	if reftable[1] != "Bar" {
+		t.Error("RefTable lookup failed, expected reftable[1] == 'Bar'")
+	}
+
+}
+
+
 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>`)
@@ -123,6 +147,8 @@ func TestUnmarshallSheet(t *testing.T) {
 
 }
 
+
+
 func TestUnmarshallXML(t *testing.T) {
 	var error os.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>`)