Comments (6)
@bondliu2020 how are you constructing the Sheet that you're passing to AppendSheet? The CellStores got added in V3 IIRC and you might have an issue around those.
Above is all the code.
from xlsx.
I tested v2 and it was normal. V3 is error.
wb.AppendSheet(*sheet, sheetName)
from xlsx.
@bondliu2020 how are you constructing the Sheet that you're passing to AppendSheet? The CellStores got added in V3 IIRC and you might have an issue around those.
from xlsx.
func main() {
var out string
var inPath string
flag.StringVar(&inPath, "d", "tmp", "指定需要合并的工作薄目录")
flag.StringVar(&out, "o", "out.xlsx", "指定合并后文件的命名,格式:out.xlsx")
flag.Parse()
//设置路径,文件夹放在main的同级目录下
PthSep := string(os.PathSeparator)
PthDir := inPath
dir, err := os.ReadDir(PthDir)
if err != nil {
fmt.Printf("open dir failed: %s\n", err.Error())
}
//申明合并后的文件
var newFile *xlsx.File
newFile = xlsx.NewFile()
sCount := 0
var sheetName string
var newErr error
//检索所有文件
for _, fi := range dir {
fmt.Printf("open success: %s\n", PthDir+PthSep+fi.Name())
if newErr != nil {
fmt.Printf(newErr.Error())
}
//循环读取每个文件
xlFile, err := xlsx.OpenFile(PthDir + PthSep + fi.Name())
if err != nil {
fmt.Printf("open failed: %s\n", err)
}
sCount++
for _, sheet := range xlFile.Sheets {
fmt.Printf("Sheet Name: %s\n", sheet.Name)
//
sheetName = "sheet" + strconv.Itoa(sCount)
fmt.Println("marrow", sheet.MaxRow, "合并后sheetName:", sheetName)
_, newErr := newFile.AppendSheet(*sheet, sheetName)
if newErr != nil {
fmt.Printf(newErr.Error())
}
}
}
//写入文件
newErr = newFile.Save(out)
if newErr != nil {
fmt.Printf(newErr.Error())
} else {
fmt.Printf("全部文件合并完成.")
}
}
from xlsx.
@bondliu2020 - thank you, I'll try and find time to look at this soon.
from xlsx.
OK @bondliu2020 - I now know why this is happening. When you append the sheets you give them new sheet names (perfectly correct!), but the backing row store uses the sheet name as part of its key, so it can no longer find the rows by name (even though it has all the data still). I'll try to work up a fix.
from xlsx.
Related Issues (20)
- ValueOnly option truncating break xml HOT 3
- Shit library HOT 1
- Shit library
- Security protection is recommended for functions OpenReaderAt and OpenFile. HOT 1
- The func (f *File) Save(path string) (err error) resource in the file.go file is leaked. HOT 1
- Resource leakage in the lib.go file HOT 2
- Can it support multiple drop lists? HOT 2
- oom err HOT 3
- Read the contents of an Excel file in batches using stream processing
- how to get the number of cells in a row
- RowLimit option truncating xml ignore xmlns prefix
- codecov.io reports needs activation HOT 1
- 不支持 go1.21 版本,麻烦给处理一下,谢谢 HOT 6
- golang 1.21 incompatibility - Suddenly all my sheets are empty -- all projects HOT 8
- how to set cell custom type as yyyy/mm/dd hh:mm:ss HOT 1
- XLSX files produced by this library need recover by Microsoft Excel when open it. HOT 19
- Using WPS to open the generated Excel border defaults to dashed lines. How to remove the dashed border HOT 4
- Fourth time a cell is set it won't be written to if it's not the last cell written to HOT 7
- Why cell.String() method returned datetime string contains double backslash? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xlsx.