Ver código fonte

Baseline functionality working with minimal testing - lets call this 0.01

Geoffrey J. Teale 14 anos atrás
pai
commit
44799e921d
3 arquivos alterados com 20 adições e 34 exclusões
  1. 15 1
      lib.go
  2. 5 0
      lib_test.go
  3. 0 33
      workbook_test.go

+ 15 - 1
lib.go

@@ -4,6 +4,7 @@ import (
 	"archive/zip"
 	"io"
 	"os"
+	"strconv"
 	"xml"
 )
 
@@ -26,6 +27,15 @@ type Cell struct {
 	data string
 }
 
+// CellInterface defines the public API of the Cell.
+type CellInterface interface {
+	String() string
+}
+
+func (c *Cell) String() string {
+	return c.data
+}
+
 // Row is a high level structure indended to provide user access to a
 // row within a xlsx.Sheet.  An xlsx.Row contains a slice of xlsx.Cell.
 type Row struct {
@@ -58,7 +68,11 @@ func readRowsFromSheet(worksheet *XLSXWorksheet, reftable []string) []*Row {
 		row.Cells = make([]*Cell, len(rawrow.C))
 		for j, rawcell := range rawrow.C {
 			cell := new(Cell)
-			cell.data = rawcell.V.Data
+			ref, error := strconv.Atoi(rawcell.V.Data)
+			if error != nil {
+				panic("Invalid reference in Excel Cell (not found in sharedStrings.xml")
+			}
+			cell.data = reftable[ref]
 			row.Cells[j] = cell
 		}
 		rows[i] = row

+ 5 - 0
lib_test.go

@@ -57,6 +57,11 @@ func TestCreateSheet(t *testing.T) {
 		t.Error("Expected len(row.Cells) == 2")
 		return
 	}
+	cell := row.Cells[0]
+	cellstring := cell.String()
+	if cellstring != "Foo" {
+		t.Error("Expected cell.String() == 'Foo', got ", cellstring)
+	}
 }
 
 // Test that we can correctly extract a reference table from the

+ 0 - 33
workbook_test.go

@@ -82,36 +82,3 @@ func TestUnmarshallWorkbookXML(t *testing.T) {
 	}
 }
 
-
-// // Test we can correctly create an xlsx.XLSXWorksheet from a reference
-// // in an xlsx.XLSXSheet using getWorksheetFromSheet()
-// func TestGetWorksheetFromSheet(t *testing.T) {
-
-// 	var xlsxFile *File
-// 	var error os.Error
-// 	xlsxFile, error = OpenFile("testfile.xlsx")
-// 	if error != nil {
-// 		t.Error(error.String())
-// 		return
-// 	}
-// 	var workbook *XLSXWorkbook
-// 	workbook = new(XLSXWorkbook)
-// 	error = xml.Unmarshal(buf, workbook)
-// 	if error != nil {
-// 		t.Error(error.String())
-// 		return
-// 	}
-// 	if len(workbook.Sheets.Sheet) == 0 {
-// 		t.Error("Expected len(workbook.Sheets.Sheet) == 0")
-// 	}
-// 	sheet := workbook.Sheets.Sheet[0]
-// 	worksheet, error := getWorksheetFromSheet(sheet, file)
-// 	if error != nil {
-// 		t.Error(error.String())
-// 		return
-// 	}
-// 	if worksheet == nil {
-// 		t.Error("getWorksheetFromSheet return nil worksheet without reporting an error")
-// 		return
-// 	}
-// }