jschofield Posted January 26, 2007 Share Posted January 26, 2007 Hello php'ers,I have built a script that imports a xls and exports a csv. The xls file has the first 4 rows as a header that i am trying to remove usingmy php script. I know I can use the continue command but not to sure on how to use it. Below is my script. Any help from anyone would be a big help and really apprciated. Thanks, Johnnie.<?php$inputfile = "C:/SMDIM/Data/Data dump Holy Spirit School.xls";$outputfile = "C:/SMDIM/Data/All_Student_Data.csv";$logfilename = "C:/SMDIM/Logs/All_Student_Log.txt";include'C:/SMDIM/Translators/importlibrary.inc.php';//The query$query = "SELECT * FROM [Sheet1$]";//The excel driver we need$connection = odbc_connect('Driver={Microsoft Excel Driver (*.xls)}; DriverId=790;Dbq='.$inputfile.';','','');$count = 0;//Execute the queryif(!$dbexec = odbc_exec($connection, $query)) { wlogdie("Failed to execute the query"); }else{ wlog("Successfully executed the query");}//open the fileif(!$outfilefp = fopen($outputfile, "w")) { wlogdie("Failed to open $outputfile"); }else{ wlog("Opened $outputfile for writing"); }//add English language codes to the end of each linewhile (odbc_fetch_into($dbexec, $row)) { $row[12] = "English";$count++; writeLine($outfilefp, $row);}if($count !== '0') { wlog("finished the import with a total of $count records");}else{ wlog("Failed to import data");}?> Link to comment https://forums.phpfreaks.com/topic/35865-solved-php-working-with-excel/ Share on other sites More sharing options...
Psycho Posted January 26, 2007 Share Posted January 26, 2007 This should prevent the first row from being added to the output file[code]<?php$header = true;//add English language codes to the end of each linewhile (odbc_fetch_into($dbexec, $row)) { if($header) { $header = false; } else { $row[12] = "English"; $count++; writeLine($outfilefp, $row); }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/35865-solved-php-working-with-excel/#findComment-170053 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.