Parcourir la source

Fix blank column handling to pass new test case.

Geoffrey J. Teale il y a 12 ans
Parent
commit
1e3dddf3b7
3 fichiers modifiés avec 30 ajouts et 11 suppressions
  1. 1 1
      lib.go
  2. 22 5
      lib_test.go
  3. 7 5
      wpsBlankLine_test.go

+ 1 - 1
lib.go

@@ -345,7 +345,7 @@ func readRowsFromSheet(Worksheet *xlsxWorksheet, file *File) ([]*Row, int, int)
 
 			// Some spreadsheets will omit blank cells
 			// from the data.
-			for x > (insertColIndex + 1) {
+			for x > insertColIndex {
 				// Put an empty Cell into the array
 				row.Cells[insertColIndex-minCol] = new(Cell)
 				insertColIndex++

+ 22 - 5
lib_test.go

@@ -645,7 +645,24 @@ func TestReadRowsFromSheetWithLeadingEmptyRows(t *testing.T) {
 func TestReadRowsFromSheetWithEmptyCells(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="8" uniqueCount="5"><si><t>Bob</t></si><si><t>Alice</t></si><si><t>Sue</t></si><si><t>Yes</t></si><si><t>No</t></si></sst>`)
+<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="8" uniqueCount="5">
+  <si>
+    <t>Bob</t>
+  </si>
+  <si>
+    <t>Alice</t>
+  </si>
+  <si>
+    <t>Sue</t>
+  </si>
+  <si>
+    <t>Yes</t>
+  </si>
+  <si>
+    <t>No</t>
+  </si>
+</sst>
+`)
 	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:C3"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="D3" sqref="D3"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="15"/>
@@ -731,12 +748,12 @@ func TestReadRowsFromSheetWithEmptyCells(t *testing.T) {
 		t.Error("Expected cell1.String() == 'No', got ", cell1.String())
 	}
 	cell2 := row.Cells[1]
-	if cell2.String() != "Yes" {
-		t.Error("Expected cell2.String() == 'Yes', got ", cell2.String())
+	if cell2.String() != "" {
+		t.Error("Expected cell2.String() == '', got ", cell2.String())
 	}
 	cell3 := row.Cells[2]
-	if cell3.String() != "" {
-		t.Error("Expected cell3.String() == 'No', got ", cell3.String())
+	if cell3.String() != "Yes" {
+		t.Error("Expected cell3.String() == 'Yes', got ", cell3.String())
 	}
 
 }

+ 7 - 5
wpsBlankLine_test.go

@@ -32,15 +32,17 @@ func TestWpsBlankLine(t *testing.T) {
 		t.Errorf("[TestWpsBlankLine] expected cell A3 = '%s', but got :'%s'", expected, s)
 		return
 	}
-  
-  s = sheet.Rows[4].Cells[1].String()
+
+	row = sheet.Rows[4]
+	cell = row.Cells[1]
+	s = cell.String()
 	if s != "" {
 		t.Errorf("[TestWpsBlankLine] expected cell B5 = '%s', but got :'%s'", "", s)
 		return
-	}  
-  s = sheet.Rows[4].Cells[2].String()
+	}
+	s = sheet.Rows[4].Cells[2].String()
 	if s != expected {
 		t.Errorf("[TestWpsBlankLine] expected cell C5 = '%s', but got :'%s'", expected, s)
 		return
-	}  
+	}
 }