Skip to content

Commit

Permalink
This closes qax-os#1732, saving workbook with sorted internal part path
Browse files Browse the repository at this point in the history
  • Loading branch information
user65536 committed Nov 30, 2023
1 parent 866e7fd commit 972917f
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"io"
"os"
"path/filepath"
"sort"
"strings"
"sync"
)
Expand Down Expand Up @@ -200,31 +201,40 @@ func (f *File) writeToZip(zw *zip.Writer) error {
return err
}
}
var err error
var (
err error
files, tempFiles []string
)
f.Pkg.Range(func(path, content interface{}) bool {
if err != nil {
return false
}
if _, ok := f.streams[path.(string)]; ok {
return true
}
files = append(files, path.(string))
return true
})
sort.Strings(files)
for _, path := range files {
var fi io.Writer
if fi, err = zw.Create(path.(string)); err != nil {
return false
if fi, err = zw.Create(path); err != nil {
break
}
content, _ := f.Pkg.Load(path)
_, err = fi.Write(content.([]byte))
return true
})
}
f.tempFiles.Range(func(path, content interface{}) bool {
if _, ok := f.Pkg.Load(path); ok {
return true
}
var fi io.Writer
if fi, err = zw.Create(path.(string)); err != nil {
return false
}
_, err = fi.Write(f.readBytes(path.(string)))
tempFiles = append(tempFiles, path.(string))
return true
})
sort.Strings(tempFiles)
for _, path := range tempFiles {
var fi io.Writer
if fi, err = zw.Create(path); err != nil {
break
}
_, err = fi.Write(f.readBytes(path))
}
return err
}

0 comments on commit 972917f

Please sign in to comment.