Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/lib/excel/test.php
Go to the documentation of this file.
00001 <?php
00002   //require_once('OLEwriter.php');
00003   //require_once('BIFFwriter.php');
00004   require_once('Worksheet.php');
00005   require_once('Workbook.php');
00006 
00007   function HeaderingExcel($filename) {
00008       header("Content-type: application/vnd.ms-excel");
00009       header("Content-Disposition: attachment; filename=$filename" );
00010       header("Expires: 0");
00011       header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
00012       header("Pragma: public");
00013       }
00014 
00015   // HTTP headers
00016   HeaderingExcel('test.xls');
00017 
00018   // Creating a workbook
00019   $workbook = new Workbook("-");
00020   // Creating the first worksheet
00021   $worksheet1 =& $workbook->add_worksheet('First One');
00022 // set the column width
00023   $worksheet1->set_column(1, 1, 40);
00024 // set the row height
00025   $worksheet1->set_row(1, 20);
00026   $worksheet1->write_string(1, 1, "This worksheet's name is ".$worksheet1->get_name());
00027   $worksheet1->write(2,1,"http://www.phpclasses.org/browse.html/package/767.html");
00028   $worksheet1->write_number(3, 0, 11);
00029   $worksheet1->write_number(3, 1, 1);
00030   $worksheet1->write_string(3, 2, "by four is");
00031   $worksheet1->write_formula(3, 3, "=A4 * (2 + 2)");
00032   //$worksheet1->write_formula(3, 3, "= SUM(A4:B4)");
00033   $worksheet1->write(5, 4, "= POWER(2,3)");
00034   $worksheet1->write(4, 4, "= SUM(5, 5, 5)");
00035   //$worksheet1->write_formula(4, 4, "= LN(2.71428)");
00036   //$worksheet1->write_formula(5, 4, "= SIN(PI()/2)");
00037 
00038   // Creating the second worksheet
00039   $worksheet2 =& $workbook->add_worksheet();
00040 
00041   // Format for the headings
00042   $formatot =& $workbook->add_format();
00043   $formatot->set_size(10);
00044   $formatot->set_align('center');
00045   $formatot->set_color('white');
00046   $formatot->set_pattern();
00047   $formatot->set_fg_color('magenta');
00048 
00049   $worksheet2->set_column(0,0,15);
00050   $worksheet2->set_column(1,2,30);
00051   $worksheet2->set_column(3,3,15);
00052   $worksheet2->set_column(4,4,10);
00053 
00054   $worksheet2->write_string(1,0,"Id",$formatot);
00055   $worksheet2->write_string(1,1,"Name",$formatot);
00056   $worksheet2->write_string(1,2,"Adress",$formatot);
00057   $worksheet2->write_string(1,3,"Phone Number",$formatot);
00058   $worksheet2->write_string(1,4,"Salary",$formatot);
00059 
00060   $worksheet2->write(3,0,"22222222-2");
00061   $worksheet2->write(3,1,"John Smith");
00062   $worksheet2->write(3,2,"Main Street 100");
00063   $worksheet2->write(3,3,"02-5551234");
00064   $worksheet2->write(3,4,100);
00065   $worksheet2->write(4,0,"11111111-1");
00066   $worksheet2->write(4,1,"Juan Perez");
00067   $worksheet2->write(4,2,"Los Paltos 200");
00068   $worksheet2->write(4,3,"03-5552345");
00069   $worksheet2->write(4,4,110);
00070   // if you are writing a very long worksheet, you may want to use
00071   // write_xxx() functions, instead of write() for performance reasons.
00072   $worksheet2->write_string(5,0,"11111111-1");
00073   $worksheet2->write_string(5,1,"Another Guy");
00074   $worksheet2->write_string(5,2,"Somewhere 300");
00075   $worksheet2->write_string(5,3,"03-5553456");
00076   $worksheet2->write(5,4,108);
00077 
00078 
00079   // Calculate some statistics
00080   $worksheet2->write(7, 0, "Average Salary:");
00081   $worksheet2->write_formula(7, 4, "= AVERAGE(E4:E6)");
00082   $worksheet2->write(8, 0, "Minimum Salary:");
00083   $worksheet2->write_formula(8, 4, "= MIN(E4:E6)");
00084   $worksheet2->write(9, 0, "Maximum Salary:");
00085   $worksheet2->write_formula(9, 4, "= MAX(E4:E6)");
00086 
00087   //$worksheet2->insert_bitmap(0, 0, "some.bmp",10,10);
00088 
00089   $workbook->close();
00090 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations