Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wong in read in sheets #89

Closed
snailQH opened this issue Jul 28, 2017 · 4 comments
Closed

wong in read in sheets #89

snailQH opened this issue Jul 28, 2017 · 4 comments

Comments

@snailQH
Copy link

snailQH commented Jul 28, 2017

Hello,I am using your lib in read in some xlsx files. But I fount that "excelize" cannot read in the content for every xlsx files.
I attached an example file which I tried out by "tealeg/xlsx".
Can you help me finding out the problem(s)? There are 3 sheets in the example xlsx file,But only two can be read out by "excelize".
errorin360EntSecGroup-Skylar.xlsx

@xuri
Copy link
Member

xuri commented Jul 28, 2017

I have tested with your attached file with following code and it works well:

package main

import (
	"fmt"
	"os"
	"strconv"

	"github.com/xuri/excelize"
)

func main() {
	xlsx, err := excelize.OpenFile("./errorin360EntSecGroup-Skylar.xlsx")
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	// Get sheet index.
	index := xlsx.GetSheetIndex("cannot")
	// Get all the rows in a sheet.
	rows := xlsx.GetRows("sheet" + strconv.Itoa(index))
	for _, row := range rows {
		for _, colCell := range row {
			fmt.Print(colCell, "\t")
		}
		fmt.Println()
	}
}

@snailQH
Copy link
Author

snailQH commented Jul 28, 2017

Thanks. It works by your code.
I wrote the following code. And it didn't work in some unsure case. Did I use it in a wrong way?


	sheets := xlsx.GetSheetMap()
	for i := range sheets {
		fmt.Println(i, sheets[i])
		rows := xlsx.GetRows(sheets[i])
		for _, row := range rows {
			for _, colCell := range row {
				fmt.Print(colCell, "\t")
			}
			fmt.Println()
		}
	}

@xuri
Copy link
Member

xuri commented Jul 28, 2017

Use rows := xlsx.GetRows(fmt.Sprintf("Sheet%d", i)) instead of rows := xlsx.GetRows(sheets[i]), relate issue #25, #43, #47 and #51.

@snailQH
Copy link
Author

snailQH commented Jul 28, 2017

Thanks @xuri . It works well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants