qax-os / excelize

Go language library for reading and writing Microsoft Excel™ (XLAM / XLSM / XLSX / XLTM / XLTX) spreadsheets
https://xuri.me/excelize
BSD 3-Clause "New" or "Revised" License
18.28k stars 1.71k forks source link

Add SetColStyle for stream writer #1493

Closed inX-Su closed 1 year ago

inX-Su commented 1 year ago

Description SetColStyle not working

Steps to reproduce the issue:


func test() {
    file := excelize.NewFile()
    writer, _ := file.NewStreamWriter("sheet1")
    row := make([]interface{}, 0)
    row = append(row, 100)
    writer.SetRow("A1", row)
    // $ format
    dollarStyle, _ := file.NewStyle(&excelize.Style{
        NumFmt: 177,
    })
    file.SetColStyle("sheet1", "A", dollarStyle)

    file.SaveAs("a.xlsx")
}
xuri commented 1 year ago

Thanks for your issue. The SetColStyle function is not a streaming API, so it won't work in stream mode, we need to implement it for stream writer, and contribution are welcome.

inX-Su commented 1 year ago

I find the SetColWidth function supported for streaming API, however, it also doesn't work.


func main() {
    file := excelize.NewFile()

    writer, _ := file.NewStreamWriter("Sheet1")
    row := make([]interface{}, 0)
    row = append(row, 101)
    row = append(row, 123)
    writer.SetRow("A1", row)

    writer.SetColWidth(2, 3, 20)

    file.SaveAs("a.xlsx")
}
xuri commented 1 year ago

As the documentation notice: "you must call the SetColWidth function before the SetRow function." This was duplicate with issue #1294, I closed this merged into #1294.