summaryrefslogtreecommitdiff
path: root/excelize.go
diff options
context:
space:
mode:
Diffstat (limited to 'excelize.go')
-rw-r--r--excelize.go36
1 files changed, 24 insertions, 12 deletions
diff --git a/excelize.go b/excelize.go
index 256d427..f4c7a25 100644
--- a/excelize.go
+++ b/excelize.go
@@ -181,8 +181,10 @@ func OpenReader(r io.Reader, opts ...Options) (*File, error) {
return f, err
}
f.sheetMap = f.getSheetMap()
- f.Styles, err = f.stylesReader()
- f.Theme = f.themeReader()
+ if f.Styles, err = f.stylesReader(); err != nil {
+ return f, err
+ }
+ f.Theme, err = f.themeReader()
return f, err
}
@@ -335,7 +337,7 @@ func checkSheetR0(ws *xlsxWorksheet, sheetData *xlsxSheetData, r0 *xlsxRow) {
// setRels provides a function to set relationships by given relationship ID,
// XML path, relationship type, target and target mode.
func (f *File) setRels(rID, relPath, relType, target, targetMode string) int {
- rels := f.relsReader(relPath)
+ rels, _ := f.relsReader(relPath)
if rels == nil || rID == "" {
return f.addRels(relPath, relType, target, targetMode)
}
@@ -360,7 +362,7 @@ func (f *File) addRels(relPath, relType, target, targetMode string) int {
uniqPart := map[string]string{
SourceRelationshipSharedStrings: "/xl/sharedStrings.xml",
}
- rels := f.relsReader(relPath)
+ rels, _ := f.relsReader(relPath)
if rels == nil {
rels = &xlsxRelationships{}
}
@@ -418,7 +420,10 @@ func (f *File) addRels(relPath, relType, target, targetMode string) int {
// </c>
// </row>
func (f *File) UpdateLinkedValue() error {
- wb := f.workbookReader()
+ wb, err := f.workbookReader()
+ if err != nil {
+ return err
+ }
// recalculate formulas
wb.CalcPr = nil
for _, name := range f.GetSheetList() {
@@ -465,12 +470,15 @@ func (f *File) AddVBAProject(bin string) error {
if path.Ext(bin) != ".bin" {
return ErrAddVBAProject
}
- wb := f.relsReader(f.getWorkbookRelsPath())
- wb.Lock()
- defer wb.Unlock()
+ rels, err := f.relsReader(f.getWorkbookRelsPath())
+ if err != nil {
+ return err
+ }
+ rels.Lock()
+ defer rels.Unlock()
var rID int
var ok bool
- for _, rel := range wb.Relationships {
+ for _, rel := range rels.Relationships {
if rel.Target == "vbaProject.bin" && rel.Type == SourceRelationshipVBAProject {
ok = true
continue
@@ -482,7 +490,7 @@ func (f *File) AddVBAProject(bin string) error {
}
rID++
if !ok {
- wb.Relationships = append(wb.Relationships, xlsxRelationship{
+ rels.Relationships = append(rels.Relationships, xlsxRelationship{
ID: "rId" + strconv.Itoa(rID),
Target: "vbaProject.bin",
Type: SourceRelationshipVBAProject,
@@ -495,9 +503,12 @@ func (f *File) AddVBAProject(bin string) error {
// setContentTypePartProjectExtensions provides a function to set the content
// type for relationship parts and the main document part.
-func (f *File) setContentTypePartProjectExtensions(contentType string) {
+func (f *File) setContentTypePartProjectExtensions(contentType string) error {
var ok bool
- content := f.contentTypesReader()
+ content, err := f.contentTypesReader()
+ if err != nil {
+ return err
+ }
content.Lock()
defer content.Unlock()
for _, v := range content.Defaults {
@@ -516,4 +527,5 @@ func (f *File) setContentTypePartProjectExtensions(contentType string) {
ContentType: ContentTypeVBA,
})
}
+ return err
}