tealeg / xlsx

Go library for reading and writing XLSX files.
Other
5.84k stars 816 forks source link

Is there any way to freeze row(s)? #255

Closed pedorich-n closed 7 years ago

pedorich-n commented 7 years ago

In LibreOffice/Excel you can click on the row, go to View -> Freeze Rows and Columns, and they will be acting like static header in table. Is there any way to freeze rows while creating xlsx file?

tealeg commented 7 years ago

@pedorich-n we don't currently have that feature. We welcome pull requests ;-) Generally the easiest way to see what's required is to save an empty XLSX document from your spreadsheet of choice, the save another one that's got just the change you want to implement (freezing in this case), and then unzip both documents and look for the differences in the XML.

pedorich-n commented 7 years ago

@tealeg, I did as you said, and I found this string in differences: <pane xSplit="0" ySplit="2" topLeftCell="A3" activePane="bottomLeft" state="frozen" /> This is freezing first two lines, so I decided to try, and I wrote this code:

    sheet.SheetViews = []xlsx.SheetView{{Pane: &xlsx.Pane{
        XSplit:      0,
        YSplit:      2,
        TopLeftCell: "A3",
        ActivePane:  "bottomLeft",
        State:       "frozen",
    }}}

And it works! "A3" is the first cell after frozen rows, "YSplit: 2," stands, I guess for how many rows will be frozen. XSplit is for the column freezing