Bladeren bron

Error when opening file without workbook_rels.

Geoffrey J. Teale 10 jaren geleden
bovenliggende
commit
de62f3bac3
3 gewijzigde bestanden met toevoegingen van 13 en 0 verwijderingen
  1. 6 0
      lib.go
  2. 7 0
      lib_test.go
  3. BIN
      testdocs/badfile_noWorkbookRels.xlsx

+ 6 - 0
lib.go

@@ -845,10 +845,16 @@ func ReadZipReader(r *zip.Reader) (*File, error) {
 			}
 		}
 	}
+	if workbookRels == nil {
+		return nil, fmt.Errorf("xl/_rels/workbook.xml.rels not found in input xlsx.")
+	}
 	sheetXMLMap, err = readWorkbookRelationsFromZipFile(workbookRels)
 	if err != nil {
 		return nil, err
 	}
+	// if len(worksheets) == 0 {
+
+	// }
 	file.worksheets = worksheets
 	reftable, err = readSharedStringsFromZipFile(sharedStrings)
 	if err != nil {

+ 7 - 0
lib_test.go

@@ -13,6 +13,13 @@ type LibSuite struct{}
 
 var _ = Suite(&LibSuite{})
 
+// Attempting to open a file without workbook.xml.rels returns an error.
+func (l *LibSuite) TestReadZipReaderWithFileWithNoWorkbookRels(c *C) {
+	_, err := OpenFile("./testdocs/badfile_noWorkbookRels.xlsx")
+	c.Assert(err, NotNil)
+	c.Assert(err.Error(), Equals, "xl/_rels/workbook.xml.rels not found in input xlsx.")
+}
+
 // 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_noWorkbookRels.xlsx