Closed topialla closed 5 months ago
This issue is stale because it has been open 365 days with no activity. Remove stale label or comment or this will be closed in 7 days.
This issue was closed because it has been stalled for 7 days with no activity.
Is your feature request related to a problem? Please describe. I would love to set the print range of a sheet programmatically, as this has often to be set manually.
Describe the solution you'd like Add a function
setPrintRange
similar tocreateNamedRegion()
. This will give a lot of value also topageSetup()
.Setting it to "none" would remove the print area. The function should also detect a set print area, so another range can be added, and a switch to either add to or replace an existing print area would likely also be required (not for me, but for the general usage, I guess).
-->I described a possible solution to the end of this post.
Describe alternatives you've considered None really, except for setting this manually.
Additional context I found out, that setting a print range creates a named range in
workbook.xml
called"_xlnm.Print_Area"
So I tried to create a respective Area, (which works partially) NB: the
pageSetup
was done, since I was unsure, if this initialises something to help with printing (it seems not to).I wrote "partially" as the generic range name for the print range is found by Excel 2016, I only have a german version available, sorry, for that.
I then went on further, noting that saving a file in excel changes several things to the xml etc, that are not initially set by
saveWorkbook
, sosaveWorkbook
I noted the following changes invoked by Excel 2016.
[Content_Types].xml
testprintrange/[Content_Types].xml
is ameliorated withworkbook.xml
testprintrange/xl/workbook.xml
already containedbut is ameliorated by setting the print range manually with
sheet1.xml
testprintrange/xl/worksheets/sheet1.xml
is also changed slightly:original file
after setting the print range
So a reference seems to be added to the page setup.
Solution
Upon further playing around, I found out, that adding
localSheetId="0"
to the<definedNames>
inworkbook.xml
is sufficient to make it work. (see above my remarks regardingworkbook.xml
).So I would propose a function that calls
createNamedRegion()
and sets the name to"_xlnm.Print_Area"
, but alsolocalSheetId="0"
(the number is the sheet index seems to be the value ofsheetId
–1