1

I've searched the API, Google, StackOverflow, etc. trying to find an answer to the following questions, but thus far, my quest has been disappointing. Is anyone out there able to help me out?

1) I'm attempting to use the set_page_view() option to default the worksheet to the "Page Break Preview". Unfortunately the CPAN page does not give me the valid parameters for this function. I've attempted using set_page_view('Page Break Preview'), but that gives me the "Page Layout" view instead.

2) In my script, I reference the set_h_pagebreaks() and set_v_pagebreaks to dynamically place the page-breaks as I write the excel sheet. This works wonderfully, however the worksheets will sometimes create default page-breaks as well. Is there any way to remove the default page breaks using this module?

Thanks for any help that you can provide!! I can provide some of my code-set if need be.

etspaceman
  • 520
  • 5
  • 9
  • So set_page_view literally means default to "Page Layout"? Alright, that makes sense. Thanks! Any thoughts on the pagebreaks? – etspaceman Mar 21 '13 at 21:49
  • Take a look at https://github.com/jmcnamara/excel-writer-xlsx/blob/master/lib/Excel/Writer/XLSX/Worksheet.pm#L6174. It has a comment saying *# TODO. Add pageBreakPreview mode when requested*. Apparently, this has not been implemented yet. In the method `set_page_view` itself it is possible to pass a parameter which is not being validated. You could fork the project and patch it yourself. – simbabque Mar 21 '13 at 21:49
  • Yes, at the moment it means "default to 'Page Layout'" I believe. But as I said, it's prepared. You could add that yourself. I'm sure JMCNAMARA is glad about any good help he can get. – simbabque Mar 21 '13 at 21:51

2 Answers2

2

In relation to your questions:

  1. Page Break Preview isn't currently supported by Excel::Writer::XLSX.

  2. The Excel::Writer::XLSX module doesn't do anything to set default page breaks. These are probably set by Excel itself. If they are then Excel::Writer::XLSX doesn't have any facility to remove them.

jmcnamara
  • 38,196
  • 6
  • 90
  • 108
  • Sad day. Alrighty, thanks for the help! I can live with removing the page breaks when they occur. I'll use simbabque's suggestion and crack open the code to see if I can add the pageBreakPreview mode. :) – etspaceman Mar 21 '13 at 21:57
0

About your question : "Is there any way to remove the default page breaks using this module?"

I think I have the beggining of a solution for you ;)

(even if it was 5 years ago my response could help others so...)

I struggled with this too (had a vertical and horizontal automatic page brak, arg, so annoying!) but I've come to realize that like the office website say : "Microsoft Excel inserts automatic page breaks based on the paper size, margin settings, scale options, and the positions of any manual page breaks that you insert." (https://support.office.com/en-us/article/insert-move-or-delete-page-breaks-in-a-worksheet-ad3dc726-beec-4a4c-861f-ed640612bdc2?omkt=en-001&ui=en-US&rs=en-001&ad=US)

So, like this text say, your automatic page breaks depend on several factors. What is your scale for printing by example? what is your paper size? And so on...

Personnally, my problem was that I had a scale of 100% for a very wide and long excel document. So I just wrote a function that calculate the ideal scale to avoid an automatic vertical page break and my automatic horizontal page breaks disappeared.

Hope it's useful ^^


EDIT : Here's an example of code

#We put the horizontal page breaks at line 20, 40 and 60
worksheet.set_h_pagebreaks([20,40,60])
#We calculate the ideal scale according to your criterias
ideal_scale=pre_determined_number/width_of_all_columns
#We put a scale and then, Excel won't put some automatic breakline when we'll 
#finish to write the excel file
worksheet.set_print_scale(ideal_scale)