
dennismonsewicz
Members-
Posts
1,136 -
Joined
-
Last visited
Everything posted by dennismonsewicz
-
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
RHODESA YOUR A GENIOUS! I took the code out of the switch and placed in another file called excel.php and then linked over to it and it worked! There was something happening in the switch Everything works like a charm now! You ROCK! -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
I even had a coworker go to the exact link and on a windows machine using Office 03 and still is having the same problem -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Ok... I clicked your link and was able to open it. I updated the PHP script, and still the same problem. I did notice this though: When I click on my link and try to open it, Excel displays this message: But when I click on your link it works and does not display the above message -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Sure here is the code I am using: The following is my code in my switch case "export": include "../includes/db_login.php"; include "excelWriter.inc.php"; $excel=new ExcelWriter(); $myArr=array("Id","Product","Company","Description","Web Address","Last Used","Where product was last used","Is product active or inactive?"); $excel->writeLine($myArr); $query = "SELECT * FROM table_name"; $result = mysql_query($query); if(!$result){ die("Could not query the database: <br/>" . mysql_error()); } while($row = mysql_fetch_array($result, MYSQL_ASSOC)){ $id = $row['rowid']; $company = $row['company']; $product = $row['product']; $description = $row['description']; $web = $row['web']; $last = $row['last']; $used = $row['used']; $active = $row['active']; $myArr = array($id,$product,$company,$description,$web,$last,$used,$active); $excel->writeLine($myArr); } $excel->send('hr'); exit; } /* END SWITCH */ Here is the code I am using for my include: <?php class ExcelWriter{ var $data = null; var $filename = null; var $newRow = false; function ExcelWriter(){ } function writeLine($line_arr){ if(!is_array($line_arr)){ trigger_error("Error : Argument is not valid. Supply an valid Array.",E_USER_WARNING); return false; } $this->data .= " <tr>\n"; foreach($line_arr as $value) $this->data .= " <td class=xl24 width=64 >{$value}</td>\n"; $this->data .= " </tr>\n"; } function send($filename = null){ if($filename){ header ( "Expires: Mon, 1 Apr 1974 05:00:00 GMT" ); header ( "Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT" ); header ( "Pragma: no-cache" ); header ( "Content-type: application/x-msexcel" ); header ( "Content-Disposition: attachment; filename={$filename}.xls" ); } print $this->GetHeader(); print $this->data; print $this->GetFooter(); if($filename) exit; } function GetHeader(){ ob_start(); ?> <html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=us-ascii"> <meta name=ProgId content=Excel.Sheet> <!--[if gte mso 9]><xml> <o:DocumentProperties> <o:LastAuthor>Sriram</o:LastAuthor> <o:LastSaved>2005-01-02T07:46:23Z</o:LastSaved> <o:Version>10.2625</o:Version> </o:DocumentProperties> <o:OfficeDocumentSettings> <o:DownloadComponents/> </o:OfficeDocumentSettings> </xml><![endif]--> <style> <!--table {mso-displayed-decimal-separator:"\."; mso-displayed-thousand-separator:"\,";} @page {margin:1.0in .75in 1.0in .75in; mso-header-margin:.5in; mso-footer-margin:.5in;} tr {mso-height-source:auto;} col {mso-width-source:auto;} br {mso-data-placement:same-cell;} .style0 {mso-number-format:General; text-align:general; vertical-align:bottom; white-space:nowrap; mso-rotate:0; mso-background-source:auto; mso-pattern:auto; color:windowtext; font-size:10.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Arial; mso-generic-font-family:auto; mso-font-charset:0; border:none; mso-protection:locked visible; mso-style-name:Normal; mso-style-id:0;} td {mso-style-parent:style0; padding-top:1px; padding-right:1px; padding-left:1px; mso-ignore:padding; color:windowtext; font-size:10.0pt; font-weight:400; font-style:normal; text-decoration:none; font-family:Arial; mso-generic-font-family:auto; mso-font-charset:0; mso-number-format:General; text-align:general; vertical-align:bottom; border:none; mso-background-source:auto; mso-pattern:auto; mso-protection:locked visible; white-space:nowrap; mso-rotate:0;} .xl24 {mso-style-parent:style0; white-space:normal;} --> </style> <!--[if gte mso 9]><xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <x:Name>srirmam</x:Name> <x:WorksheetOptions> <x:Selected/> <x:ProtectContents>False</x:ProtectContents> <x:ProtectObjects>False</x:ProtectObjects> <x:ProtectScenarios>False</x:ProtectScenarios> </x:WorksheetOptions> </x:ExcelWorksheet> </x:ExcelWorksheets> <x:WindowHeight>10005</x:WindowHeight> <x:WindowWidth>10005</x:WindowWidth> <x:WindowTopX>120</x:WindowTopX> <x:WindowTopY>135</x:WindowTopY> <x:ProtectStructure>False</x:ProtectStructure> <x:ProtectWindows>False</x:ProtectWindows> </x:ExcelWorkbook> </xml><![endif]--> </head> <body link=blue vlink=purple> <table x:str border=0 cellpadding=0 cellspacing=0 style='border-collapse: collapse;table-layout:fixed;'> <?php return ob_get_clean(); } function GetFooter(){ return "</table></body></html>"; } } ?> -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
ok... so I commented out the first thing, to just get the headers to come through and it did not work. So something is wrong somewhere, obviously everything is spelled correctly. I am running this script inside of a switch with a case name of export. -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Sorry about not getting back with everyone late yesterday. I left work and then a bad storm came through the area so no internet. I am at work now working on the script now. I will be in contact today. Thanks again for everyone's help! -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Yep I am using the exact file you uploaded. It opens Excel but cannot open the XLS file spreadsheet itself. I have even tried on another computer and it cannot open the spreadsheet. Any thoughts? -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
I can run the example script. I am trying to run the modified script from rhodesa. I am going to probably have to revert back to the old one i guess -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
I have office 04 (MAC) But I sent it to a co worker who has office 03 (windows) and it still did not open -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Anyone have any ideas? -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Like it opens Excel but cannot open the actual XLS file. This saddens me -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
ok so I have this slight problem: It worked, but when I try to open the file it physically does not open the file HAHA this is pretty funny. Any ideas on this? -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
the file problem has been fixed, but it keeps looping the same sentence and it is only writing one record into the Excel sheet! -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
ok I am not getting an error but I am getting this problem: It is looping the line of "data is write into hr.xls successfully" There is only one record recorded into the XLS file And the file is not over-writing the previous one. Here is my code: include "../includes/db_login.php"; include("../excel/excelwriter.inc.php"); $excel=new ExcelWriter(); $myArr=array("Id","Product","Company","Description","Web Address","Last Used","Where product was last use","Is product active or inactive?"); $excel->writeLine($myArr); $query = "SELECT * FROM $tablename"; $result = mysql_query( $query ); if(!$result) { die("Could not query the database: <br/>" . mysql_error()); } while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { $id = $row['rowid']; $company = $row['company']; $product = $row['product']; $description = $row['description']; $web = $row['web']; $last = $row['last']; $used = $row['used']; $active = $row['active']; $myArr=array($id,$product,$company,$description,$web,$last,$used,$active); $excel->writeLine($myArr); $excel->close(); echo "data is write into hr.xls Successfully."; } $excel->send('hr'); -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Rhodesa, is there a way to make the array's dynamic? I see where you can manually add them but how would I make them dynamic? Making them dynamic would probably be a lot easier to manage. -Dennis -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Yeah I actually need for this to be dynamic. I am trying to locate the documentation now, and can't seem to find out how to do that? -
[SOLVED] Export Data into Excel Spreadsheet
dennismonsewicz replied to dennismonsewicz's topic in PHP Coding Help
Rhodesa, So in the below code I change the values of the $myArr variable array with the values of my header names from my DB table? <?php include("excelwriter.inc.php"); $excel=new ExcelWriter("myXls.xls"); if($excel==false) echo $excel->error; $myArr=array("Name","Last Name","Address","Age"); $excel->writeLine($myArr); $myArr=array("Sriram","Pandit","23 mayur vihar",24); $excel->writeLine($myArr); $excel->writeRow(); $excel->writeCol("Manoj"); $excel->writeCol("Tiwari"); $excel->writeCol("80 Preet Vihar"); $excel->writeCol(24); $excel->writeRow(); $excel->writeCol("Harish"); $excel->writeCol("Chauhan"); $excel->writeCol("115 Shyam Park Main"); $excel->writeCol(22); $myArr=array("Tapan","Chauhan","1st Floor Vasundhra",25); $excel->writeLine($myArr); $excel->close(); echo "data is write into myXls.xls Successfully."; ?> -
Does anyone know how I can do a PHP export from a website into an excel spreadsheet? Example: My company intranet has a ton of data that is loaded into MySQL and one of the users of the intranet wants an export to excel function. So if they are looking at a table of data they can click on export to excel and it does it. Anyone know where to start? -Dennis