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

Generating big tables with time cells results with corrupted file #643

Closed
ludmanp opened this issue May 23, 2020 · 2 comments
Closed

Generating big tables with time cells results with corrupted file #643

ludmanp opened this issue May 23, 2020 · 2 comments

Comments

@ludmanp
Copy link

ludmanp commented May 23, 2020

Description

Generating big table with time columns output file is corrupted.

Steps to reproduce the issue:
here is example script
`package main

import (
"flag"
"fmt"
"github.com/360EntSecGroup-Skylar/excelize"
"math/rand"
"reflect"
"strconv"
"time"
)

type NullTime struct {
Time time.Time
Valid bool // Valid is true if Time is not NULL
}

func main() {
r := rand.New(rand.NewSource(99))

excel := excelize.NewFile()

sheetName := "Test sheet"
sheetIndex := excel.GetActiveSheetIndex()
excel.SetSheetName(excel.GetSheetName(sheetIndex), sheetName)

dateStyle, _ := excel.NewStyle(`{"custom_number_format": "yyyy-mm-dd"}`)
floatStyle, _ := excel.NewStyle(`{"number_format": 2}`)

rowsCount := flag.Int("rows", 100, "Number of rows")
flag.Parse()
for row := 1; row <= *rowsCount; row++ {
	for col := 1; col <= 10; col++ {
		val := randate()
		t := reflect.ValueOf(val)
		_ = excel.SetCellValue(sheetName, intToCharIndex(col)+strconv.Itoa(row), t.Interface())
		_ = excel.SetCellStyle(sheetName, intToCharIndex(col)+strconv.Itoa(row), intToCharIndex(col)+strconv.Itoa(row), dateStyle)
	}
	for col := 11; col <= 101; col++ {
		_ = excel.SetCellValue(sheetName, intToCharIndex(col)+strconv.Itoa(row), r.Float64())
		_ = excel.SetCellStyle(sheetName, intToCharIndex(col)+strconv.Itoa(row), intToCharIndex(col)+strconv.Itoa(row), floatStyle)
	}
}
if err := excel.SaveAs("Test.xlsx"); err != nil {
	fmt.Println(err)
}

}

func intToCharIndex(i int) string {
col, _ := excelize.ColumnNumberToName(i+1)
return col
}

func randate() time.Time {
min := time.Date(2010, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
max := time.Date(2020, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
delta := max - min

sec := rand.Int63n(delta) + min
return time.Unix(sec, 0).UTC()

}

`

making some 100 or 1000 rows output file is ok, making 10k rows file is corrupted.

Describe the results you received:

Describe the results you expected:

Output of go version:

go version go1.14.2 darwin/amd64

Excelize version or commit ID:

v2.2.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):

macOS Catalina, MS Excel for Mac 16.37

@xuri xuri added the in progress Working in progress label May 23, 2020
@xuri xuri closed this as completed in a546427 May 24, 2020
@xuri
Copy link
Member

xuri commented May 24, 2020

Thanks for your issue. I have fixed it. Please try to upgrade the library with the master branch code.

@xuri xuri removed the in progress Working in progress label May 24, 2020
@ludmanp
Copy link
Author

ludmanp commented May 24, 2020

Great, thank you for fast reaction.

Jerome1337 pushed a commit to Jerome1337/excelize that referenced this issue Jun 16, 2020
nullfy pushed a commit to nullfy/excelize that referenced this issue Oct 23, 2020
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