Browse Source

Error when opening a file with no worksheets.

Geoffrey J. Teale 10 years ago
parent
commit
6df8184fc1
3 changed files with 10 additions and 3 deletions
  1. 3 3
      lib.go
  2. 7 0
      lib_test.go
  3. BIN
      testdocs/badfile_noWorksheets.xlsx

+ 3 - 3
lib.go

@@ -852,9 +852,9 @@ func ReadZipReader(r *zip.Reader) (*File, error) {
 	if err != nil {
 		return nil, err
 	}
-	// if len(worksheets) == 0 {
-
-	// }
+	if len(worksheets) == 0 {
+		return nil, fmt.Errorf("Input xlsx contains no worksheets.")
+	}
 	file.worksheets = worksheets
 	reftable, err = readSharedStringsFromZipFile(sharedStrings)
 	if err != nil {

+ 7 - 0
lib_test.go

@@ -20,6 +20,13 @@ func (l *LibSuite) TestReadZipReaderWithFileWithNoWorkbookRels(c *C) {
 	c.Assert(err.Error(), Equals, "xl/_rels/workbook.xml.rels not found in input xlsx.")
 }
 
+// Attempting to open a file with no worksheets returns an error.
+func (l *LibSuite) TestReadZipReaderWithFileWithNoWorksheets(c *C) {
+	_, err := OpenFile("./testdocs/badfile_noWorksheets.xlsx")
+	c.Assert(err, NotNil)
+	c.Assert(err.Error(), Equals, "Input xlsx contains no worksheets.")
+}
+
 // which they are contained from the XLSX file, even when the
 // worksheet files have arbitrary, non-numeric names.
 func (l *LibSuite) TestReadWorkbookRelationsFromZipFileWithFunnyNames(c *C) {

BIN
testdocs/badfile_noWorksheets.xlsx