set_style($document, $st_doc_12_Underline); text ($document, "Test Number: "); set_style($document, $st_doc_12_Body); text ($document, "@row"); enter ($document);
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |