开发者

Setting an Excel worksheet's custom page size (not the printable area) from Perl

Long story short, all I'm really attempting to do is print my reports on half sheets. I had Kinko's chop a pack of printer paper in half and my laser printer is perfectly happy to suck them in and print the reports properly, if the paper size of the Excel report is set to exactly 8.5" x 5.64".

That can be done easily in Excel, but it's the one and only adjustme开发者_StackOverflownt, in my project, I wasn't able to automate with Perl using Spreadsheet::WriteExcel. The CPAN documentation states that you can pick from some of the default sizes normally available with Excel, but doesn't provide an option to specify your own paper size.

Even if you establish the custom size you need in Excel beforehand, making it available in future spreadsheets, as one of your selectable paper sizes, there doesn't seem to be an index, using set_paper($index), that would specify that newly established custom size.

Thank you in advance!

    #!/usr/local/gnu/bin/perl --
    use strict;
    use warnings;
    use Spreadsheet::WriteExcel;

    my $repWB = Spreadsheet::WriteExcel->new('../tmp/test.xls');
    my $repWS = $repWB->add_worksheet('AA');

    $repWS->set_paper(1);


Since VBScript can do many of these things natively, maybe you could try embedding the necessary VBScript into your main Perl script using Inline:WSC.

You could determine the needed VBScript by recording an Excel macro of you setting the print size. Then embed that code into your main Perl script.


I am the author of Spreadsheet::writeExcel.

As far as I know there isn't an option in Excel to set a custom paper size. This is usually set in the printer (correct me if I am wrong).

Excel can store printer information along with the workbook data so there may be a workaround.

Can you send me a single sheet workbook with data in cell A1 only and a copy with the custom page set and I'll take a look to see if it is possible.

P.S. The available option B5 (index 13) in landscape mode is fairly close: 8.27" x5.83". Or the undocumented "Organiser L" (index 129) which should be half Letter size: 8.5" x 5.5".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜