Golang 1.9 failing with excelize (simple case works under 1.8.3)

1,263 views
Skip to first unread message

G Shields

unread,
Aug 25, 2017, 6:10:40 PM8/25/17
to golang-nuts
Under 1.8.3 the program run:
package main

import (
    "fmt"
    "os"
    "strconv"

    "github.com/Luxurioust/excelize"
)

func checkErr(err error) {
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }

}
func main() {

    xlsx, err := excelize.OpenFile("test.xlsx")
    checkErr(err)
    mysheet := xlsx.GetSheetName(1)
    index := xlsx.GetSheetIndex(mysheet)
    rows := xlsx.GetRows("Sheet" + strconv.Itoa(index))
    for _, row := range rows {
        for _, colCell := range row {
            fmt.Print(colCell, "\t")
        }
        fmt.Println()
    }
}

With results of:
na    Apple    Orange    Pear   
Small    2    3    3   
Normal    5    2    4   
Large    6    7    8
Success: process exited with code 0.

Under 1.9 I get no data and no errors:
Success: process exited with code 0.

peterGo

unread,
Aug 26, 2017, 7:29:13 AM8/26/17
to golang-nuts
In Go, always check for errors. For example,

    mysheet := xlsx.GetSheetName(1)

https://godoc.org/github.com/360EntSecGroup-Skylar/excelize#File.GetSheetName

func (*File) GetSheetName

func (f *File) GetSheetName(index int) string

GetSheetName provides function to get sheet name of XLSX by given worksheet index.
If given sheet index is invalid, will return an empty string.

Peter

peterGo

unread,
Aug 26, 2017, 8:23:43 AM8/26/17
to golang-nuts
I am unable to reproduce your issue:

go1.8.3

na      Apple   Orange  Pear    
Small   2       3       3    
Normal  5       2       4    
Large   6       7       8    

go1.9

na      Apple   Orange  Pear    
Small   2       3       3    
Normal  5       2       4    
Large   6       7       8    

devel +bad6b6f Fri Aug 25 23:29:55 2017 +0000

na      Apple   Orange  Pear    
Small   2       3       3    
Normal  5       2       4    
Large   6       7       8   


To reproduce the issue precisely, provide us with a copy of your input: test.xlsx.

Peter

G Shields

unread,
Aug 28, 2017, 2:55:25 PM8/28/17
to golang-nuts
here is the xlsx data file
FYI this fails on both mac and ubuntu with 1.9
test.xlsx

silviu...@gmail.com

unread,
Aug 29, 2017, 12:00:21 AM8/29/17
to golang-nuts
Interesting... For this portion of code:


The xml decoder returns row and col token types for  1.8.3 but rushes into an EOF for 1.9

If the document gets re-saved with LibreOffice for example, it works, so it may be invalid, but still... maybe some changes in the Xml parsed inner workings ?

Sam Whited

unread,
Aug 29, 2017, 2:22:12 AM8/29/17
to golan...@googlegroups.com
On Mon, Aug 28, 2017, at 22:59, silviu...@gmail.com wrote:
> Interesting... For this portion of code:
>
> https://github.com/360EntSecGroup-Skylar/excelize/blob/master/rows.go#L76-L85
>
> The xml decoder returns row and col token types for 1.8.3 but rushes
> into
> an EOF for 1.9

In Go 1.8 the patch in 02240408a1 was ported to restore error masking
behavior from 1.7 (which is why you get output in 1.8). I don't see that
patch in 1.9.

See also https://golang.org/issue/19333

—Sam

peterGo

unread,
Aug 29, 2017, 2:35:28 AM8/29/17
to golang-nuts
This was commited for Go1.8.1. It was not included in Go1.9.

https://go.googlesource.com/go/+/02240408a1dc47f1cdefd9695d220cf1d2fff264

Peter

G Shields

unread,
Aug 30, 2017, 6:42:19 PM8/30/17
to golang-nuts
Tried the trick with saving under LibreOffice and MS excel, and in both cases the files created are different and both continue to fail.

At this point 1.9 is not stable for me with XML.

Enclosed are some more files (renamed for the application origin, but the same test.xlsx)

Thanks


On Friday, August 25, 2017 at 3:10:40 PM UTC-7, G Shields wrote:
ms.xlsx
libre.xlsx

silviu...@gmail.com

unread,
Aug 30, 2017, 7:36:23 PM8/30/17
to golang-nuts
This library https://github.com/plandem/xlsx that was advertised here a few days ago worked for me with your initial test.xlsx

G Shields

unread,
Aug 31, 2017, 3:58:56 PM8/31/17
to golang-nuts
All,

Thanks for all the suggestions.
I cleaned out everything with: go clean -r -i …
installed go 1.9 and created a file new test file of:

package main

import (
    "fmt"
    "os"


)

func checkErr(err error) {
    if err != nil {
        fmt.Println(err)
        os.Exit(1)
    }
}

func main() {

    xl, err := xlsx.Open("test.xlsx")
    checkErr(err)
    defer xl.Close()

    sheet := xl.Sheet(0)

    for iRow, iMax := 0, sheet.TotalRows(); iRow < iMax; iRow++ {
        row := sheet.Row(iRow)

        for iCol, cell := range row.Cells() {
            fmt.Println(" %q %q ", iCol, cell.Value)
        }

    }
}

And the results were not good I could not get cell values, further when empty cell are encounter with  plandem/xlsx I get a panic when it executes.

Good news with cleaning everything our and install a fresh copy of 1.9 I can generate and read with excelize.

I am disappointed in the compiler upgrade process and lack of error messages during previous attempts.

Lessons learned , delete everything with go clean -r -i …, and rebuild with go install ….

Not a perfect solution, but GOfigure :)

As additional test I opened and saved the xlsx with libreoffice 5.4.0.3 (on osx 10.12.6) and the simple test failed again.
Then I opened and save the file with excel 2016 (widow 10) and excelize reads the file with no errors and correct output(on osx and ubuntu 17.10).
Bottom line sticking with excelize, due to better documentation and functional.

Thanks again!


On Friday, August 25, 2017 at 3:10:40 PM UTC-7, G Shields wrote:
Reply all
Reply to author
Forward
0 new messages