in reply to Re^2: Insert blank rows in a CSV
in thread Insert blank rows in a CSV

runrig's advice still applies.  print CSV_HANDLE ",,,,,\n"; would print a row with six empty cells to CSV_HANDLE file handle.

Replies are listed 'Best First'.
Re^4: Insert blank rows in a CSV
by ArmandoG (Sexton) on Jan 09, 2008 at 19:47 UTC
    Hi I am kinda new to Perl, Its going to sound dumb but, my CSV_Handle which one is it these is the code:
    # create the sql select statement my $sql = "SELECT * INTO OUTFILE 'c:/proyecto/$filename' FIELDS TERMINATED BY ',' LINES TERMINATED BY '\r\n' FROM t3132"; my $sth = $dbh->prepare($sql); $sth->execute (); $sth->finish (); $dbh->disconnect (); my $Excel = Win32::OLE->GetActiveObject('Excel.Application') || Win32::OLE->new('Excel.Application', 'Quit'); #------ Abro el archivo CSV y lo dirijo al primera hoja de trabajo --- +-- my $Book = $Excel->Workbooks->Open("c:\\proyecto\\$filename"); my $Sheet = $Book->Worksheets(1); print $filename ",,,,,\n"; #------ Busco las ultimas celdas usadas en la hoja de trabajo ------ my $LastRow = $Sheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByRows})->{Row}; my $LastCol = $Sheet->UsedRange->Find({What=>"*", SearchDirection=>xlPrevious, SearchOrder=>xlByColumns})->{Column}; #------ Imprimo en pantalla los valores ------- print "Ultima Columna:\n"; print "$LastCol\n"; print "Ultimo renglon:\n"; print "$LastRow\n"; #------ Ahora busco las celdas de la hoja de excel ----- #en este caso dejo la primera linea sin contar porque es la de los enc +abezados my ($Start_col, $Num_Cols,$End_col) = ('A', $LastCol, 'A'); ++$End_col while --$Num_Cols; my ($Start_row, $Num_rows) = (4, $LastRow); my $End_row = $Start_row + $Num_rows - 1; my $Range_str = "$Start_col$Start_row:$End_col$End_row"; #------ Imprimo los valores ----------- print $Start_col; print $Start_row; print $End_col; print $End_row; print "Fin de busqueda de los datos"; my $range2 = $Sheet->Range($Range_str); $range2->AutoFormat(7);
    thanks
      Instead of selecting straight into a file, you might want to write the file using Spreadsheet::WriteExcel. That module is capable of inserting images into the spreadsheet. You then wouldn't need to use Win32::OLE.
      Generally, when you want to open a file for writing, you would do something like:
      open FILE_HANDLE, ">filename.csv" or die "Couldn't open filename.csv f +or writing $!";
      and then to print to the file you would specify the file handle as part of the print statement, hence print FILE_HANDLE ",,,,,\n"; In this case, I can see where you're opening the work book with Win32::OLE, but all of your print statements seem to be going to standard output, which won't write anything to the file.

      update: fixed type (thanks blazar)