ソースを参照

Test that we can deal with arbitrarily named sheet files within the XLSX file.

Geoffrey J. Teale 12 年 前
コミット
d827bc35f6
2 ファイル変更27 行追加1 行削除
  1. 1 1
      lib.go
  2. 26 0
      lib_test.go

+ 1 - 1
lib.go

@@ -522,7 +522,7 @@ func ReadZip(f *zip.ReadCloser) (*File, error) {
 		case "xl/styles.xml":
 			styles = v
 		default:
-			if len(v.Name) > 12 {
+			if len(v.Name) > 14 {
 				if v.Name[0:13] == "xl/worksheets" {
 					worksheets[v.Name[14:len(v.Name)-4]] = v
 				}

+ 26 - 0
lib_test.go

@@ -360,6 +360,32 @@ func TestReadWorkbookRelationsFromZipFile(t *testing.T) {
 	}
 }
 
+
+// We can extract a map of relationship Ids to the worksheet files in
+// which they are contained from the XLSX file, even when the
+// worksheet files have arbitrary, non-numeric names.
+func TestReadWorkbookRelationsFromZipFileWithFunnyNames(t *testing.T) {
+	var xlsxFile *File
+	var error error
+
+	xlsxFile, error = OpenFile("testrels.xlsx")
+	if error != nil {
+		t.Error(error.Error())
+		return
+	}
+	sheetCount := len(xlsxFile.Sheet)
+	if sheetCount != 2 {
+		t.Error("Expected 3 items in xlsxFile.Sheet, but found ", strconv.Itoa(sheetCount))
+	}
+	bob := xlsxFile.Sheet["Bob"]
+	row1 := bob.Rows[0]
+	cell1 := row1.Cells[0]
+	if cell1.String() != "I am Bob" {
+		t.Error("Expected cell1.String() == 'I am Bob', but got '" + cell1.String() + "'")
+	}
+}
+
+
 func TestLettersToNumeric(t *testing.T) {
 	cases := map[string]int{"A": 0, "G": 6, "z": 25, "AA": 26, "Az": 51,
 		"BA": 52, "Bz": 77, "ZA": 26*26 + 0, "ZZ": 26*26 + 25,