如何使用XLSXWRITER默认显示分页。

huangapple go评论74阅读模式
英文:

How to display Break page by default with XLSXWRITER

问题

.break page of configuration the added I .xlsxwriter in default by view break page display to possible it is it if know to want I .(python) xlsxwriter in view break page the display to possible it is it if know to want I .error got I but sheet.set_page_break_view() with tried I .

英文:

I added the configuration of break page .I want to know if is it possible to display page break view by default in xlsxwriter (python)?

I tried with sheet.set_page_break_view() but I got error .

答案1

得分: 2

已经发布了Xlsxwriter 3.1.2,于2023年5月29日,因此不再需要对代码进行修改以启用pageBreakPreview,请参考@jmcnamara的回答

在版本3.1.1的'xlswriter worksheet code'中,有关设置页面视图的代码worksheet.set_page_view()仍然只允许启用一个选项。

def set_page_view(self):
    """
    Set the page view mode.
    Args:
        None.
    Returns:
        Nothing.
    """
    self.page_view = 1

而且唯一的选项是pageLayout

# 如果需要,设置页面视图/布局模式。
if self.page_view:
    attributes.append(("view", "pageLayout"))

如果你愿意编辑xlsxwriter工作表文件,你可以轻松地将该选项更改为:

if self.page_view:
    attributes.append(("view", "pageBreakPreview"))

这样,使用worksheet.set_page_view()将会将视图设置为pageBreakPreview,而不是pageLayout视图。

或者,你也可以编辑以便选择任何一个(或者全部三个,包括'normal')。

如果我漏掉了什么内容,我相信@jmcnamara会提供更新的细节。

英文:

EDIT<br>
Given that Xlsxwriter 3.1.2 has been released on May 29th 2023 it would no longer be necessary to make code modification to enable pageBreakPreview per @jmcnamara answer in this post.<br>
----------------------------------------------------------------------------------------------<br>
<br>
There has been some talk of adding this in but looking at the 'xlswriter worksheet code' in version 3.1.1 worksheet.set_page_view() still only allows for enabling one option

def set_page_view(self):
    &quot;&quot;&quot;
    Set the page view mode.
    Args:
        None.
    Returns:
        Nothing.
    &quot;&quot;&quot;
    self.page_view = 1

and that one option is pageLayout

# Set the page view/layout mode if required.
if self.page_view:
    attributes.append((&quot;view&quot;, &quot;pageLayout&quot;))

If you are happy to edit the xlsxwriter worksheet file you can easily change that one option to

if self.page_view:
    attributes.append((&quot;view&quot;, &quot;pageBreakPreview&quot;))

so that using

worksheet.set_page_view()

will then set the view to pageBreakPreview rather than pageLayout view.

Or you can edit so either (or all three including 'normal') can be selected.

I'm sure that @jmcnamara will provide any updated details if I've missed something.

答案2

得分: 2

I've added this as a feature to XlsxWriter v3.1.2 via the worksheet.set_pagebreak_view() method:

import xlsxwriter

workbook = xlsxwriter.Workbook("test.xlsx")
worksheet = workbook.add_worksheet()

worksheet.write("A1", "Hello")
worksheet.write("Z100", "Hello")

worksheet.set_h_pagebreaks([10, 20, 30, 40])

worksheet.set_pagebreak_view()

workbook.close()

Output:

如何使用XLSXWRITER默认显示分页。

英文:

I've added this as a feature to XlsxWriter v3.1.2 via the worksheet.set_pagebreak_view() method:

import xlsxwriter

workbook = xlsxwriter.Workbook(&quot;test.xlsx&quot;)
worksheet = workbook.add_worksheet()

worksheet.write(&quot;A1&quot;, &quot;Hello&quot;)
worksheet.write(&quot;Z100&quot;, &quot;Hello&quot;)

worksheet.set_h_pagebreaks([10, 20, 30, 40])

worksheet.set_pagebreak_view()

workbook.close()

Output:

如何使用XLSXWRITER默认显示分页。

huangapple
  • 本文由 发表于 2023年5月28日 03:08:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/76348589.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定