[GH-ISSUE #472] Add support to set window size #368

Closed
opened 2026-05-05 12:12:46 -06:00 by gitea-mirror · 7 comments
Owner

Originally created by @tomas789 on GitHub (Feb 13, 2025).
Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/472

Originally assigned to: @jmcnamara on GitHub.

In Python version, there is a function Workbook.set_size to set window size (link). It sets windowWidth and windowHeight of the workbookView element (as implemented here).

There does not seem to be an support for this feature in the libxlsxwriter. The corresponding values in _write_workbook_view are hard-coded.

/*
 * Write the <workbookView> element.
 */
STATIC void
_write_workbook_view(lxw_workbook *self)
{
    struct xml_attribute_list attributes;
    struct xml_attribute *attribute;

    LXW_INIT_ATTRIBUTES();
    LXW_PUSH_ATTRIBUTES_STR("xWindow", "240");
    LXW_PUSH_ATTRIBUTES_STR("yWindow", "15");
    LXW_PUSH_ATTRIBUTES_STR("windowWidth", "16095");
    LXW_PUSH_ATTRIBUTES_STR("windowHeight", "9660");

    if (self->first_sheet)
        LXW_PUSH_ATTRIBUTES_INT("firstSheet", self->first_sheet);

    if (self->active_sheet)
        LXW_PUSH_ATTRIBUTES_INT("activeTab", self->active_sheet);

    lxw_xml_empty_tag(self->file, "workbookView", &attributes);

    LXW_FREE_ATTRIBUTES();
}

I'd like to kindly ask for this feature to be implemented in this library too. I'm currently not able to contribute the PR myself.

Originally created by @tomas789 on GitHub (Feb 13, 2025). Original GitHub issue: https://github.com/jmcnamara/libxlsxwriter/issues/472 Originally assigned to: @jmcnamara on GitHub. In Python version, there is a function `Workbook.set_size` to set window size ([link](https://xlsxwriter.readthedocs.io/workbook.html#workbook-set-size)). It sets `windowWidth` and `windowHeight` of the `workbookView` element ([as implemented here](https://github.com/jmcnamara/XlsxWriter/blob/5636b427e404438a4428e24448c5751a9dfdf16c/xlsxwriter/workbook.py#L1705)). There does not seem to be an support for this feature in the libxlsxwriter. The corresponding values in `_write_workbook_view` are hard-coded. ```cpp /* * Write the <workbookView> element. */ STATIC void _write_workbook_view(lxw_workbook *self) { struct xml_attribute_list attributes; struct xml_attribute *attribute; LXW_INIT_ATTRIBUTES(); LXW_PUSH_ATTRIBUTES_STR("xWindow", "240"); LXW_PUSH_ATTRIBUTES_STR("yWindow", "15"); LXW_PUSH_ATTRIBUTES_STR("windowWidth", "16095"); LXW_PUSH_ATTRIBUTES_STR("windowHeight", "9660"); if (self->first_sheet) LXW_PUSH_ATTRIBUTES_INT("firstSheet", self->first_sheet); if (self->active_sheet) LXW_PUSH_ATTRIBUTES_INT("activeTab", self->active_sheet); lxw_xml_empty_tag(self->file, "workbookView", &attributes); LXW_FREE_ATTRIBUTES(); } ``` I'd like to kindly ask for this feature to be implemented in this library too. I'm currently not able to contribute the PR myself.
gitea-mirror 2026-05-05 12:12:46 -06:00
Author
Owner

@jmcnamara commented on GitHub (Feb 13, 2025):

I can add that.

Out of interest, what is your use case for this?

<!-- gh-comment-id:2657583815 --> @jmcnamara commented on GitHub (Feb 13, 2025): I can add that. Out of interest, what is your use case for this?
Author
Owner

@tomas789 commented on GitHub (Feb 14, 2025):

I write summary report for my optimization system into excel files. That means I very often open new Excel files as opposed to working with one file. Probably like 50 files a day. And first thing I do with each of them is to resize it. And it quickly gets boring :)

<!-- gh-comment-id:2658684643 --> @tomas789 commented on GitHub (Feb 14, 2025): I write summary report for my optimization system into excel files. That means I very often open new Excel files as opposed to working with one file. Probably like 50 files a day. And first thing I do with each of them is to resize it. And it quickly gets boring :)
Author
Owner

@jmcnamara commented on GitHub (Feb 14, 2025):

And first thing I do with each of them is to resize it.

Is that on macOS or some other OS?

<!-- gh-comment-id:2658813450 --> @jmcnamara commented on GitHub (Feb 14, 2025): > And first thing I do with each of them is to resize it. Is that on macOS or some other OS?
Author
Owner

@tomas789 commented on GitHub (Feb 14, 2025):

Yes. Mac.

<!-- gh-comment-id:2658867536 --> @tomas789 commented on GitHub (Feb 14, 2025): Yes. Mac.
Author
Owner

@jmcnamara commented on GitHub (Feb 14, 2025):

I've pushed a fix for this to main. Please test it if you get a chance.

The interface is:

    workbook_set_size(workbook, 2000, 950);

The docs are:

/**
 * @brief Set the size of a workbook window.
 *
 * @param workbook Pointer to a lxw_workbook instance.
 * @param width    Width of the window in pixels.
 * @param height   Height of the window in pixels.
 *
 * Set the size of a workbook window. This is generally only useful on macOS
 * since Microsoft Windows uses the window size from the last time an Excel file
 * was opened/saved. The default size is 1073 x 644 pixels.
 *
 * The resulting pixel sizes may not exactly match the target screen and
 * resolution since it is based on the original Excel for Windows sizes. Some
 * trial and error may be required to get an exact size.
 */
<!-- gh-comment-id:2659031871 --> @jmcnamara commented on GitHub (Feb 14, 2025): I've pushed a fix for this to main. Please test it if you get a chance. The interface is: ```C workbook_set_size(workbook, 2000, 950); ``` The docs are: ```C /** * @brief Set the size of a workbook window. * * @param workbook Pointer to a lxw_workbook instance. * @param width Width of the window in pixels. * @param height Height of the window in pixels. * * Set the size of a workbook window. This is generally only useful on macOS * since Microsoft Windows uses the window size from the last time an Excel file * was opened/saved. The default size is 1073 x 644 pixels. * * The resulting pixel sizes may not exactly match the target screen and * resolution since it is based on the original Excel for Windows sizes. Some * trial and error may be required to get an exact size. */ ```
Author
Owner

@jmcnamara commented on GitHub (Feb 19, 2025):

@tomas789 Did you try this?

<!-- gh-comment-id:2667749011 --> @jmcnamara commented on GitHub (Feb 19, 2025): @tomas789 Did you try this?
Author
Owner

@jmcnamara commented on GitHub (Feb 26, 2025):

This change is now upstream as part of release v1.2.1. Thanks for the input.

<!-- gh-comment-id:2686126617 --> @jmcnamara commented on GitHub (Feb 26, 2025): This change is now upstream as part of release v1.2.1. Thanks for the input.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/libxlsxwriter#368
No description provided.