PHP - Extract Images From Excel (xls) File
Hi all,
Does anyone know of a way of extracting/reading images from an excel file using PHP? This seems great (http://phpexcel.codeplex.com/) but I can't see a way of reading images from excel files. Any help would be greatly appreciated! Thanks Similar TutorialsI 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 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? Hi, how do I extract just file extension? eg: $file="hello.xml"; $fileExt=??? print $fileExt; Any help much appreciated! Hi guys, I'm using this upload/extract zip script. I wonder if I can modify the script to link the file after it is unzip. Now it just unzip and show the content, I want to give the link to that content. Please let me know if this even possible with the code below. <form enctype="multipart/form-data" action="index.php" method="POST"> Upload a Zip Archive (*.zip): <input name="zip" type="file" /><input type="submit" value="Upload" /> </form> <?php /* UnZip on Server - using PHP by 3scriptz.com */ //check if file is uploaded if(isset($_FILES['zip'])){ require_once('pclzip.lib.php'); //include class $upload_dir = 'uploads'; //your upload directory NOTE: CHMODD 0777 $filename = $_FILES['zip']['name']; //the filename //move file if(move_uploaded_file($_FILES['zip']['tmp_name'], $upload_dir.'/'.$filename)) echo "Uploaded ". $filename . " - ". $_FILES['zip']['size'] . " bytes<br />"; else die("<font color='red'>Error : Unable to upload file</font><br />"); $zip_dir = basename($filename, ".zip"); //get filename without extension fpr directory creation //create directory in $upload_dir and chmodd directory if(!@mkdir($upload_dir.'/'.$zip_dir, 0777)) die("<font color='red'>Error : Unable to create directory</font><br />"); $archive = new PclZip($upload_dir.'/'.$filename); if ($archive->extract(PCLZIP_OPT_PATH, $upload_dir.'/'.$zip_dir) == 0) die("<font color='red'>Error : Unable to unzip archive</font>"); //show what was just extracted $list = $archive->listContent(); echo "<br /><b>Files in Archive</b><br />"; for ($i=0; $i<sizeof($list); $i++) { if(!$list[$i]['folder']) $bytes = " - ".$list[$i]['size']." bytes"; else $bytes = ""; echo "".$list[$i]['filename']."$bytes<br />"; } unlink($upload_dir.'/'.$filename); //delete uploaded file } ?> Thanks Hi there, I have a cronjob for PHP which generates a table with dynamic data and this table is exported to excel when run. When i have one table it downloads one excel file. I want to download multiple excel files using a for loop. Please Help... Any suggestions will be helpful.. Thank you, Regards, Rohit For example: I am using this code: Code: [Select] $myFile = "newuser.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); echo $theData; and it displays: Code: [Select] Bob 2 Which I am reading from my newuser.txt file! Which corresponds to the username bob, and he has the ID of 2. Now I want to make that linkable like this: Code: [Select] <a href=.?act=Profile&id=$IDFROMTEXTFILE(2)>$NAMEFROMTEXTFILE(BOB)</a> this is possible? If so, Thanks! I'm trying to extract the contents of a zip file to a folder. I found the ZipArchive class and followed the examples to get it to work for the most part. But I want to extract the files in the folder inside the zip file but leave the folder out. So it should extract just the files to my given destination. I found this on php.net. Code: [Select] If you want to copy one file at a time and remove the folder name that is stored in the ZIP file, so you don't have to create directories from the ZIP itself, then use this snippet (basically collapses the ZIP file into one Folder). <?php $path = 'zipfile.zip' $zip = new ZipArchive; if ($zip->open($path) === true) { for($i = 0; $i < $zip->numFiles; $i++) { $filename = $zip->getNameIndex($i); $fileinfo = pathinfo($filename); copy("zip://".$path."#".$filename, "/your/new/destination/".$fileinfo['basename']); } $zip->close(); } ?> For some reason that 'copy' line is not working for me. Obviosly I've changed the variables in the line to the correct variables. Can someone help me out. Thanks Mike Hello, Hi Guys, I am looking for a way to format excel cells using PHP, I am exporting mysql data to excel file using below method: $fields = array("Date", "Time In", "Time Out", "Hours", "Project", "Component", "Sub-Component", "Work Done", "Supervisor Changes", PHP_EOL); file_put_contents($filename, implode("\t", $fields), FILE_APPEND); Now I want to make BOLD all this header fields, so please help me to this construct.. Thank you Hello, Is it possible to read the content of an excel file with file_get_contents. I tried it a couple times. The result looked like this: ������������������������������������������������������������������������������������������������������������������������������������Oh��+'��0�8@Td p|�WorkshopJohn@�v����@��p�������՜.��+,�D��՜.��+,�$�HPX`hp x�� HuidcoachHuidcoach en spec. in huidverbSheet3 f2�ـ����\pJohn B�a�=���=�?�8�@�"��1���A And if it's possible can somebody tell me what i'm doing wrong. Thanx I have an excel file that I want to show in PHP page. I dont want this to first download and then view. I want it something like gmail where you just click on the file name and it opens up. Can you please give me an idea as how to do this. Regards, Faisa Hello Everyone, I'm new to PHP and got a good big stuff. I would like to write an image in excel file. There will be almost 600+ rows and each row will have url and qrcode image. I would like to write an excel file which will write url and respective image into the next cell of the url. Is it possible to write an image in excel file? If yes, can anyone please guide me how? I have read so many post saying to use a pear package but again pear package is not allowing to write jpe/gif it only allows .bmp files. So, pear package is I don't think will work for me. I have also attached an example excel file which is showing the way I require to have an output. Please anyone if having any idea guide me and let me know. Thank you in advance for your help. Looking forward to hear from you soon! hello everyone, please anyone can help me how to read data of excel file in php Hello. I have one programming problem. I have this log, from witch i have to read specific area of text: webtopay.log OK 123.456.7.89 [2012-03-15 09:09:59 -0400] v1.5: MIKRO to:"1398", from:"865458961", id:"13525948", sms:"MCLADM thing" So i need the script to extract word "thing" from that log. Also that script has to check if there is new entries in the log, and extract text from the last one. (Explaining in other words, that script should extract word AFTER MCLADM. Every time its a different word) p.s. I need that script to be integrated here (this has to send command to server "/manuadd (text from log)" : Code: [Select] <?php try{ $HOST = "178.16.35.196"; //the ip of the bukkit server $password = "MCLietuva"; //Can't touch this: $sock = socket_create(AF_INET, SOCK_STREAM, 0) or die("error: could not create socket\n"); $succ = socket_connect($sock, $HOST, 4445) or die("error: could not connect to host\n"); //Authentification socket_write($sock, $command = md5($password)."<Password>", strlen($command) + 1) or die("error: failed to write to socket\n"); //Begin custom code here. socket_write($sock, $command = "/Command/ExecuteConsoleCommandAndReturn-SimpleBroadCast:broadcast lol;", strlen($command) + 1) //Writing text/command we want to send to the server or die("error: failed to write to socket\n"); sleep(2); // This is example code and here has to be that script i want to make. //while(($returnedString = socket_read($sock,50000))!= ""){ $returnedString = socket_read($sock,50000,PHP_NORMAL_READ); print($returnedString) //} print("End of script"); socket_close($sock); }catch(Exception $e){ echo $e->getMessage(); } ?> I hope i made things clear and you will help me Thanks Hi, this is my first time here. i am trying to create an xls file from the data i get from mysql. here is the code i tried but i am not able to use it correctly. Code: [Select] ob_start(); include('config'); $datacat = mysql_query("SELECT * FROM `leads`") or die(mysql_error()); $name = mysql_fetch_assoc($datacat); $line1="Industry,Company Name,Officials Name,Job Title,Country,Direct Number Mobile Number,Switch Board Number,E-mail,Executive NamePitch Date,Call Back Date,Comments\t"; while($row = mysql_fetch_array($datacat, MYSQL_ASSOC)) { $line2= $name['industry'].",".$name['company_name'].",".$name['officials_name'].",".$name['job_title'].",".$name['country'].",".$name['direct_number_mobile_number'].",".$name['switch_board_number'].",".$name['email'].",".$name['executive_name'].",".$name['pitch_date'].",".$name['call_back_date'].",".$name['comment']."\t"."\n"; } $data="$line1\n$line2\n"; header("Content-type: application/x-msdownload"); header("Content-Disposition: attachment; filename=extraction.xls"); header("Pragma: no-cache"); header("Expires: 0"); print "$header\n$data"; i get my webpage title in the top of xls file and all the fields in xls file are separated by commas, whereas i want them to be in proper tables. Help would be much appreciated. I have an excel file that has several columns with different data and I need to create a form that can upload this excel file and insert the data from the columns into its conrresponding data columns in a mysql database. I know how to create the form but I have no idea how to get the file and tell it to input each cell of data into its corresponding field in the mysql database. Does anyone know how to do this? Any help would be appreciated. Thanks, Hi.., My code is like: Code: [Select] <?php $filename ="excelreport.xls"; print "<table border=1>"; print "<tr ><td valign=bottom><img src=http://abc/images/big.png ></img></td> <td valign=bottom><img src=http://abc/images/small.png ></img></td> </tr>"; print "</table>"; header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename='.$filename); ?>when I open the excel file, the images alignment is from top to bottom(equal from top of image). what i want is from bottom to top(equal from bottom of image). i did try using valign in td property, but still the images equal from top of image thanks for any reply/ help what I am trying to do is use this php script to load the data being submitted in the html form into my database and then populate the database into an excel (xls) file and then e-mail it to my address. Everything works great it populates into the database and creates the xls file perfect. But it is wanting me to download the file. What can I add to the script to have it e-mail the file to my e-mail address INSTEAD of downloading it. Code: [Select] <?php define('DB_NAME', 'database'); define('DB_USER', 'username'); define('DB_PASSWORD', 'password'); define('DB_HOST', 'hostname'); $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); if (!$link) { die('Could not connect: ' . mysql_error()); } $db_selected = mysql_select_db(DB_NAME, $link); if (!$db_selected) { die('Can\'t use ' . DB_NAME . ': ' . mysql_error()); } $value1 = $_POST['groupname']; $value2 = $_POST['name']; $value3 = $_POST['address']; $value4 = $_POST['city']; $value5 = $_POST['state']; $value6 = $_POST['zip']; $value7 = $_POST['homephone']; $value8 = $_POST['cellphone']; $value9 = $_POST['email']; $value10 = $_POST['age']; $value11 = $_POST['maritalstatus']; $value12 = $_POST['income']; $value13 = $_POST['contact1']; $value14 = $_POST['contact2']; $value15 = $_POST['contact3']; $value16 = $_POST['date1']; $value17 = $_POST['date2']; $value18 = $_POST['date3']; $sql = "INSERT INTO clients (groupname, name, address, city, state, zip, homephone, cellphone, email, age, maritalstatus, income, contact1, contact2, contact3, date1, date2, date3) VALUES ('$value1', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } mysql_close(); mysql_connect('hostname', 'username', 'password'); mysql_select_db('database'); $sql = "SELECT `groupname` AS `Group`, `name` AS `Customer Name`, `address` AS `Address`, `city` AS `City`, `state` AS `State`, `zip` AS `Zip Code`, `homephone` AS `Home Phone`, `cellphone` AS `Cell Phone`, `email` AS `E-Mail`, `age` AS `Age Group`, `maritalstatus` AS `Marital Status`, `income` AS `Household Income`, `contact1` AS `Contact VIA`, `contact2` AS `Contact VIA`, `contact3` AS `Contact VIA`, `date1` AS `1st Date`, `date2` AS `2nd Date`, `date3` AS `3rd Date` FROM fundtour_info.clients clients"; // Query Database $result=mysql_query($sql); $filename = 'file.xls'; // Send Header header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header("Content-Type: application/octet-stream"); header("Content-Type: application/download");; header("Content-Disposition: attachment;filename=$filename"); header("Content-Transfer-Encoding: binary "); // XLS Data Cell xlsBOF(); xlsWriteLabel(0,0,"Group"); xlsWriteLabel(0,1,"Name"); xlsWriteLabel(0,2,"Address"); xlsWriteLabel(0,3,"City"); xlsWriteLabel(0,4,"State"); xlsWriteLabel(0,5,"Zip Code"); xlsWriteLabel(0,6,"Home Phone"); xlsWriteLabel(0,7,"Cell Phone"); xlsWriteLabel(0,8,"E-mail Address :"); xlsWriteLabel(0,9,"Age Group"); xlsWriteLabel(0,10,"Marital Status"); xlsWriteLabel(0,11,"Income"); xlsWriteLabel(0,12,"Contact Via"); xlsWriteLabel(0,13,"Dates"); $xlsRow = 1; while(list($groupname,$name,$address,$city,$state,$zip,$homephone,$cellphone,$email,$age,$maritalstatus,$income,$contact1, $contact2, $contact3,$date1, $date3, $date3)=mysql_fetch_row($result)) { ++$i; xlsWriteLabel($xlsRow,0,"$groupname"); xlsWriteLabel($xlsRow,1,"$name"); xlsWriteLabel($xlsRow,2,"$address"); xlsWriteLabel($xlsRow,3,"$city"); xlsWriteLabel($xlsRow,4,"$state"); xlsWriteLabel($xlsRow,5,"$zip"); xlsWriteLabel($xlsRow,6,"$homephone"); xlsWriteLabel($xlsRow,7,"$cellphone"); xlsWriteLabel($xlsRow,8,"$email"); xlsWriteLabel($xlsRow,9,"$age"); xlsWriteLabel($xlsRow,10,"$maritalstatus"); xlsWriteLabel($xlsRow,11,"$income"); xlsWriteLabel($xlsRow,12,"$contact1, $contact2, $contact3"); xlsWriteLabel($xlsRow,13,"$date1, $date3, $date3"); $xlsRow+++; } xlsEOF(); exit(); function xlsBOF() { echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0); return; } function xlsEOF() { echo pack("ss", 0x0A, 0x00); return; } function xlsWriteNumber($Row, $Col, $Value) { echo pack("sssss", 0x203, 14, $Row, $Col, 0x0); echo pack("d", $Value); return; } function xlsWriteLabel($Row, $Col, $Value ) { $L = strlen($Value); echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L); echo $Value; return; } ?> Thanks for any help Hi, i have export the search result to excel file, but arabic characters not displaying properly in excel file, eventhough i mention the header content type as utf-8 here my code... Code: [Select] <?php include("global.php"); // Original PHP code by Chirp Internet: www.chirp.com.au // Please acknowledge use of this code by including this header. function cleanData(&$str) { $str = preg_replace("/\t/", "\\t", $str); $str = preg_replace("/\r?\n/", "\\n", $str); if(strstr($str, '"')) $str = '"' . str_replace('"', '""', $str) . '"'; } $sql = $_SESSION['emp_search_sql']; // file name for download $filename = "employees_" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel; charset=UTF-8"); header("Pragma: no-cache"; $flag = false; $result = $DB_site->query($sql) or die('Query failed!'); while(false !== ($row = mysql_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"; } ?> Thanks, |