homer.favenir Posted October 24, 2008 Share Posted October 24, 2008 hi, can someone help me please. im desperately need some help here. i tried different functions and a lot of searching but i cant really find the answer. i like to export my output text file to excel. my script <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title><?php echo $batch[8] ?></title> </head> <?php $kebase = $batch[0]; $qcbase = $batch[1]; $dir = $batch[2]; $kedir = $batch[3]; $qcdir = $batch[4] ; $kefiles = $batch[5]; $qcfiles = $batch[6]; $count_files = $batch[7] - 2; ?> <?php echo $count_files . " " . "files found" . " " . "in" . " " . $dir . " " . "directory" . "<br>"; ?> <?php echo anchor('Front_cont/index', 'Home'); ?> <pre> <table border="1" width="0" cellpadding="0" cellspacing="5"> <th>Batch/Line</th> <th>Field Image</th> <th>Minor Error</th> <th>Major Error</th> <tr> <?php for($i = 2; $i <= $count_files; $i++) { if(isset($qcfiles[$i])) { ?> <?php echo "<tr><td>"; ?><h4><?php echo $qcfiles[$i];?></h4><?php echo "</td></tr>"; ?> <?php $file1 = file($kedir . "/" . $kefiles[$i]); $file2 = file($qcdir . "/" . $qcfiles[$i]); $file1_count = count($file1); $file2_count = count($file2); $count = 1; for($x = 0; $x <= $file1_count; $x++) { if(isset($file1[$x]) && isset($file2[$x])) { $vtag1 = substr($file1[$x],178,1); $vtag2 = substr($file2[$x],178,1); $page1 = substr($file1[$x],0,4); $page2 = substr($file2[$x],0,4); $type1 = substr($file1[$x],5,1); $type2 = substr($file2[$x],5,1); $name1 = substr($file1[$x],7,78); $name2 = substr($file2[$x],7,78); $ind1 = substr($file1[$x],0,1); $ind2 = substr($file2[$x],0,1); $addr1 = substr($file1[$x], 1, 78); $addr2 = substr($file2[$x], 1, 78); $city1 = substr($file1[$x], 79, 30); $city2 = substr($file2[$x], 79, 30); $state1 = substr($file1[$x], 110, 2); $state2 = substr($file2[$x], 110, 2); $zc1 = substr($file1[$x], 112, 5); $zc2 = substr($file2[$x], 112, 5); $tf1 = substr($file1[$x], 123, 40); $tf2 = substr($file2[$x], 123, 40); $ac1 = substr($file1[$x], 164, 3); $ac2 = substr($file2[$x], 164, 3); $phone1 = substr($file1[$x], 168, ; $phone2 = substr($file2[$x], 168, ; $fp = fopen('data.xls', 'w'); if($vtag2 == 1) { $fp = fopen('data.xls', 'w'); $page_comp = strcmp($page1, $page2); $type_comp = strcmp($type1, $type2); $name_comp = strcmp($name1, $name2); if($page_comp != 0) { $err_stat = 1; $error = TRUE; $err_line = $count; $err_page1 = $page1; $err_page2 = $page2;?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE Page: " . " " . $err_page1 . "\t" . "QC Page: " . " " . $err_page2; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($type_comp != 0) { $err_stat = 1; $error = TRUE; $err_line = $count; $err_type1 = $type1; $err_type2 = $type2;?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE List Type: " . " " . $err_type1 . "<br>" . "QC List Type: " . " " . $err_type2; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($name_comp != 0) { $err_stat = 1; $error = TRUE; $err_line = $count; $err_name1 = $name1; $err_name2 = $name2; ?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE Name: " . " " . $err_name1 . "<br>" . "QC Name: " . " " . $err_name2; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } }else{ $ind_comp = strcmp($ind1, $ind2); $addr_comp = strcmp($addr1, $addr2); $city_comp = strcmp($city1, $city2); $state_comp = strcmp($state1, $state2); $zc_comp = strcmp($zc1, $zc2); $tf_comp = strcmp($tf1, $tf2); $ac_comp = strcmp($ac1, $ac2); $phone_comp = strcmp($phone1, $phone2); if($ind_comp != 0) { $error = TRUE; $err_line = $count; $err_ind1 = $ind1; $err_ind2 = $ind2;?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE Indent: " . " " . $err_ind1 . "<br>" . "QC Indent: " . " " . $err_ind2; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($addr_comp != 0) { $error = TRUE; $err_line = $count; $err_addr1 = $addr1; $err_addr2 = $addr2;?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE Address: " . " " . $err_addr1 . "<br>" . "QC Address: " . " " . $err_addr2; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($city_comp != 0) { $error = TRUE; $err_line = $count; $err_city1 = $city1; $err_city2 = $city2; ?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE City: " . " " . $err_city1 . "<br>" . "QC City: " . " " . $err_city2; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($state_comp != 0) { $error = TRUE; $err_line = $count; $err_state1 = $state1; $err_state2 = $state2; ?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE State: " . " " . $err_state1 . "<br>" . "QC State: " . " " . $err_state2; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($zc_comp != 0) { $error = TRUE; $err_line = $count; $err_zc1 = $zc1; $err_zc2 = $zc2; ?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE ZipCode: " . " " . $err_zc1 . "<br>" . "QC ZipCode: " . " " . $err_zc2; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($tf_comp != 0) { $error = TRUE; $err_line = $count; $err_tf1 = $tf1; $err_tf2 = $tf2; ?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE TollFreeText: " . " " . $err_tf1 . "<br>" . "QC TollFreeText: " . " " . $err_tf2; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($ac_comp != 0) { $error = TRUE; $err_line = $count; $err_ac1 = $ac1; $err_ac2 = $ac2; ?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE AreaCode: " . " " . $err_ac1 . "<br>" . "QC AreaCode: " . " " . $err_ac2; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } if($phone_comp != 0) { $error = TRUE; $err_line = $count; $err_phone1 = $phone1; $err_phone2 = $phone2; ?> <?php echo "<tr><td>"; ?> <?php echo "Line" . " " . $err_line;?><?php echo "</td>"; ?> <?php echo "<td>";?><?php echo "KE PhoneNumber: " . " " . $err_phone1 . "<br>" . "QC PhoneNumber: " . " " . $err_phone2; ?> <?php echo "<td>";?><?php if(!isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "<td>";?><?php if(isset($error)){echo 1;}?><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } } if(isset($err_name1)){echo $x. " " . $err_name1 . "<br>";} $count++; } } ?> <?php echo "<tr><td>"; ?><b><?php echo "Total";?></b><?php echo "</td>"; ?> <?php echo "<td>";?><?php ?> <?php echo "<td>";?><b><?php echo ""; ?></b><?php echo "</td>"; ?> <?php echo "<td>";?><b><?php echo ""; ?></b><?php echo "</td>"; ?> <?php echo "</td></tr>"; ?> <?php } } ?> </tr> </table> </pre> </head> </html> many thanks! Link to comment https://forums.phpfreaks.com/topic/129893-export-to-excel/ Share on other sites More sharing options...
Alt_F4 Posted October 24, 2008 Share Posted October 24, 2008 sorry, just to clarify - are you trying to read an existing text file and output it via php as an excel file? Link to comment https://forums.phpfreaks.com/topic/129893-export-to-excel/#findComment-673397 Share on other sites More sharing options...
homer.favenir Posted October 24, 2008 Author Share Posted October 24, 2008 yes i have a raw txt file and read it thru php. and i want to export the output from php to excel. Link to comment https://forums.phpfreaks.com/topic/129893-export-to-excel/#findComment-673437 Share on other sites More sharing options...
Alt_F4 Posted October 24, 2008 Share Posted October 24, 2008 ok and the text file how is it structured? By that i mean is each piece of data separated by a tab or on a new line etc Link to comment https://forums.phpfreaks.com/topic/129893-export-to-excel/#findComment-673445 Share on other sites More sharing options...
homer.favenir Posted October 24, 2008 Author Share Posted October 24, 2008 the text file is fixed length Link to comment https://forums.phpfreaks.com/topic/129893-export-to-excel/#findComment-673446 Share on other sites More sharing options...
ramarbstr12play Posted October 24, 2008 Share Posted October 24, 2008 You may want o look into PHP_EXCEL_WRITER from pear. http://pear.php.net/package/Spreadsheet_Excel_Writer Link to comment https://forums.phpfreaks.com/topic/129893-export-to-excel/#findComment-673450 Share on other sites More sharing options...
Alt_F4 Posted October 24, 2008 Share Posted October 24, 2008 have a look here: http://www.dreamincode.net/forums/showtopic10132.htm or here: http://www.999tutorials.com/tutorial-create-excel-files-with-php.html and see if that helps, Link to comment https://forums.phpfreaks.com/topic/129893-export-to-excel/#findComment-673451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.