Jump to content

dennismonsewicz

Members
  • Posts

    1,136
  • Joined

  • Last visited

Everything posted by dennismonsewicz

  1. 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!
  2. 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
  3. 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
  4. 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>"; } } ?>
  5. 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.
  6. 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!
  7. 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?
  8. 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
  9. I have office 04 (MAC) But I sent it to a co worker who has office 03 (windows) and it still did not open
  10. Like it opens Excel but cannot open the actual XLS file. This saddens me
  11. 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?
  12. the file problem has been fixed, but it keeps looping the same sentence and it is only writing one record into the Excel sheet!
  13. 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');
  14. 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
  15. 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?
  16. 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."; ?>
  17. 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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.