PHP - Reading Excel Spreadsheets
Can anyone tell me the best tools to read Excel files?
Similar Tutorialshello everyone, please anyone can help me how to read data of excel file in php I need some help and hopefully will respond. I'm trying to put some information to the second row of the excel sheet once extracted. Can somebody help me with this script? I'm trying to move the address line to the second row. Thanks. Hello, i am currently getting an Microsoft Excel formatted text file whose save type is .Txt from a URL.I used to open it and will change the save type as excel file. Please suggest whether we can do this with php code. currently my code is like this, <? php copy("http://www.faa.gov/airports/airport_safety/airportdata_5010/menu/emergencyplanexport.cfm?Region=&District=&State=&County=&City=LAS%20VEGAS&Use=&Certification=","./contactsexport.xls"); ?> where as the contactsexport.xls type is .Txt which i need it in .xls Thanks in Advance. Hi I have a database set up using MySQL and want to be able to query this and then export to Excel using PHP. I've had a look around on the web but a lot of what I'm reading is going over my head. I don't have PEAR so can't use the ready made stuff. Basically, I want to be able to query the database, then export the arrays to an excel file and a pop up to appear asking the user to open / save / cancel (standard pop-up) Anyone know of any good places to start looking for the information for this? Sorry, I'm new to all this so any help / pointers would be greatly appreciated. Cheers Hi All, I am trying to export a table into excel and it is working, kind of.. I'm trying to import data that has commas in it. Unfortunately, it looks like this "PHP to CVS" process is comma delimited. How can I get around that, while having the data in the correct columns? Here is my code: Code: [Select] $file = 'Notes_Export'; $csv_output = ''; $sql = "SHOW COLUMNS FROM prop_notes WHERE Field IN ('note', 'created_by', 'created_on', 'updated_by', 'updated_on')"; $result = mysqli_query($connect, $sql); $i = 0; if (mysqli_num_rows($result) > 0) { while ($row = mysqli_fetch_assoc($result)) { $csv_output .= $row['Field'].", "; $i++; } } $csv_output .= "\n"; $sql = "SELECT note, created_by, created_on, updated_by, updated_on FROM prop_notes"; $values = mysqli_query($connect, $sql); while($rowr = mysqli_fetch_row($values)) { for ($j=0;$j<$i;$j++) { $csv_output .= $rowr[$j].", "; } $csv_output .= "\n"; } $filename = $file."_".date("Y-m-d_H-i",time()); header("Content-type: application/vnd.ms-excel"); header("Content-disposition: csv" . date("Y-m-d") . ".csv"); // header( "Content-disposition: filename=".$filename.".csv"); header("Content-disposition: attachment; filename=".$filename.".csv"); print $csv_output; exit; Hi I have a script which references a DB and then produces an XML output saved as XLS to then open in Excel. This works an absolute dream in my dev environment using IE7 and in live using Firefox. However my entire audience uses IE7 and this is where it breaks in the live environment. For some reason, I cannot get the download to work. I get a windows pop-up with an error on it - see attached. If you need to see code, let me know which bit of code could possibly cause this, i.e. headers etc. I've not posted code as there's loads of it and I can't understand why it works in dev in IE 7 but not in live, and works in Firefox in live. I need to parse xls files (Microsoft Excel). The option to tell the users who will be uploading the files to convert it to a more friendly format like XML or CSV is not an option (I know its unfortunately, though I have to make it so it parses those formats as well (fun is)). Users must be able to just save the file, and upload it as is. below is a link to a example xls file. So I am looking to see if there's anything native to php that will allow me to open and read xls formatted files quickly and efficiently and work with the values independently on a per row per column basis when outputting them. Or if there's a recommended library/class I can use that someone here can suggest. My biggest issue is I am on a time crunch so I need something I can work with quickly and efficiently all around. Any samples would be greatly appreciated. http://mtpdev.com/dev/xls-reader/sample.xls I need a way of parsing Excel files.. both xls and xlsx in what seems to be various formats.. the concept of the way the expected sheets are to come in is with 2 tabs first tab row one column one will be a single value.. second tab will be any number of values only 2 columns though. I had found one parser class that I could use but it was very limiting and for some reason didn't work when I saved a fresh file... whats the best class, or way of handling an excel file? is there anything out there freely avaliable to work with thats kept upto date? or that works? Hi people. Need some help if anyone could give a hand! I'm currently trying to incorporate an export to Excel feature on search returns on my web page. Here is how my searches are returned, so what I want now is when the user clicks on the 'Export to Excel' button it downloads the search results and opens it in the same format in Excel. I've tried using http://phpexcel.codeplex.com/ but can't understand how to use it properly, does anyone have any suggestions? I don't have any code written for the Export to Excel yet as it's just a submit button. How I see it in my head is the user clicks the button, it goes to a new page and performs a new query then downloads that but I don't no if thats right or not. Is it possible to export a single value from a mysql DB into a pre-existing excel spread sheet? I know how to create a spread sheet from php and mysql, but not a single value into a pre-existing excel document cell. here's basically what I'm doing: Creating a financial expense tracking report in php, user will input each expense, it will keep a running tally of the available funds in user's bank account. The user has an excel spread sheet that requires the current value of available funds and updates a budget forecast according. SO, I need to somehow get the available balance of the bank account (generated by user input) into the pre-existing excel spreadsheet. Any thoughts? I'm totally at a loss. Thanks! Hi I have a page displaying orders from a mysql table. How can i add a button which exports this to an excel file? Hi Attached file I get sent a excel file as attached each day updating products and stock levels and prices.. I am trying to find away to dump that file into my database without having to restructure the excel file. It needs to be in the data base in such away that I can create a popout menu with the headings you see in the file i.e CPUs :: Intel CPUs :: AMD etc etc to filter the procucts in my shopping cart.. I have 3 tables atm, maincat, subcat and products.. But it takes way to long to try and manually sort the changes. Any Ideas on how I can do it by just dumping the excel file? ok, so I am not good with arrays, they confuse me. how can I set this up so that $data is all results that are returned from the database that correspond to it? Code: [Select] $data = array( array("firstname" => '$firstname', "lastname" => '$lastname', "age" => '$age')); the original code looked like: Code: [Select] <?PHP $data = array( array("firstname" => "Mary", "lastname" => "Johnson", "age" => 25), array("firstname" => "Amanda", "lastname" => "Miller", "age" => 18), array("firstname" => "James", "lastname" => "Brown", "age" => 31), array("firstname" => "Patricia", "lastname" => "Williams", "age" => 7), array("firstname" => "Michael", "lastname" => "Davis", "age" => 43), array("firstname" => "Sarah", "lastname" => "Miller", "age" => 24), array("firstname" => "Patrick", "lastname" => "Miller", "age" => 27) ); ?> but that won't do it for me. I need it so that the results from the database will automatically be filled in. basically, everyone that is in the database, so when a new member is added, they will show up too. please help Hi, I am attempting to export some table data to an excel spreadsheet. Below is the code I am working with. <?php include('includes/admin_session.php'); require_once("includes/connection.php"); function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } // file name for download $filename = "student_list_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; $result = mysqli_query($connection,"SELECT * FROM students ORDER BY tutor") or die(mysqli_error($connection)); while(false !== ($row = mysqli_fetch_assoc($result))) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } array_walk($row, 'cleanData'); echo implode("\t", array_values($row)) . "\n"; } ?> It is exporting the rows as requested and I am able to open the file in excel....however...when downloading it becomes stuck on a loop and continues to download over 20mb of nothing. As a result I am forced to stop the download. When I open my excel file, below my table data is the following error, over and over and over and over! Quote <br /> <b>Warning</b>: array_walk() [<a href='function.array-walk'>function.array-walk</a>]: The argument should be an array in <b>/home/inschool/public_html/student_list_export.php</b> on line <b>33</b><br /> <br /> <b>Warning</b>: array_values() [<a href='function.array-values'>function.array-values</a>]: The argument should be an array in <b>/home/inschool/public_html/student_list_export.php</b> on line <b>34</b><br /> <br /> <b>Warning</b>: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed in <b>/home/inschool/public_html/student_list_export.php</b> on line <b>34</b><br /> Any help on this would be awesome I have an excel file with many rows and columns but depending on the user I need it to show only one row. I am a php newbie. Hi. I have a large amount of data in an excel spread sheet. I have isolated 3 rows containing a date (yyyy-mm-dd plus two decimal values). I saved this as a tab delimited text instead of a comma separated csv. What I want to do is read each line of a text file and split it up into 3 and construct an INSERT INTO sql. the problem is this is not separated by comas for a split function. Can I split on a tab instead? I have used commas in the past only. TIA Desmond.
This topic has been moved to Miscellaneous. http://www.phpfreaks.com/forums/index.php?topic=345846.0 So i have this script, it pull data via mysql and inserts it into an excel file. However it does not properly tab each field as it should nor go to a new lines as it should instead it stick everything into 1 whole row. Ok but here's the kicker... this same identical script runs 100% fine on another website. The only difference is the query string. There it works fine on this new site it bugs out. any idea where the bug is? <?php include('dbcon.php'); $tablename = $_POST['tablename']; $full_query = "SELECT * FROM $tablename"; $header = ''; $data = ''; $export = mysql_query($full_query); $fields = mysql_num_fields($export); for ($i = 0; $i < $fields; $i++) { $header .= mysql_field_name($export, $i) . "\t"; } while($row = mysql_fetch_row($export)) { $line = ''; foreach($row as $value) { if ((!isset($value)) OR ($value == "")) { $value = "\t"; } else { $value = str_replace('"', '""', $value); $value = '"' . $value . '"' . "\t"; } $line .= $value; } $data .= trim($line)."\n"; } $data = str_replace("\r","",$data); if ($data == "") { $data = "\n(0) Records Found!\n"; } header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=monet_search_results.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; ?> PS: This is a linux box if that makes a difference. THANKS! my issue is each time a user selcts a category or sub category, the excel file stored in server is fetched, read and output its contents and then closed again.....its quite cumbersome cos what if multiple users were logged into the system doing this same process....server load wud b definitely high......so,i would like to parse excel files and store it as an array so that data can be retrieved from the array rather than opening the file,fetching data and closing it, then again opening it,fetching it and closing and so on.....i am thinking of reading the data into an array and then unset the array if a different category or subcategory is selected....is this solution even possible? am using this code Code: [Select] <?php require_once 'PHPExcel.php'; require_once 'PHPExcel/IOFactory.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("Matthew Casperson") ->setLastModifiedBy("Matthew Casperson") ->setTitle("Office 2007 XLSX Test Document") ->setSubject("Office 2007 XLSX Test Document") ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes."); $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A1', 'Hello') ->setCellValue('B2', 'world!') ->setCellValue('C1', 'Hello') ->setCellValue('D2', 'world!'); header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="test.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); ?> but excelsheet contain following error............. <b>Fatal error</b>: Class 'ZipArchive' not found in <b>C:\Program Files\xampp\htdocs\immigration\PHPExcelSourceCode\PHPExcel\Writer\Excel2007.php</b> on line <b>224</b><br /> but excelsheet contain this error............. please help how to fix it? |