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

Sorry and thanks for the reply CountZero

Im currently learning perl and im trying to make some scripts

I have attached the snippet which wilnt work ..pls rectify my errors..

The format of the document is as follows:

Hi im going to extract from this document and the extraction starts here

1. Check1

Check2

2. Check3

Check4

3. Check5

Check6

The snippet im using is:

$ExcelSheet = getcwd."\\"."Sheet"; $ExcelSheet =~ s/\//\\/g; $Win32::OLE::Warn = 3; my $Excel = Win32::OLE->new('Excel.Application'); $Excel->{Visible} = 0; #0 is hidden, 1 is visible $Excel->{DisplayAlerts}=0; #0 is hide alerts $Excel->{ScreenUpdating} =0; # 0 False my $ExcelReport = $Excel->Workbooks->Open("$ExcelSheet"); my $Sheet=$ExcelReport->Worksheets(2); $Sheet->Activate; @checkfiles=glob('*.doc'); foreach my $file (@checkfiles) { my $document = Win32::OLE -> GetObject("$var"); print "Extracting Text ...\n"; my @array; my $paragraphs = $document->Paragraphs(); my $enumerate = new Win32::OLE::Enum($paragraphs); while(my $paragraph = $enumerate->Next()) { my $text = $paragraph->{Range}->{Text}; $text =~ s/[\n\r\t]//g; $text =~ s/\x0B/\n/g; $text =~ s/\x07//g; chomp $text; my $Data .= $text; @array=split(/\.$/,$Data); foreach my $line( @array) { if($line =~ m/starts here$/)

When "STARTS HERE" is matched the next following lines till the end of the document should be written to the excelsheet("$ExcelSheet")...and i want check1 and check2 to come in one cell and check3 and check4 to come in the next cell and so on.

Replies are listed 'Best First'.
Re: Writing into Excel sheet
by CountZero (Bishop) on Jan 15, 2012 at 08:37 UTC
    Im getting "Checking the com ports" in one cell and "testing is done" in the next cell whereas I want the whole point to come in the same cell.
    They are on two different lines in the word-file, so you get two different entries.

    BUT: your "snippet" cannot work. Your test if($line =~ m/starts here$/) will be true on the line that ends with starts here and false everywhere else, so you actually never reach the line that puts "Checking the com ports" into the spreadsheet!

    Anyhow, if you want to put more than one line in the same record, you will have to accumulate the data into a variable. That means you must know when to start and when to stop accumulating the data. From the limited extract of data you show, it is difficult to see how the word-file is made up. If you show us some more data, please put this data inside <code> ... </code> tags, so we can clearly see how it is formatted.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James