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

Unable to set row height when using streamWriter #835

Closed
tinlacoo opened this issue May 6, 2021 · 4 comments
Closed

Unable to set row height when using streamWriter #835

tinlacoo opened this issue May 6, 2021 · 4 comments
Labels
duplicate This issue or pull request already exists

Comments

@tinlacoo
Copy link

tinlacoo commented May 6, 2021

Description

Steps to reproduce the issue:

  1. Create file.
  2. Set Row height using function SetRowHeight - e.g: file.SetRowHeight("Sheet1", 1, 30)
  3. Create StreamWriter from file.
  4. Flush StreamWriter using function streamWriter.Flush().
  5. Check row height using function GetRowHeight.

Describe the results you received:
Row height is reset to default.
image

Note: - Result still the same if row height is set via : streamWriter.File.SetRowHeight("Sheet1", 1, 30)
- Set row height after streamWriter.Flush() will do but the file output still keep the default height.
image

Describe the results you expected:
Row height is updated correctly.

Code Sample

file := excelize.NewFile()

	file.SetRowHeight("Sheet1", 1, 30)
	height, _ := file.GetRowHeight("Sheet1", 1)
	fmt.Println("File row height: ", height)

	streamWriter, err := file.NewStreamWriter("Sheet1")
	styleID, _ := file.NewStyle(`{"font":{"color":"#777777"}}`)

	if err := streamWriter.SetRow("A1", []interface{}{excelize.Cell{StyleID: styleID, Value: "Data Sample"}}); err != nil {
		fmt.Println(err)
	}

	heightStream, _ := streamWriter.File.GetRowHeight("Sheet1", 1)
	fmt.Println("streamWriter.File row height after new: ", heightStream)

	for rowID := 2; rowID <= 5; rowID++ {
		row := make([]interface{}, 50)
		for colID := 0; colID < 2; colID++ {
			row[colID] = rand.Intn(640000)
		}
		cell, _ := excelize.CoordinatesToCellName(1, rowID)
		if err := streamWriter.SetRow(cell, row); err != nil {
			fmt.Println(err)
		}
	}

	err = streamWriter.Flush()
	if err != nil {
		fmt.Println(err)
	}

	height, _ = file.GetRowHeight("Sheet1", 1)
	fmt.Println("File row height after flush: ", height)

	name := uuid.NewV1().String()
	if err := file.SaveAs("Book1.xlsx"); err != nil {
                 fmt.Println(err)
        }

Output of go version:

go 1.15

Excelize version or commit ID:

github.com/360EntSecGroup-Skylar/excelize/v2 v2.4.0

Environment details (OS, Microsoft Excel™ version, physical, etc.):
Windows 10 Pro, Office professional plus 2016

@xuri
Copy link
Member

xuri commented May 6, 2021

This issue duplicate with #725, you can't use common API and stream API mixed, also reference #777 and #826.

@xuri xuri closed this as completed May 6, 2021
@xuri xuri added the duplicate This issue or pull request already exists label May 6, 2021
@tinlacoo
Copy link
Author

tinlacoo commented May 6, 2021

Hi @xuri,

So can you provide any solutions for me to set height is this case.
Because the height is set using common API before create stream as mentioned in the above steps.

@xuri
Copy link
Member

xuri commented May 6, 2021

You can't use streaming API in this case, use the common API (such as SetSheetRow or SetCellValue ) to set the worksheet cell value and column width.

@tinlacoo
Copy link
Author

tinlacoo commented May 6, 2021

Thank @xuri,
My file have complex functions (merge cells, panel..) with big data (always 20000 rows ) so I must use stream for the best output performance.
image
Currently, I'm using excelize v2.3.1 without problem with SetRowHeight function but have a little performance issue with merge cells.
And you guys have done amazing job for improved the performance so much in v2.4.0 . So I tried to apply this but got problem with the Height :(.
image
Thanks anyway

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants