Wednesday 15 September 2010

javascript - PHPExcel - Render HTML markups on output -



javascript - PHPExcel - Render HTML markups on output -

in site have several forms using ckeditor store it's data. when export content, in excel can see markups on document. there easy way convert \n or somehow have phpexcel recognize them breaks?

i tried changing export type excel2007 thinking maybe excel render html markup, when switch types study crashes. im sticking excel5.

any help appreciated.

<?php /** phpexcel */ require_once '/excelphp/classes/phpexcel.php'; // create new phpexcel object $objphpexcel = new phpexcel(); $rows=2; $sheet=$objphpexcel->getactivesheet(); // set properties $objphpexcel->getproperties()->setcreator("maarten balliauw") ->setlastmodifiedby("maarten balliauw") ->settitle("office 2007 xlsx test document") ->setsubject("office 2007 xlsx test document") ->setdescription("test document office 2007 xlsx, generated using php classes.") ->setkeywords("office 2007 openxml php") ->setcategory("test result file"); //this hard coded *non dynamic* cell formatting $sheet->getcolumndimension('a')->setwidth(5); $sheet->getcolumndimension('b')->setwidth(15); $sheet->getcolumndimension('c')->setwidth(50); $sheet->getcolumndimension('d')->setwidth(50); $sheet->getsheetview()->setzoomscale(90); $sheet->getstyle('a:d') ->getalignment()->setvertical(phpexcel_style_alignment::vertical_center); //font setting back upwards grouping title. $support_team = array('font'=> array('bold'=> true,'color' => array('rgb' => '4d4d4d'),'size' => 22,'name' => 'arial'),'alignment' => array('horizontal' => phpexcel_style_alignment::horizontal_center,'vertical' => phpexcel_style_alignment::vertical_center),); //font settings header cells only. $headers = array('font'=> array('bold'=> true,'color' => array('rgb' => '4d4d4d'),'size' => 12,'name' => 'arial'),'alignment' => array('horizontal' => phpexcel_style_alignment::horizontal_center,'vertical' => phpexcel_style_alignment::vertical_center),); //border settings $borders = array('borders' => array('inside'=> array('style' => phpexcel_style_border::border_thin,'color' => array('argb' => '717171')),'outline' => array('style' => phpexcel_style_border::border_thin,'color' => array('argb' => '717171')))); // sql database connections $db = mysql_connect("localhost", "imc_coe2", "imc123"); mysql_select_db("imc_coe2",$db); $sql="select client, team_name,support_team_prime,prime_comments,support_team_backup,backup_comments,escalation1,escalation1_comments,escalation2,escalation2_comments,escalation3,escalation3_comments,escalation4,escalation4_comments,note tbl_address order team_name"; $result=mysql_query($sql); $numrows=mysql_num_rows($result); if ($numrows>0) { while($data=mysql_fetch_array($result)) { //cell merging $sheet ->mergecells('b'.$rows.':d'.$rows) ->mergecells('b'.($rows+2).':d'.($rows+2)) ->mergecells('b'.($rows+5).':d'.($rows+5)) ->mergecells('b'.($rows+10).':d'.($rows+10)) ->mergecells('c'.($rows+1).':d'.($rows+1)) ->mergecells('b'.($rows+11).':d'.($rows+11)); // add together info $objphpexcel->setactivesheetindex(0) ->setcellvalue('b'.($rows+1), 'client:') ->setcellvalue('b'.($rows+2), 'support grouping contacts') ->setcellvalue('b'.($rows+3), 'prime:') ->setcellvalue('b'.($rows+4), 'backup:') ->setcellvalue('b'.($rows+5), 'escalations') ->setcellvalue('b'.($rows+6), 'escalation 1:') ->setcellvalue('b'.($rows+7), 'escalation 2:') ->setcellvalue('b'.($rows+8), 'escalation 3:') ->setcellvalue('b'.($rows+9), 'escalation 4:') ->setcellvalue('b'.($rows+10), 'notes'); //format hardcoded text $sheet->getstyle('b'.$rows)->applyfromarray($support_team); $sheet->getstyle('b'.($rows+2))->applyfromarray($headers); $sheet->getstyle('b'.($rows+5))->applyfromarray($headers); $sheet->getstyle('b'.($rows+10))->applyfromarray($headers); //row height adjustments $sheet->getrowdimension($rows+3)->setrowheight(60); $sheet->getrowdimension($rows+4)->setrowheight(60); $sheet->getrowdimension($rows+6)->setrowheight(60); $sheet->getrowdimension($rows+7)->setrowheight(60); $sheet->getrowdimension($rows+8)->setrowheight(60); $sheet->getrowdimension($rows+9)->setrowheight(60); $sheet->getrowdimension($rows+11)->setrowheight(100); //cell wraptext $sheet->getstyle('c'.($rows+1).':d'.($rows+1))->getalignment()->setwraptext(true); $sheet->getstyle('c'.($rows+3).':d'.($rows+3))->getalignment()->setwraptext(true); $sheet->getstyle('c'.($rows+4).':d'.($rows+4))->getalignment()->setwraptext(true); $sheet->getstyle('c'.($rows+6).':d'.($rows+6))->getalignment()->setwraptext(true); $sheet->getstyle('c'.($rows+7).':d'.($rows+7))->getalignment()->setwraptext(true); $sheet->getstyle('c'.($rows+8).':d'.($rows+8))->getalignment()->setwraptext(true); $sheet->getstyle('c'.($rows+9).':d'.($rows+9))->getalignment()->setwraptext(true); $sheet->getstyle('b'.($rows+11).':d'.($rows+11))->getalignment()->setwraptext(true); //background color on cells $sheet->getstyle('b'.$rows.':d'.$rows)->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ff9bc2e6'); $sheet->getstyle('b'.($rows+2).':d'.($rows+2))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ff9bc2e6'); $sheet->getstyle('b'.($rows+5).':d'.($rows+5))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ff9bc2e6'); $sheet->getstyle('b'.($rows+10).':d'.($rows+10))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ff9bc2e6'); $sheet->getstyle('b'.($rows+1))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ffe6f1fa'); $sheet->getstyle('b'.($rows+3))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ffe6f1fa'); $sheet->getstyle('b'.($rows+4))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ffe6f1fa'); $sheet->getstyle('b'.($rows+6))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ffe6f1fa'); $sheet->getstyle('b'.($rows+7))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ffe6f1fa'); $sheet->getstyle('b'.($rows+8))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ffe6f1fa'); $sheet->getstyle('b'.($rows+9))->getfill()->setfilltype(phpexcel_style_fill::fill_solid)->getstartcolor()->setargb('ffe6f1fa'); //border range $sheet->getstyle('b'.$rows.':d'.($rows+11))->applyfromarray($borders); //this section actual info imported sql database *don't touch* $objphpexcel->setactivesheetindex(0) ->setcellvalue('c'.($rows+1), utf8_encode($data['client'])) //this give cell c2. ->setcellvalue('b'.$rows, utf8_encode($data['team_name'])) // give cell b2 ->setcellvalue('c'.($rows+3), utf8_encode($data['support_team_prime'])) //this give c5 ->setcellvalue('d'.($rows+3), utf8_encode($data['prime_comments'])) // give d5 ->setcellvalue('c'.($rows+4), utf8_encode($data['support_team_backup'])) //this give c6 ->setcellvalue('d'.($rows+4), utf8_encode($data['backup_comments'])) //this give d6 ->setcellvalue('c'.($rows+6), utf8_encode($data['escalation1']))//this give c8 ->setcellvalue('d'.($rows+6), utf8_encode($data['escalation1_comments']))//this give d8 ->setcellvalue('c'.($rows+7), utf8_encode($data['escalation2']))//this give c9 ->setcellvalue('d'.($rows+7), utf8_encode($data['escalation2_comments']))//this give d9 ->setcellvalue('c'.($rows+8), utf8_encode($data['escalation3']))//this give c10 ->setcellvalue('d'.($rows+8), utf8_encode($data['escalation3_comments']))//this give d10 ->setcellvalue('c'.($rows+9), utf8_encode($data['escalation4']))//this give c11 ->setcellvalue('d'.($rows+9), utf8_encode($data['escalation4_comments']))//this give d11 ->setcellvalue('b'.($rows+11), utf8_encode($data['note'])); //this give b13 $rows+=14; } } // rename sheet $sheet->settitle('directory tool total dump'); // set active sheet index first sheet, excel opens first sheet $objphpexcel->setactivesheetindex(0); // redirect output client’s web browser (excel5) ob_end_clean(); $objwriter = phpexcel_iofactory::createwriter($objphpexcel, 'excel5'); header('content-type: application/vnd.ms-excel'); $today=date("f.d.y"); $filename = "directory_export-$today.xls"; header("content-disposition: attachment; filename=$filename"); header("cache-control: must-revalidate, post-check=0, pre-check=0"); $objwriter->save('php://output'); exit; ?>

ms excel has no concept of html markup within cell, it's string value.... storing value abc<br />def treated string containing abc<br />def , not 2 lines containing abc , def respectively. if want treated 2 lines need alter <br /> "\n". need set cell alignment wrap.

javascript php html phpexcel

No comments:

Post a Comment