I have written a script that will grab information from an access database and insert it in a word doc. I am having a problem with format. I am trying to underline a word on a line that has more words on it. The problem is when it is generating the doc. it shows that it is underline but once the document finishes generating it does away with the underline. So the question is how do I keep it underlined.
The problems occurs here:

set_style($document, $st_doc_12_Underline); text ($document, "Test Number: "); set_style($document, $st_doc_12_Body); text ($document, "@row"); enter ($document);

Here is the Code:
use warnings; use strict; use DBI; use Win32::OLE; use Win32::OLE::Const 'Microsoft.Word'; # wd constants use Win32::OLE::Const 'Microsoft Office'; # mso constants # connecting to the database my $dbh = DBI->connect( "dbi:ODBC:driver=Microsoft Access Driver (*.md +b);dbq=C:TestCasesXP2K.mdb", "", "" ); #selecting the Test Case numbers from the database of XP for the ones +that failed my $stg = $dbh->prepare(q{SELECT NSAXPTestCaseNum FROM TestCasesOutput + WHERE NSAXPTestCaseNum <> 'XP0' AND PassFail = 'FAIL' ORDER BY NSAXP +TestCaseNum}); $stg->execute || die "Could not execute SQL statement ... maybe invalid?"; #selecting the Test Execution from the database of XP for the ones tha +t failed my $sth = $dbh->prepare(q{SELECT TESTEXECUTION FROM TestCasesOutput WH +ERE NSAXPTestCaseNum <> 'XP0' AND PassFail = 'FAIL' ORDER BY NSAXPTes +tCaseNum}); $sth->execute || die "Could not execute SQL statement ... maybe invalid?"; #selecting the Requirement from the database of XP for the ones that f +ailed my $stt = $dbh->prepare(q{SELECT REQUIREMENT FROM TestCasesOutput WHER +E NSAXPTestCaseNum <> 'XP0' AND PassFail = 'FAIL' ORDER BY NSAXPTestC +aseNum}); $stt->execute || die "Could not execute SQL statement ... maybe invalid?"; #selecting the Test Results from the database of XP for the ones that +failed my $stf = $dbh->prepare(q{SELECT TESTRESULT FROM TestCasesOutput WHERE + NSAXPTestCaseNum <> 'XP0' AND PassFail = 'FAIL' ORDER BY NSAXPTestCa +seNum}); $stf->execute || die "Could not execute SQL statement ... maybe invalid?"; #Writing all the info. from the database to a word document my $cur_style = 'a'; my $cur_bookmark = 'a'; #opening a word document or die my $word = CreateObject Win32::OLE 'Word.Application' or die $!; $word->{'Visible'} = 1; my $document = $word->Documents->Add; # selection is the insertion point. my $selection = $word->Selection; # Setting the text style my $st_bold_12_Heading = create_style($document, "Times new Roman", +12, 1, 0, 1); my $st_doc_12_Body = create_style($document, "Times new Roman", 12, 0, + 0, 0); my $st_doc_12_Underline = create_style($document, "Times new Roman", 1 +2, 1, 1, 1); set_style($document, $st_bold_12_Heading); text ($document, "1 INTRODUCTION"); enter ($document); enter ($document); set_style($document, $st_bold_12_Heading); text ($document, "2 SCOPE"); enter ($document); set_style($document, $st_bold_12_Heading); text ($document, "3 RISK LEVEL DEFINITIONS"); enter ($document); set_style($document, $st_bold_12_Heading); text ($document, "4 APPROACH"); enter ($document); # While loop to return everything that meets the selects statements while (my @row=$stg->fetchrow_array) { my @row1=$sth->fetchrow_array; my @row2=$stt->fetchrow_array; my @row3=$stf->fetchrow_array; set_style($document, $st_doc_12_Underline); text ($document, "Test Number: "); set_style($document, $st_doc_12_Body); text ($document, "@row"); enter ($document); set_style($document, $st_doc_12_Body); text ($document, "@row1"); enter ($document); set_style($document, $st_doc_12_Body); text ($document, "@row2"); enter ($document); set_style($document, $st_doc_12_Body); text ($document, "@row3\n\n"); enter ($document); } #########Subroutines######### sub text { my $document = shift; my $text = shift; $document->ActiveWindow->Selection -> TypeText($text); } # aka new line, newline or NL sub enter { my $document = shift; $document->ActiveWindow->Selection -> TypeParagraph; } sub set_style { my $document = shift; my $style_arg = shift; $document->ActiveWindow->Selection -> {Style} = $style_arg -> {name} +; } sub create_style { my $document = shift; my $fontname = shift; my $font_size = shift; my $bold = shift; my $italic = shift; my $underline = shift; my $style = $document->Styles->Add($cur_style); my $style_font = $style->{Font}; $style_font -> {Name } = $fontname; $style_font -> {Size } = $font_size; $style_font -> {Bold } = $bold; $style_font -> {Italic} = $italic; $style_font -> {Underline} = $underline; my %style; $style{name} = $cur_style++; return \%style; }

janitored by ybiC: Balanced <readmore> tags around longish codeblock, as per Monastery convention


In reply to Microsoft Word Problem by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.