qball has asked for the wisdom of the Perl Monks concerning the following question:

Hi All, When I run the following sub routine it creates a word doc with 1 column spanning over 30 pages in a word doc. My goal is to write multiple columns on one page single spaced in order to cut down the numbers of pages being created.
sub getSND(){ $sql = <<END_SQL; select distinct a.send_id from perbill_doc_data a, perbill_types b where a.send_id <> b.type_name and trans_date between '010501' and '010530' END_SQL $query = &execsql($sql); if(!$print_only){ $~ = PB_TOP_SNDIDONLY; write; while (@data = $query->fetchrow) { $~ = PB_BODY_SNDIDONLY; write; } }else{ open(PB_BODY_SNDIDONLY, "> tmp/SND.DOC") or die "Can't $!\n"; #Lock File flock(PB_BODY_SNDIDONLY, 2); $~ = PB_TOP_SNDIDONLY; write PB_TOP_SNDIDONLY; $~ = PB_BODY_SNDIDONLY; write PB_BODY_SNDIDONLY while( @data = $query->fetchrow ); #Unlock file flock(PB_BODY_SNDIDONLY, 8); close (PB_BODY_SNDIDONLY); } }
Thank you in advance for you responses.

qball~"I have node idea?!"

Replies are listed 'Best First'.
Re: Column distribution
by bikeNomad (Priest) on Jun 11, 2001 at 23:40 UTC
    You don't say how you're generating a Word document from the text output from your Perl program. If, however, you're just making a text document and then reading it into Word, you're going to have some problems using Word's multicolumnar mode.

    Although you could probably use formats to make a double-column output in a text file, if you read it into Word it wouldn't look very good unless it was in a monospaced font. And the pagination would not flow properly, since Word wouldn't know that it was supposed to be multiple columns.

    A better solution may be to make a single-column text file, and read it into a Word template that is set up to be multiple columns.

Re: Column distribution
by VSarkiss (Monsignor) on Jun 11, 2001 at 23:34 UTC
    Your use of PB_BODY_SNDIDONLY doesn't make sense to me. You're using it as at least two different things:
    • a format name: $~ = PB_BODY_SNDIDONLY
    • a filehandle: open(PB_BODY_SNDIDONLY
    Can you include a snippet showing the format you're using?? Something like: format PB_BODY_SNDIDONLY = ... Also, you should be aware that once a format is associated with a filehandle, it keeps the association; you don't have to set it repeatedly, such as in your first while.

    Unfortunately your code sample doesn't have the right details to answer your question....

      I'm using PB_BODY_SNDIDONLY as both a format and a filehandle.

      qball~"I have node idea?!"
        Well, I already figured out that much....

        It sounds like you're writing a text file and opening it in MS Word, but the result isn't what you want. Is that correct? The problem is your description doesn't make it clear what your output file looks like, how you feed it to Word, how Word formats the result, and why it isn't what you're looking for. There are many possible problems and solutions within the above scenario:

        Do you just need to binmode the output file for Word's benefit??

        Do you need to wrap lines in your output? You can use a double-tilde ~~ in your format to have Perl output as many lines as necessary to write out the contents of the variable. Something like this

        format PB_BODY_SNDIDONLY = ~~ ^<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $var .
        will output the full contents of $var, preceded by three blanks, in as many lines as necessary. The perlform doc has all the details.

        Do you need control of Word character and paragraph placement? If you're running Perl on Win32, you can use the Win32::OLE modules to do that.

        Sorry if this is all vague, but so is your question. ;-)