Git Product home page Git Product logo

Comments (6)

bondliu2020 avatar bondliu2020 commented on May 27, 2024 1

@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.

bondliu2020 avatar bondliu2020 commented on May 27, 2024

I tested v2 and it was normal. V3 is error.
wb.AppendSheet(*sheet, sheetName)

from xlsx.

tealeg avatar tealeg commented on May 27, 2024

@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.

bondliu2020 avatar bondliu2020 commented on May 27, 2024

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.

tealeg avatar tealeg commented on May 27, 2024

@bondliu2020 - thank you, I'll try and find time to look at this soon.

from xlsx.

tealeg avatar tealeg commented on May 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.