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
17.62k stars 1.68k forks source link

Make it possible to set xlsxWorkBookView.WindowWidth and WindowHeight #1934

Closed mbe81 closed 2 days ago

mbe81 commented 3 days ago

When generating an Excel File I would like to control the window size when the Excel sheet is opened for the first time.

I think this is controlled with WorkBookView.WindowWidth and WindowHeight. Currently those fields are filled with defaults in template.go:

const templateWorkbook =

It would be nice if it is possible to override those defaults.

xuri commented 2 days ago

Yep, you can set windows height and width for default workbook view like this:

f := excelize.NewFile()
f.WorkBook.BookViews.WorkBookView[0].WindowHeight = 95790
f.WorkBook.BookViews.WorkBookView[0].WindowWidth = 95790

Note that the unit of measurement for WindowHeight and WindowWidth fields value is twips (One twip is 1⁄1440 inch, or 17.64μm).

mbe81 commented 2 days ago

Oh, thanks! I looked into the documentation and I could not find anything about it. I also was looking to af function to call but this will work. Thanks for your great work!