1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240 |
- <?php
- class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
- {
-
- private $parser;
-
- private $xlsStringMaxLength;
-
- private $columnInfo;
-
- private $selection;
-
- private $activePane;
-
- private $outlineOn;
-
- private $outlineStyle;
-
- private $outlineBelow;
-
- private $outlineRight;
-
- private $stringTotal;
-
- private $stringUnique;
-
- private $stringTable;
-
- private $colors;
-
- private $firstRowIndex;
-
- private $lastRowIndex;
-
- private $firstColumnIndex;
-
- private $lastColumnIndex;
-
- public $phpSheet;
-
- private $countCellStyleXfs;
-
- private $escher;
-
- public $fontHashIndex;
-
- public function __construct(&$str_total, &$str_unique, &$str_table, &$colors, $parser, $preCalculateFormulas, $phpSheet)
- {
-
- parent::__construct();
-
- $this->_preCalculateFormulas = $preCalculateFormulas;
- $this->stringTotal = &$str_total;
- $this->stringUnique = &$str_unique;
- $this->stringTable = &$str_table;
- $this->colors = &$colors;
- $this->parser = $parser;
- $this->phpSheet = $phpSheet;
-
-
- $this->xlsStringMaxLength = 255;
- $this->columnInfo = array();
- $this->selection = array(0,0,0,0);
- $this->activePane = 3;
- $this->_print_headers = 0;
- $this->outlineStyle = 0;
- $this->outlineBelow = 1;
- $this->outlineRight = 1;
- $this->outlineOn = 1;
- $this->fontHashIndex = array();
-
- $minR = 1;
- $minC = 'A';
- $maxR = $this->phpSheet->getHighestRow();
- $maxC = $this->phpSheet->getHighestColumn();
-
- $this->lastRowIndex = ($maxR > 65535) ? 65535 : $maxR ;
- $this->firstColumnIndex = PHPExcel_Cell::columnIndexFromString($minC);
- $this->lastColumnIndex = PHPExcel_Cell::columnIndexFromString($maxC);
- if ($this->lastColumnIndex > 255) {
- $this->lastColumnIndex = 255;
- }
- $this->countCellStyleXfs = count($phpSheet->getParent()->getCellStyleXfCollection());
- }
-
- public function close()
- {
- $phpSheet = $this->phpSheet;
- $num_sheets = $phpSheet->getParent()->getSheetCount();
-
- $this->storeBof(0x0010);
-
- $this->writePrintHeaders();
-
- $this->writePrintGridlines();
-
- $this->writeGridset();
-
- $phpSheet->calculateColumnWidths();
-
- if (($defaultWidth = $phpSheet->getDefaultColumnDimension()->getWidth()) < 0) {
- $defaultWidth = PHPExcel_Shared_Font::getDefaultColumnWidthByFont($phpSheet->getParent()->getDefaultStyle()->getFont());
- }
- $columnDimensions = $phpSheet->getColumnDimensions();
- $maxCol = $this->lastColumnIndex -1;
- for ($i = 0; $i <= $maxCol; ++$i) {
- $hidden = 0;
- $level = 0;
- $xfIndex = 15;
- $width = $defaultWidth;
- $columnLetter = PHPExcel_Cell::stringFromColumnIndex($i);
- if (isset($columnDimensions[$columnLetter])) {
- $columnDimension = $columnDimensions[$columnLetter];
- if ($columnDimension->getWidth() >= 0) {
- $width = $columnDimension->getWidth();
- }
- $hidden = $columnDimension->getVisible() ? 0 : 1;
- $level = $columnDimension->getOutlineLevel();
- $xfIndex = $columnDimension->getXfIndex() + 15;
- }
-
-
-
-
-
-
-
- $this->columnInfo[] = array($i, $i, $width, $xfIndex, $hidden, $level);
- }
-
- $this->writeGuts();
-
- $this->writeDefaultRowHeight();
-
- $this->writeWsbool();
-
- $this->writeBreaks();
-
- $this->writeHeader();
-
- $this->writeFooter();
-
- $this->writeHcenter();
-
- $this->writeVcenter();
-
- $this->writeMarginLeft();
-
- $this->writeMarginRight();
-
- $this->writeMarginTop();
-
- $this->writeMarginBottom();
-
- $this->writeSetup();
-
- $this->writeProtect();
-
- $this->writeScenProtect();
-
- $this->writeObjectProtect();
-
- $this->writePassword();
-
- $this->writeDefcol();
-
- if (!empty($this->columnInfo)) {
- $colcount = count($this->columnInfo);
- for ($i = 0; $i < $colcount; ++$i) {
- $this->writeColinfo($this->columnInfo[$i]);
- }
- }
- $autoFilterRange = $phpSheet->getAutoFilter()->getRange();
- if (!empty($autoFilterRange)) {
-
- $this->writeAutoFilterInfo();
- }
-
- $this->writeDimensions();
-
- foreach ($phpSheet->getRowDimensions() as $rowDimension) {
- $xfIndex = $rowDimension->getXfIndex() + 15;
- $this->writeRow($rowDimension->getRowIndex() - 1, $rowDimension->getRowHeight(), $xfIndex, ($rowDimension->getVisible() ? '0' : '1'), $rowDimension->getOutlineLevel());
- }
-
- foreach ($phpSheet->getCellCollection() as $cellID) {
- $cell = $phpSheet->getCell($cellID);
- $row = $cell->getRow() - 1;
- $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1;
-
- if ($row > 65535 || $column > 255) {
- break;
- }
-
- $xfIndex = $cell->getXfIndex() + 15;
- $cVal = $cell->getValue();
- if ($cVal instanceof PHPExcel_RichText) {
-
- $arrcRun = array();
- $str_len = PHPExcel_Shared_String::CountCharacters($cVal->getPlainText(), 'UTF-8');
- $str_pos = 0;
- $elements = $cVal->getRichTextElements();
- foreach ($elements as $element) {
-
- if ($element instanceof PHPExcel_RichText_Run) {
- $str_fontidx = $this->fontHashIndex[$element->getFont()->getHashCode()];
- } else {
- $str_fontidx = 0;
- }
- $arrcRun[] = array('strlen' => $str_pos, 'fontidx' => $str_fontidx);
-
- $str_pos += PHPExcel_Shared_String::CountCharacters($element->getText(), 'UTF-8');
- }
- $this->writeRichTextString($row, $column, $cVal->getPlainText(), $xfIndex, $arrcRun);
- } else {
- switch ($cell->getDatatype()) {
- case PHPExcel_Cell_DataType::TYPE_STRING:
- case PHPExcel_Cell_DataType::TYPE_NULL:
- if ($cVal === '' || $cVal === null) {
- $this->writeBlank($row, $column, $xfIndex);
- } else {
- $this->writeString($row, $column, $cVal, $xfIndex);
- }
- break;
- case PHPExcel_Cell_DataType::TYPE_NUMERIC:
- $this->writeNumber($row, $column, $cVal, $xfIndex);
- break;
- case PHPExcel_Cell_DataType::TYPE_FORMULA:
- $calculatedValue = $this->_preCalculateFormulas ?
- $cell->getCalculatedValue() : null;
- $this->writeFormula($row, $column, $cVal, $xfIndex, $calculatedValue);
- break;
- case PHPExcel_Cell_DataType::TYPE_BOOL:
- $this->writeBoolErr($row, $column, $cVal, 0, $xfIndex);
- break;
- case PHPExcel_Cell_DataType::TYPE_ERROR:
- $this->writeBoolErr($row, $column, self::mapErrorCode($cVal), 1, $xfIndex);
- break;
- }
- }
- }
-
- $this->writeMsoDrawing();
-
- $this->writeWindow2();
-
- $this->writePageLayoutView();
-
- $this->writeZoom();
- if ($phpSheet->getFreezePane()) {
- $this->writePanes();
- }
-
- $this->writeSelection();
-
- $this->writeMergedCells();
-
- foreach ($phpSheet->getHyperLinkCollection() as $coordinate => $hyperlink) {
- list($column, $row) = PHPExcel_Cell::coordinateFromString($coordinate);
- $url = $hyperlink->getUrl();
- if (strpos($url, 'sheet://') !== false) {
-
- $url = str_replace('sheet://', 'internal:', $url);
- } elseif (preg_match('/^(http:|https:|ftp:|mailto:)/', $url)) {
-
-
- } else {
-
- $url = 'external:' . $url;
- }
- $this->writeUrl($row - 1, PHPExcel_Cell::columnIndexFromString($column) - 1, $url);
- }
- $this->writeDataValidity();
- $this->writeSheetLayout();
-
- $this->writeSheetProtection();
- $this->writeRangeProtection();
- $arrConditionalStyles = $phpSheet->getConditionalStylesCollection();
- if (!empty($arrConditionalStyles)) {
- $arrConditional = array();
-
-
- $this->writeCFHeader();
-
- foreach ($arrConditionalStyles as $cellCoordinate => $conditionalStyles) {
- foreach ($conditionalStyles as $conditional) {
- if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_EXPRESSION
- || $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS) {
- if (!in_array($conditional->getHashCode(), $arrConditional)) {
- $arrConditional[] = $conditional->getHashCode();
-
- $this->writeCFRule($conditional);
- }
- }
- }
- }
- }
- $this->storeEof();
- }
-
- private function writeBIFF8CellRangeAddressFixed($range = 'A1')
- {
- $explodes = explode(':', $range);
-
- $firstCell = $explodes[0];
-
- if (count($explodes) == 1) {
- $lastCell = $firstCell;
- } else {
- $lastCell = $explodes[1];
- }
- $firstCellCoordinates = PHPExcel_Cell::coordinateFromString($firstCell);
- $lastCellCoordinates = PHPExcel_Cell::coordinateFromString($lastCell);
- return pack('vvvv', $firstCellCoordinates[1] - 1, $lastCellCoordinates[1] - 1, PHPExcel_Cell::columnIndexFromString($firstCellCoordinates[0]) - 1, PHPExcel_Cell::columnIndexFromString($lastCellCoordinates[0]) - 1);
- }
-
- public function getData()
- {
- $buffer = 4096;
-
- if (isset($this->_data)) {
- $tmp = $this->_data;
- unset($this->_data);
- return $tmp;
- }
-
- return false;
- }
-
- public function printRowColHeaders($print = 1)
- {
- $this->_print_headers = $print;
- }
-
- public function setOutline($visible = true, $symbols_below = true, $symbols_right = true, $auto_style = false)
- {
- $this->outlineOn = $visible;
- $this->outlineBelow = $symbols_below;
- $this->outlineRight = $symbols_right;
- $this->outlineStyle = $auto_style;
-
- if ($this->outlineOn) {
- $this->outlineOn = 1;
- }
- }
-
- private function writeNumber($row, $col, $num, $xfIndex)
- {
- $record = 0x0203;
- $length = 0x000E;
- $header = pack("vv", $record, $length);
- $data = pack("vvv", $row, $col, $xfIndex);
- $xl_double = pack("d", $num);
- if (self::getByteOrder()) {
- $xl_double = strrev($xl_double);
- }
- $this->append($header.$data.$xl_double);
- return(0);
- }
-
- private function writeString($row, $col, $str, $xfIndex)
- {
- $this->writeLabelSst($row, $col, $str, $xfIndex);
- }
-
- private function writeRichTextString($row, $col, $str, $xfIndex, $arrcRun)
- {
- $record = 0x00FD;
- $length = 0x000A;
- $str = PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($str, $arrcRun);
-
- if (!isset($this->stringTable[$str])) {
- $this->stringTable[$str] = $this->stringUnique++;
- }
- $this->stringTotal++;
- $header = pack('vv', $record, $length);
- $data = pack('vvvV', $row, $col, $xfIndex, $this->stringTable[$str]);
- $this->append($header.$data);
- }
-
- private function writeLabel($row, $col, $str, $xfIndex)
- {
- $strlen = strlen($str);
- $record = 0x0204;
- $length = 0x0008 + $strlen;
- $str_error = 0;
- if ($strlen > $this->xlsStringMaxLength) {
- $str = substr($str, 0, $this->xlsStringMaxLength);
- $length = 0x0008 + $this->xlsStringMaxLength;
- $strlen = $this->xlsStringMaxLength;
- $str_error = -3;
- }
- $header = pack("vv", $record, $length);
- $data = pack("vvvv", $row, $col, $xfIndex, $strlen);
- $this->append($header . $data . $str);
- return($str_error);
- }
-
- private function writeLabelSst($row, $col, $str, $xfIndex)
- {
- $record = 0x00FD;
- $length = 0x000A;
- $str = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($str);
-
- if (!isset($this->stringTable[$str])) {
- $this->stringTable[$str] = $this->stringUnique++;
- }
- $this->stringTotal++;
- $header = pack('vv', $record, $length);
- $data = pack('vvvV', $row, $col, $xfIndex, $this->stringTable[$str]);
- $this->append($header.$data);
- }
-
- private function writeNote($row, $col, $note)
- {
- $note_length = strlen($note);
- $record = 0x001C;
- $max_length = 2048;
-
- $length = 0x0006 + min($note_length, 2048);
- $header = pack("vv", $record, $length);
- $data = pack("vvv", $row, $col, $note_length);
- $this->append($header . $data . substr($note, 0, 2048));
- for ($i = $max_length; $i < $note_length; $i += $max_length) {
- $chunk = substr($note, $i, $max_length);
- $length = 0x0006 + strlen($chunk);
- $header = pack("vv", $record, $length);
- $data = pack("vvv", -1, 0, strlen($chunk));
- $this->append($header.$data.$chunk);
- }
- return(0);
- }
-
- public function writeBlank($row, $col, $xfIndex)
- {
- $record = 0x0201;
- $length = 0x0006;
- $header = pack("vv", $record, $length);
- $data = pack("vvv", $row, $col, $xfIndex);
- $this->append($header . $data);
- return 0;
- }
-
- private function writeBoolErr($row, $col, $value, $isError, $xfIndex)
- {
- $record = 0x0205;
- $length = 8;
- $header = pack("vv", $record, $length);
- $data = pack("vvvCC", $row, $col, $xfIndex, $value, $isError);
- $this->append($header . $data);
- return 0;
- }
-
- private function writeFormula($row, $col, $formula, $xfIndex, $calculatedValue)
- {
- $record = 0x0006;
-
- $stringValue = null;
-
- if (isset($calculatedValue)) {
-
-
- if (is_bool($calculatedValue)) {
-
- $num = pack('CCCvCv', 0x01, 0x00, (int)$calculatedValue, 0x00, 0x00, 0xFFFF);
- } elseif (is_int($calculatedValue) || is_float($calculatedValue)) {
-
- $num = pack('d', $calculatedValue);
- } elseif (is_string($calculatedValue)) {
- if (array_key_exists($calculatedValue, PHPExcel_Cell_DataType::getErrorCodes())) {
-
- $num = pack('CCCvCv', 0x02, 0x00, self::mapErrorCode($calculatedValue), 0x00, 0x00, 0xFFFF);
- } elseif ($calculatedValue === '') {
-
- $num = pack('CCCvCv', 0x03, 0x00, 0x00, 0x00, 0x00, 0xFFFF);
- } else {
-
- $stringValue = $calculatedValue;
- $num = pack('CCCvCv', 0x00, 0x00, 0x00, 0x00, 0x00, 0xFFFF);
- }
- } else {
-
- $num = pack('d', 0x00);
- }
- } else {
- $num = pack('d', 0x00);
- }
- $grbit = 0x03;
- $unknown = 0x0000;
-
- if ($formula{0} == '=') {
- $formula = substr($formula, 1);
- } else {
-
- $this->writeString($row, $col, 'Unrecognised character for formula');
- return -1;
- }
-
- try {
- $error = $this->parser->parse($formula);
- $formula = $this->parser->toReversePolish();
- $formlen = strlen($formula);
- $length = 0x16 + $formlen;
- $header = pack("vv", $record, $length);
- $data = pack("vvv", $row, $col, $xfIndex)
- . $num
- . pack("vVv", $grbit, $unknown, $formlen);
- $this->append($header . $data . $formula);
-
- if ($stringValue !== null) {
- $this->writeStringRecord($stringValue);
- }
- return 0;
- } catch (PHPExcel_Exception $e) {
-
- }
- }
-
- private function writeStringRecord($stringValue)
- {
- $record = 0x0207;
- $data = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($stringValue);
- $length = strlen($data);
- $header = pack('vv', $record, $length);
- $this->append($header . $data);
- }
-
- private function writeUrl($row, $col, $url)
- {
-
- return($this->writeUrlRange($row, $col, $row, $col, $url));
- }
-
- public function writeUrlRange($row1, $col1, $row2, $col2, $url)
- {
-
- if (preg_match('[^internal:]', $url)) {
- return($this->writeUrlInternal($row1, $col1, $row2, $col2, $url));
- }
- if (preg_match('[^external:]', $url)) {
- return($this->writeUrlExternal($row1, $col1, $row2, $col2, $url));
- }
- return($this->writeUrlWeb($row1, $col1, $row2, $col2, $url));
- }
-
- public function writeUrlWeb($row1, $col1, $row2, $col2, $url)
- {
- $record = 0x01B8;
- $length = 0x00000;
-
- $unknown1 = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
- $unknown2 = pack("H*", "E0C9EA79F9BACE118C8200AA004BA90B");
-
- $options = pack("V", 0x03);
-
- $url = join("\0", preg_split("''", $url, -1, PREG_SPLIT_NO_EMPTY));
- $url = $url . "\0\0\0";
-
- $url_len = pack("V", strlen($url));
-
- $length = 0x34 + strlen($url);
-
- $header = pack("vv", $record, $length);
- $data = pack("vvvv", $row1, $row2, $col1, $col2);
-
- $this->append($header . $data .
- $unknown1 . $options .
- $unknown2 . $url_len . $url);
- return 0;
- }
-
- public function writeUrlInternal($row1, $col1, $row2, $col2, $url)
- {
- $record = 0x01B8;
- $length = 0x00000;
-
- $url = preg_replace('/^internal:/', '', $url);
-
- $unknown1 = pack("H*", "D0C9EA79F9BACE118C8200AA004BA90B02000000");
-
- $options = pack("V", 0x08);
-
- $url .= "\0";
-
- $url_len = PHPExcel_Shared_String::CountCharacters($url);
- $url_len = pack('V', $url_len);
- $url = PHPExcel_Shared_String::ConvertEncoding($url, 'UTF-16LE', 'UTF-8');
-
- $length = 0x24 + strlen($url);
-
- $header = pack("vv", $record, $length);
- $data = pack("vvvv", $row1, $row2, $col1, $col2);
-
- $this->append($header . $data .
- $unknown1 . $options .
- $url_len . $url);
- return 0;
- }
-
- public function writeUrlExternal($row1, $col1, $row2, $col2, $url)
- {
-
-
- if (preg_match('[^external:\\\\]', $url)) {
- return;
- }
- $record = 0x01B8;
- $length = 0x00000;
-
-
- $url = preg_replace('/^external:/', '', $url);
- $url = preg_replace('/\//', "\\", $url);
-
-
-
-
- $absolute = 0x00;
- if (preg_match('/^[A-Z]:/', $url)) {
- $absolute = 0x02;
- }
- $link_type = 0x01 | $absolute;
-
-
-
- $dir_long = $url;
- if (preg_match("/\#/", $url)) {
- $link_type |= 0x08;
- }
-
- $link_type = pack("V", $link_type);
-
- $up_count = preg_match_all("/\.\.\\\/", $dir_long, $useless);
- $up_count = pack("v", $up_count);
-
- $dir_short = preg_replace("/\.\.\\\/", '', $dir_long) . "\0";
-
- $dir_long = $dir_long . "\0";
-
- $dir_short_len = pack("V", strlen($dir_short));
- $dir_long_len = pack("V", strlen($dir_long));
- $stream_len = pack("V", 0);
-
- $unknown1 = pack("H*", 'D0C9EA79F9BACE118C8200AA004BA90B02000000');
- $unknown2 = pack("H*", '0303000000000000C000000000000046');
- $unknown3 = pack("H*", 'FFFFADDE000000000000000000000000000000000000000');
- $unknown4 = pack("v", 0x03);
-
- $data = pack("vvvv", $row1, $row2, $col1, $col2) .
- $unknown1 .
- $link_type .
- $unknown2 .
- $up_count .
- $dir_short_len.
- $dir_short .
- $unknown3 .
- $stream_len ;
-
- $length = strlen($data);
- $header = pack("vv", $record, $length);
-
- $this->append($header. $data);
- return 0;
- }
-
- private function writeRow($row, $height, $xfIndex, $hidden = false, $level = 0)
- {
- $record = 0x0208;
- $length = 0x0010;
- $colMic = 0x0000;
- $colMac = 0x0000;
- $irwMac = 0x0000;
- $reserved = 0x0000;
- $grbit = 0x0000;
- $ixfe = $xfIndex;
- if ($height < 0) {
- $height = null;
- }
-
- if ($height != null) {
- $miyRw = $height * 20;
- } else {
- $miyRw = 0xff;
- }
-
-
-
-
-
- $grbit |= $level;
- if ($hidden) {
- $grbit |= 0x0030;
- }
- if ($height !== null) {
- $grbit |= 0x0040;
- }
- if ($xfIndex !== 0xF) {
- $grbit |= 0x0080;
- }
- $grbit |= 0x0100;
- $header = pack("vv", $record, $length);
- $data = pack("vvvvvvvv", $row, $colMic, $colMac, $miyRw, $irwMac, $reserved, $grbit, $ixfe);
- $this->append($header.$data);
- }
-
- private function writeDimensions()
- {
- $record = 0x0200;
- $length = 0x000E;
- $data = pack('VVvvv', $this->firstRowIndex, $this->lastRowIndex + 1, $this->firstColumnIndex, $this->lastColumnIndex + 1, 0x0000);
- $header = pack("vv", $record, $length);
- $this->append($header.$data);
- }
-
- private function writeWindow2()
- {
- $record = 0x023E;
- $length = 0x0012;
- $grbit = 0x00B6;
- $rwTop = 0x0000;
- $colLeft = 0x0000;
-
- $fDspFmla = 0;
- $fDspGrid = $this->phpSheet->getShowGridlines() ? 1 : 0;
- $fDspRwCol = $this->phpSheet->getShowRowColHeaders() ? 1 : 0;
- $fFrozen = $this->phpSheet->getFreezePane() ? 1 : 0;
- $fDspZeros = 1;
- $fDefaultHdr = 1;
- $fArabic = $this->phpSheet->getRightToLeft() ? 1 : 0;
- $fDspGuts = $this->outlineOn;
- $fFrozenNoSplit = 0;
-
- $fSelected = ($this->phpSheet === $this->phpSheet->getParent()->getActiveSheet()) ? 1 : 0;
- $fPaged = 1;
- $fPageBreakPreview = $this->phpSheet->getSheetView()->getView() === PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_BREAK_PREVIEW;
- $grbit = $fDspFmla;
- $grbit |= $fDspGrid << 1;
- $grbit |= $fDspRwCol << 2;
- $grbit |= $fFrozen << 3;
- $grbit |= $fDspZeros << 4;
- $grbit |= $fDefaultHdr << 5;
- $grbit |= $fArabic << 6;
- $grbit |= $fDspGuts << 7;
- $grbit |= $fFrozenNoSplit << 8;
- $grbit |= $fSelected << 9;
- $grbit |= $fPaged << 10;
- $grbit |= $fPageBreakPreview << 11;
- $header = pack("vv", $record, $length);
- $data = pack("vvv", $grbit, $rwTop, $colLeft);
-
- $rgbHdr = 0x0040;
- $zoom_factor_page_break = ($fPageBreakPreview ? $this->phpSheet->getSheetView()->getZoomScale() : 0x0000);
- $zoom_factor_normal = $this->phpSheet->getSheetView()->getZoomScaleNormal();
- $data .= pack("vvvvV", $rgbHdr, 0x0000, $zoom_factor_page_break, $zoom_factor_normal, 0x00000000);
- $this->append($header.$data);
- }
-
- private function writeDefaultRowHeight()
- {
- $defaultRowHeight = $this->phpSheet->getDefaultRowDimension()->getRowHeight();
- if ($defaultRowHeight < 0) {
- return;
- }
-
- $defaultRowHeight = (int) 20 * $defaultRowHeight;
- $record = 0x0225;
- $length = 0x0004;
- $header = pack("vv", $record, $length);
- $data = pack("vv", 1, $defaultRowHeight);
- $this->append($header . $data);
- }
-
- private function writeDefcol()
- {
- $defaultColWidth = 8;
- $record = 0x0055;
- $length = 0x0002;
- $header = pack("vv", $record, $length);
- $data = pack("v", $defaultColWidth);
- $this->append($header . $data);
- }
-
- private function writeColinfo($col_array)
- {
- if (isset($col_array[0])) {
- $colFirst = $col_array[0];
- }
- if (isset($col_array[1])) {
- $colLast = $col_array[1];
- }
- if (isset($col_array[2])) {
- $coldx = $col_array[2];
- } else {
- $coldx = 8.43;
- }
- if (isset($col_array[3])) {
- $xfIndex = $col_array[3];
- } else {
- $xfIndex = 15;
- }
- if (isset($col_array[4])) {
- $grbit = $col_array[4];
- } else {
- $grbit = 0;
- }
- if (isset($col_array[5])) {
- $level = $col_array[5];
- } else {
- $level = 0;
- }
- $record = 0x007D;
- $length = 0x000C;
- $coldx *= 256;
- $ixfe = $xfIndex;
- $reserved = 0x0000;
- $level = max(0, min($level, 7));
- $grbit |= $level << 8;
- $header = pack("vv", $record, $length);
- $data = pack("vvvvvv", $colFirst, $colLast, $coldx, $ixfe, $grbit, $reserved);
- $this->append($header.$data);
- }
-
- private function writeSelection()
- {
-
- $selectedCells = $this->phpSheet->getSelectedCells();
- $selectedCells = PHPExcel_Cell::splitRange($this->phpSheet->getSelectedCells());
- $selectedCells = $selectedCells[0];
- if (count($selectedCells) == 2) {
- list($first, $last) = $selectedCells;
- } else {
- $first = $selectedCells[0];
- $last = $selectedCells[0];
- }
- list($colFirst, $rwFirst) = PHPExcel_Cell::coordinateFromString($first);
- $colFirst = PHPExcel_Cell::columnIndexFromString($colFirst) - 1;
- --$rwFirst;
- list($colLast, $rwLast) = PHPExcel_Cell::coordinateFromString($last);
- $colLast = PHPExcel_Cell::columnIndexFromString($colLast) - 1;
- --$rwLast;
-
- $colFirst = min($colFirst, 255);
- $colLast = min($colLast, 255);
- $rwFirst = min($rwFirst, 65535);
- $rwLast = min($rwLast, 65535);
- $record = 0x001D;
- $length = 0x000F;
- $pnn = $this->activePane;
- $rwAct = $rwFirst;
- $colAct = $colFirst;
- $irefAct = 0;
- $cref = 1;
- if (!isset($rwLast)) {
- $rwLast = $rwFirst;
- }
- if (!isset($colLast)) {
- $colLast = $colFirst;
- }
-
- if ($rwFirst > $rwLast) {
- list($rwFirst, $rwLast) = array($rwLast, $rwFirst);
- }
- if ($colFirst > $colLast) {
- list($colFirst, $colLast) = array($colLast, $colFirst);
- }
- $header = pack("vv", $record, $length);
- $data = pack("CvvvvvvCC", $pnn, $rwAct, $colAct, $irefAct, $cref, $rwFirst, $rwLast, $colFirst, $colLast);
- $this->append($header . $data);
- }
-
- private function writeMergedCells()
- {
- $mergeCells = $this->phpSheet->getMergeCells();
- $countMergeCells = count($mergeCells);
- if ($countMergeCells == 0) {
- return;
- }
-
- $maxCountMergeCellsPerRecord = 1027;
-
- $record = 0x00E5;
-
- $i = 0;
-
- $j = 0;
-
- $recordData = '';
-
- foreach ($mergeCells as $mergeCell) {
- ++$i;
- ++$j;
-
- $range = PHPExcel_Cell::splitRange($mergeCell);
- list($first, $last) = $range[0];
- list($firstColumn, $firstRow) = PHPExcel_Cell::coordinateFromString($first);
- list($lastColumn, $lastRow) = PHPExcel_Cell::coordinateFromString($last);
- $recordData .= pack('vvvv', $firstRow - 1, $lastRow - 1, PHPExcel_Cell::columnIndexFromString($firstColumn) - 1, PHPExcel_Cell::columnIndexFromString($lastColumn) - 1);
-
- if ($j == $maxCountMergeCellsPerRecord or $i == $countMergeCells) {
- $recordData = pack('v', $j) . $recordData;
- $length = strlen($recordData);
- $header = pack('vv', $record, $length);
- $this->append($header . $recordData);
-
- $recordData = '';
- $j = 0;
- }
- }
- }
-
- private function writeSheetLayout()
- {
- if (!$this->phpSheet->isTabColorSet()) {
- return;
- }
- $recordData = pack(
- 'vvVVVvv',
- 0x0862,
- 0x0000,
- 0x00000000,
- 0x00000000,
- 0x00000014,
- $this->colors[$this->phpSheet->getTabColor()->getRGB()],
- 0x0000
- );
- $length = strlen($recordData);
- $record = 0x0862;
- $header = pack('vv', $record, $length);
- $this->append($header . $recordData);
- }
-
- private function writeSheetProtection()
- {
-
- $record = 0x0867;
-
- $options = (int) !$this->phpSheet->getProtection()->getObjects()
- | (int) !$this->phpSheet->getProtection()->getScenarios() << 1
- | (int) !$this->phpSheet->getProtection()->getFormatCells() << 2
- | (int) !$this->phpSheet->getProtection()->getFormatColumns() << 3
- | (int) !$this->phpSheet->getProtection()->getFormatRows() << 4
- | (int) !$this->phpSheet->getProtection()->getInsertColumns() << 5
- | (int) !$this->phpSheet->getProtection()->getInsertRows() << 6
- | (int) !$this->phpSheet->getProtection()->getInsertHyperlinks() << 7
- | (int) !$this->phpSheet->getProtection()->getDeleteColumns() << 8
- | (int) !$this->phpSheet->getProtection()->getDeleteRows() << 9
- | (int) !$this->phpSheet->getProtection()->getSelectLockedCells() << 10
- | (int) !$this->phpSheet->getProtection()->getSort() << 11
- | (int) !$this->phpSheet->getProtection()->getAutoFilter() << 12
- | (int) !$this->phpSheet->getProtection()->getPivotTables() << 13
- | (int) !$this->phpSheet->getProtection()->getSelectUnlockedCells() << 14 ;
-
- $recordData = pack(
- 'vVVCVVvv',
- 0x0867,
- 0x0000,
- 0x0000,
- 0x00,
- 0x01000200,
- 0xFFFFFFFF,
- $options,
- 0x0000
- );
- $length = strlen($recordData);
- $header = pack('vv', $record, $length);
- $this->append($header . $recordData);
- }
-
- private function writeRangeProtection()
- {
- foreach ($this->phpSheet->getProtectedCells() as $range => $password) {
-
- $cellRanges = explode(' ', $range);
- $cref = count($cellRanges);
- $recordData = pack(
- 'vvVVvCVvVv',
- 0x0868,
- 0x00,
- 0x0000,
- 0x0000,
- 0x02,
- 0x0,
- 0x0000,
- $cref,
- 0x0000,
- 0x00
- );
- foreach ($cellRanges as $cellRange) {
- $recordData .= $this->writeBIFF8CellRangeAddressFixed($cellRange);
- }
-
- $recordData .= pack(
- 'VV',
- 0x0000,
- hexdec($password)
- );
- $recordData .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong('p' . md5($recordData));
- $length = strlen($recordData);
- $record = 0x0868;
- $header = pack("vv", $record, $length);
- $this->append($header . $recordData);
- }
- }
-
- private function writeExterncount($count)
- {
- $record = 0x0016;
- $length = 0x0002;
- $header = pack("vv", $record, $length);
- $data = pack("v", $count);
- $this->append($header . $data);
- }
-
- private function writeExternsheet($sheetname)
- {
- $record = 0x0017;
-
-
-
- if ($this->phpSheet->getTitle() == $sheetname) {
- $sheetname = '';
- $length = 0x02;
- $cch = 1;
- $rgch = 0x02;
- } else {
- $length = 0x02 + strlen($sheetname);
- $cch = strlen($sheetname);
- $rgch = 0x03;
- }
- $header = pack("vv", $record, $length);
- $data = pack("CC", $cch, $rgch);
- $this->append($header . $data . $sheetname);
- }
-
- private function writePanes()
- {
- $panes = array();
- if ($freezePane = $this->phpSheet->getFreezePane()) {
- list($column, $row) = PHPExcel_Cell::coordinateFromString($freezePane);
- $panes[0] = $row - 1;
- $panes[1] = PHPExcel_Cell::columnIndexFromString($column) - 1;
- } else {
-
- return;
- }
- $y = isset($panes[0]) ? $panes[0] : null;
- $x = isset($panes[1]) ? $panes[1] : null;
- $rwTop = isset($panes[2]) ? $panes[2] : null;
- $colLeft = isset($panes[3]) ? $panes[3] : null;
- if (count($panes) > 4) {
- $pnnAct = $panes[4];
- } else {
- $pnnAct = null;
- }
- $record = 0x0041;
- $length = 0x000A;
-
- if ($this->phpSheet->getFreezePane()) {
-
- if (!isset($rwTop)) {
- $rwTop = $y;
- }
- if (!isset($colLeft)) {
- $colLeft = $x;
- }
- } else {
-
- if (!isset($rwTop)) {
- $rwTop = 0;
- }
- if (!isset($colLeft)) {
- $colLeft = 0;
- }
-
-
-
-
-
- $y = 20*$y + 255;
- $x = 113.879*$x + 390;
- }
-
-
-
- if (!isset($pnnAct)) {
- if ($x != 0 && $y != 0) {
- $pnnAct = 0;
- }
- if ($x != 0 && $y == 0) {
- $pnnAct = 1;
- }
- if ($x == 0 && $y != 0) {
- $pnnAct = 2;
- }
- if ($x == 0 && $y == 0) {
- $pnnAct = 3;
- }
- }
- $this->activePane = $pnnAct;
- $header = pack("vv", $record, $length);
- $data = pack("vvvvv", $x, $y, $rwTop, $colLeft, $pnnAct);
- $this->append($header . $data);
- }
-
- private function writeSetup()
- {
- $record = 0x00A1;
- $length = 0x0022;
- $iPaperSize = $this->phpSheet->getPageSetup()->getPaperSize();
- $iScale = $this->phpSheet->getPageSetup()->getScale() ?
- $this->phpSheet->getPageSetup()->getScale() : 100;
- $iPageStart = 0x01;
- $iFitWidth = (int) $this->phpSheet->getPageSetup()->getFitToWidth();
- $iFitHeight = (int) $this->phpSheet->getPageSetup()->getFitToHeight();
- $grbit = 0x00;
- $iRes = 0x0258;
- $iVRes = 0x0258;
- $numHdr = $this->phpSheet->getPageMargins()->getHeader();
- $numFtr = $this->phpSheet->getPageMargins()->getFooter();
- $iCopies = 0x01;
- $fLeftToRight = 0x0;
-
- $fLandscape = ($this->phpSheet->getPageSetup()->getOrientation() == PHPExcel_Worksheet_PageSetup::ORIENTATION_LANDSCAPE) ?
- 0x0 : 0x1;
- $fNoPls = 0x0;
- $fNoColor = 0x0;
- $fDraft = 0x0;
- $fNotes = 0x0;
- $fNoOrient = 0x0;
- $fUsePage = 0x0;
- $grbit = $fLeftToRight;
- $grbit |= $fLandscape << 1;
- $grbit |= $fNoPls << 2;
- $grbit |= $fNoColor << 3;
- $grbit |= $fDraft << 4;
- $grbit |= $fNotes << 5;
- $grbit |= $fNoOrient << 6;
- $grbit |= $fUsePage << 7;
- $numHdr = pack("d", $numHdr);
- $numFtr = pack("d", $numFtr);
- if (self::getByteOrder()) {
- $numHdr = strrev($numHdr);
- $numFtr = strrev($numFtr);
- }
- $header = pack("vv", $record, $length);
- $data1 = pack("vvvvvvvv", $iPaperSize, $iScale, $iPageStart, $iFitWidth, $iFitHeight, $grbit, $iRes, $iVRes);
- $data2 = $numHdr.$numFtr;
- $data3 = pack("v", $iCopies);
- $this->append($header . $data1 . $data2 . $data3);
- }
-
- private function writeHeader()
- {
- $record = 0x0014;
-
- $recordData = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($this->phpSheet->getHeaderFooter()->getOddHeader());
- $length = strlen($recordData);
- $header = pack("vv", $record, $length);
- $this->append($header . $recordData);
- }
-
- private function writeFooter()
- {
- $record = 0x0015;
-
- $recordData = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($this->phpSheet->getHeaderFooter()->getOddFooter());
- $length = strlen($recordData);
- $header = pack("vv", $record, $length);
- $this->append($header . $recordData);
- }
-
- private function writeHcenter()
- {
- $record = 0x0083;
- $length = 0x0002;
- $fHCenter = $this->phpSheet->getPageSetup()->getHorizontalCentered() ? 1 : 0;
- $header = pack("vv", $record, $length);
- $data = pack("v", $fHCenter);
- $this->append($header.$data);
- }
-
- private function writeVcenter()
- {
- $record = 0x0084;
- $length = 0x0002;
- $fVCenter = $this->phpSheet->getPageSetup()->getVerticalCentered() ? 1 : 0;
- $header = pack("vv", $record, $length);
- $data = pack("v", $fVCenter);
- $this->append($header . $data);
- }
-
- private function writeMarginLeft()
- {
- $record = 0x0026;
- $length = 0x0008;
- $margin = $this->phpSheet->getPageMargins()->getLeft();
- $header = pack("vv", $record, $length);
- $data = pack("d", $margin);
- if (self::getByteOrder()) {
- $data = strrev($data);
- }
- $this->append($header . $data);
- }
-
- private function writeMarginRight()
- {
- $record = 0x0027;
- $length = 0x0008;
- $margin = $this->phpSheet->getPageMargins()->getRight();
- $header = pack("vv", $record, $length);
- $data = pack("d", $margin);
- if (self::getByteOrder()) {
- $data = strrev($data);
- }
- $this->append($header . $data);
- }
-
- private function writeMarginTop()
- {
- $record = 0x0028;
- $length = 0x0008;
- $margin = $this->phpSheet->getPageMargins()->getTop();
- $header = pack("vv", $record, $length);
- $data = pack("d", $margin);
- if (self::getByteOrder()) {
- $data = strrev($data);
- }
- $this->append($header . $data);
- }
-
- private function writeMarginBottom()
- {
- $record = 0x0029;
- $length = 0x0008;
- $margin = $this->phpSheet->getPageMargins()->getBottom();
- $header = pack("vv", $record, $length);
- $data = pack("d", $margin);
- if (self::getByteOrder()) {
- $data = strrev($data);
- }
- $this->append($header . $data);
- }
-
- private function writePrintHeaders()
- {
- $record = 0x002a;
- $length = 0x0002;
- $fPrintRwCol = $this->_print_headers;
- $header = pack("vv", $record, $length);
- $data = pack("v", $fPrintRwCol);
- $this->append($header . $data);
- }
-
- private function writePrintGridlines()
- {
- $record = 0x002b;
- $length = 0x0002;
- $fPrintGrid = $this->phpSheet->getPrintGridlines() ? 1 : 0;
- $header = pack("vv", $record, $length);
- $data = pack("v", $fPrintGrid);
- $this->append($header . $data);
- }
-
- private function writeGridset()
- {
- $record = 0x0082;
- $length = 0x0002;
- $fGridSet = !$this->phpSheet->getPrintGridlines();
- $header = pack("vv", $record, $length);
- $data = pack("v", $fGridSet);
- $this->append($header . $data);
- }
-
- private function writeAutoFilterInfo()
- {
- $record = 0x009D;
- $length = 0x0002;
- $rangeBounds = PHPExcel_Cell::rangeBoundaries($this->phpSheet->getAutoFilter()->getRange());
- $iNumFilters = 1 + $rangeBounds[1][0] - $rangeBounds[0][0];
- $header = pack("vv", $record, $length);
- $data = pack("v", $iNumFilters);
- $this->append($header . $data);
- }
-
- private function writeGuts()
- {
- $record = 0x0080;
- $length = 0x0008;
- $dxRwGut = 0x0000;
- $dxColGut = 0x0000;
-
- $maxRowOutlineLevel = 0;
- foreach ($this->phpSheet->getRowDimensions() as $rowDimension) {
- $maxRowOutlineLevel = max($maxRowOutlineLevel, $rowDimension->getOutlineLevel());
- }
- $col_level = 0;
-
-
- $colcount = count($this->columnInfo);
- for ($i = 0; $i < $colcount; ++$i) {
- $col_level = max($this->columnInfo[$i][5], $col_level);
- }
-
- $col_level = max(0, min($col_level, 7));
-
- if ($maxRowOutlineLevel) {
- ++$maxRowOutlineLevel;
- }
- if ($col_level) {
- ++$col_level;
- }
- $header = pack("vv", $record, $length);
- $data = pack("vvvv", $dxRwGut, $dxColGut, $maxRowOutlineLevel, $col_level);
- $this->append($header.$data);
- }
-
- private function writeWsbool()
- {
- $record = 0x0081;
- $length = 0x0002;
- $grbit = 0x0000;
-
-
-
-
- $grbit |= 0x0001;
- if ($this->outlineStyle) {
- $grbit |= 0x0020;
- }
- if ($this->phpSheet->getShowSummaryBelow()) {
- $grbit |= 0x0040;
- }
- if ($this->phpSheet->getShowSummaryRight()) {
- $grbit |= 0x0080;
- }
- if ($this->phpSheet->getPageSetup()->getFitToPage()) {
- $grbit |= 0x0100;
- }
- if ($this->outlineOn) {
- $grbit |= 0x0400;
- }
- $header = pack("vv", $record, $length);
- $data = pack("v", $grbit);
- $this->append($header . $data);
- }
-
- private function writeBreaks()
- {
-
- $vbreaks = array();
- $hbreaks = array();
- foreach ($this->phpSheet->getBreaks() as $cell => $breakType) {
-
- $coordinates = PHPExcel_Cell::coordinateFromString($cell);
-
- switch ($breakType) {
- case PHPExcel_Worksheet::BREAK_COLUMN:
-
- $vbreaks[] = PHPExcel_Cell::columnIndexFromString($coordinates[0]) - 1;
- break;
- case PHPExcel_Worksheet::BREAK_ROW:
-
- $hbreaks[] = $coordinates[1];
- break;
- case PHPExcel_Worksheet::BREAK_NONE:
- default:
-
- break;
- }
- }
-
- if (!empty($hbreaks)) {
-
- sort($hbreaks, SORT_NUMERIC);
- if ($hbreaks[0] == 0) {
- array_shift($hbreaks);
- }
- $record = 0x001b;
- $cbrk = count($hbreaks);
- $length = 2 + 6 * $cbrk;
- $header = pack("vv", $record, $length);
- $data = pack("v", $cbrk);
-
- foreach ($hbreaks as $hbreak) {
- $data .= pack("vvv", $hbreak, 0x0000, 0x00ff);
- }
- $this->append($header . $data);
- }
-
- if (!empty($vbreaks)) {
-
-
- $vbreaks = array_slice($vbreaks, 0, 1000);
-
- sort($vbreaks, SORT_NUMERIC);
- if ($vbreaks[0] == 0) {
- array_shift($vbreaks);
- }
- $record = 0x001a;
- $cbrk = count($vbreaks);
- $length = 2 + 6 * $cbrk;
- $header = pack("vv", $record, $length);
- $data = pack("v", $cbrk);
-
- foreach ($vbreaks as $vbreak) {
- $data .= pack("vvv", $vbreak, 0x0000, 0xffff);
- }
- $this->append($header . $data);
- }
- }
-
- private function writeProtect()
- {
-
- if (!$this->phpSheet->getProtection()->getSheet()) {
- return;
- }
- $record = 0x0012;
- $length = 0x0002;
- $fLock = 1;
- $header = pack("vv", $record, $length);
- $data = pack("v", $fLock);
- $this->append($header.$data);
- }
-
- private function writeScenProtect()
- {
-
- if (!$this->phpSheet->getProtection()->getSheet()) {
- return;
- }
-
- if (!$this->phpSheet->getProtection()->getScenarios()) {
- return;
- }
- $record = 0x00DD;
- $length = 0x0002;
- $header = pack('vv', $record, $length);
- $data = pack('v', 1);
- $this->append($header . $data);
- }
-
- private function writeObjectProtect()
- {
-
- if (!$this->phpSheet->getProtection()->getSheet()) {
- return;
- }
-
- if (!$this->phpSheet->getProtection()->getObjects()) {
- return;
- }
- $record = 0x0063;
- $length = 0x0002;
- $header = pack('vv', $record, $length);
- $data = pack('v', 1);
- $this->append($header . $data);
- }
-
- private function writePassword()
- {
-
- if (!$this->phpSheet->getProtection()->getSheet() || !$this->phpSheet->getProtection()->getPassword()) {
- return;
- }
- $record = 0x0013;
- $length = 0x0002;
- $wPassword = hexdec($this->phpSheet->getProtection()->getPassword());
- $header = pack("vv", $record, $length);
- $data = pack("v", $wPassword);
- $this->append($header . $data);
- }
-
- public function insertBitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1)
- {
- $bitmap_array = (is_resource($bitmap) ? $this->processBitmapGd($bitmap) : $this->processBitmap($bitmap));
- list($width, $height, $size, $data) = $bitmap_array;
-
- $width *= $scale_x;
- $height *= $scale_y;
-
- $this->positionImage($col, $row, $x, $y, $width, $height);
-
- $record = 0x007f;
- $length = 8 + $size;
- $cf = 0x09;
- $env = 0x01;
- $lcb = $size;
- $header = pack("vvvvV", $record, $length, $cf, $env, $lcb);
- $this->append($header.$data);
- }
-
- public function positionImage($col_start, $row_start, $x1, $y1, $width, $height)
- {
-
- $col_end = $col_start;
- $row_end = $row_start;
-
- if ($x1 >= PHPExcel_Shared_Excel5::sizeCol($this->phpSheet, PHPExcel_Cell::stringFromColumnIndex($col_start))) {
- $x1 = 0;
- }
- if ($y1 >= PHPExcel_Shared_Excel5::sizeRow($this->phpSheet, $row_start + 1)) {
- $y1 = 0;
- }
- $width = $width + $x1 -1;
- $height = $height + $y1 -1;
-
- while ($width >= PHPExcel_Shared_Excel5::sizeCol($this->phpSheet, PHPExcel_Cell::stringFromColumnIndex($col_end))) {
- $width -= PHPExcel_Shared_Excel5::sizeCol($this->phpSheet, PHPExcel_Cell::stringFromColumnIndex($col_end));
- ++$col_end;
- }
-
- while ($height >= PHPExcel_Shared_Excel5::sizeRow($this->phpSheet, $row_end + 1)) {
- $height -= PHPExcel_Shared_Excel5::sizeRow($this->phpSheet, $row_end + 1);
- ++$row_end;
- }
-
-
-
- if (PHPExcel_Shared_Excel5::sizeCol($this->phpSheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) == 0) {
- return;
- }
- if (PHPExcel_Shared_Excel5::sizeCol($this->phpSheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) == 0) {
- return;
- }
- if (PHPExcel_Shared_Excel5::sizeRow($this->phpSheet, $row_start + 1) == 0) {
- return;
- }
- if (PHPExcel_Shared_Excel5::sizeRow($this->phpSheet, $row_end + 1) == 0) {
- return;
- }
-
- $x1 = $x1 / PHPExcel_Shared_Excel5::sizeCol($this->phpSheet, PHPExcel_Cell::stringFromColumnIndex($col_start)) * 1024;
- $y1 = $y1 / PHPExcel_Shared_Excel5::sizeRow($this->phpSheet, $row_start + 1) * 256;
- $x2 = $width / PHPExcel_Shared_Excel5::sizeCol($this->phpSheet, PHPExcel_Cell::stringFromColumnIndex($col_end)) * 1024;
- $y2 = $height / PHPExcel_Shared_Excel5::sizeRow($this->phpSheet, $row_end + 1) * 256;
- $this->writeObjPicture($col_start, $x1, $row_start, $y1, $col_end, $x2, $row_end, $y2);
- }
-
- private function writeObjPicture($colL, $dxL, $rwT, $dyT, $colR, $dxR, $rwB, $dyB)
- {
- $record = 0x005d;
- $length = 0x003c;
- $cObj = 0x0001;
- $OT = 0x0008;
- $id = 0x0001;
- $grbit = 0x0614;
- $cbMacro = 0x0000;
- $Reserved1 = 0x0000;
- $Reserved2 = 0x0000;
- $icvBack = 0x09;
- $icvFore = 0x09;
- $fls = 0x00;
- $fAuto = 0x00;
- $icv = 0x08;
- $lns = 0xff;
- $lnw = 0x01;
- $fAutoB = 0x00;
- $frs = 0x0000;
- $cf = 0x0009;
- $Reserved3 = 0x0000;
- $cbPictFmla = 0x0000;
- $Reserved4 = 0x0000;
- $grbit2 = 0x0001;
- $Reserved5 = 0x0000;
- $header = pack("vv", $record, $length);
- $data = pack("V", $cObj);
- $data .= pack("v", $OT);
- $data .= pack("v", $id);
- $data .= pack("v", $grbit);
- $data .= pack("v", $colL);
- $data .= pack("v", $dxL);
- $data .= pack("v", $rwT);
- $data .= pack("v", $dyT);
- $data .= pack("v", $colR);
- $data .= pack("v", $dxR);
- $data .= pack("v", $rwB);
- $data .= pack("v", $dyB);
- $data .= pack("v", $cbMacro);
- $data .= pack("V", $Reserved1);
- $data .= pack("v", $Reserved2);
- $data .= pack("C", $icvBack);
- $data .= pack("C", $icvFore);
- $data .= pack("C", $fls);
- $data .= pack("C", $fAuto);
- $data .= pack("C", $icv);
- $data .= pack("C", $lns);
- $data .= pack("C", $lnw);
- $data .= pack("C", $fAutoB);
- $data .= pack("v", $frs);
- $data .= pack("V", $cf);
- $data .= pack("v", $Reserved3);
- $data .= pack("v", $cbPictFmla);
- $data .= pack("v", $Reserved4);
- $data .= pack("v", $grbit2);
- $data .= pack("V", $Reserved5);
- $this->append($header . $data);
- }
-
- public function processBitmapGd($image)
- {
- $width = imagesx($image);
- $height = imagesy($image);
- $data = pack("Vvvvv", 0x000c, $width, $height, 0x01, 0x18);
- for ($j=$height; $j--;) {
- for ($i=0; $i < $width; ++$i) {
- $color = imagecolorsforindex($image, imagecolorat($image, $i, $j));
- foreach (array("red", "green", "blue") as $key) {
- $color[$key] = $color[$key] + round((255 - $color[$key]) * $color["alpha"] / 127);
- }
- $data .= chr($color["blue"]) . chr($color["green"]) . chr($color["red"]);
- }
- if (3*$width % 4) {
- $data .= str_repeat("\x00", 4 - 3*$width % 4);
- }
- }
- return array($width, $height, strlen($data), $data);
- }
-
- public function processBitmap($bitmap)
- {
-
- $bmp_fd = @fopen($bitmap, "rb");
- if (!$bmp_fd) {
- throw new PHPExcel_Writer_Exception("Couldn't import $bitmap");
- }
-
- $data = fread($bmp_fd, filesize($bitmap));
-
- if (strlen($data) <= 0x36) {
- throw new PHPExcel_Writer_Exception("$bitmap doesn't contain enough data.\n");
- }
-
- $identity = unpack("A2ident", $data);
- if ($identity['ident'] != "BM") {
- throw new PHPExcel_Writer_Exception("$bitmap doesn't appear to be a valid bitmap image.\n");
- }
-
- $data = substr($data, 2);
-
-
-
- $size_array = unpack("Vsa", substr($data, 0, 4));
- $size = $size_array['sa'];
- $data = substr($data, 4);
- $size -= 0x36;
- $size += 0x0C;
-
- $data = substr($data, 12);
-
- $width_and_height = unpack("V2", substr($data, 0, 8));
- $width = $width_and_height[1];
- $height = $width_and_height[2];
- $data = substr($data, 8);
- if ($width > 0xFFFF) {
- throw new PHPExcel_Writer_Exception("$bitmap: largest image width supported is 65k.\n");
- }
- if ($height > 0xFFFF) {
- throw new PHPExcel_Writer_Exception("$bitmap: largest image height supported is 65k.\n");
- }
-
- $planes_and_bitcount = unpack("v2", substr($data, 0, 4));
- $data = substr($data, 4);
- if ($planes_and_bitcount[2] != 24) {
- throw new PHPExcel_Writer_Exception("$bitmap isn't a 24bit true color bitmap.\n");
- }
- if ($planes_and_bitcount[1] != 1) {
- throw new PHPExcel_Writer_Exception("$bitmap: only 1 plane supported in bitmap image.\n");
- }
-
- $compression = unpack("Vcomp", substr($data, 0, 4));
- $data = substr($data, 4);
-
- if ($compression['comp'] != 0) {
- throw new PHPExcel_Writer_Exception("$bitmap: compression not supported in bitmap image.\n");
- }
-
- $data = substr($data, 20);
-
- $header = pack("Vvvvv", 0x000c, $width, $height, 0x01, 0x18);
- $data = $header . $data;
- return (array($width, $height, $size, $data));
- }
-
- private function writeZoom()
- {
-
- if ($this->phpSheet->getSheetView()->getZoomScale() == 100) {
- return;
- }
- $record = 0x00A0;
- $length = 0x0004;
- $header = pack("vv", $record, $length);
- $data = pack("vv", $this->phpSheet->getSheetView()->getZoomScale(), 100);
- $this->append($header . $data);
- }
-
- public function getEscher()
- {
- return $this->escher;
- }
-
- public function setEscher(PHPExcel_Shared_Escher $pValue = null)
- {
- $this->escher = $pValue;
- }
-
- private function writeMsoDrawing()
- {
-
- if (isset($this->escher)) {
- $writer = new PHPExcel_Writer_Excel5_Escher($this->escher);
- $data = $writer->close();
- $spOffsets = $writer->getSpOffsets();
- $spTypes = $writer->getSpTypes();
-
-
- $spOffsets[0] = 0;
- $nm = count($spOffsets) - 1;
- for ($i = 1; $i <= $nm; ++$i) {
-
- $record = 0x00EC;
-
- $dataChunk = substr($data, $spOffsets[$i -1], $spOffsets[$i] - $spOffsets[$i - 1]);
- $length = strlen($dataChunk);
- $header = pack("vv", $record, $length);
- $this->append($header . $dataChunk);
-
- $record = 0x005D;
- $objData = '';
-
- if ($spTypes[$i] == 0x00C9) {
-
- $objData .=
- pack(
- 'vvvvvVVV',
- 0x0015,
- 0x0012,
- 0x0014,
- $i,
- 0x2101,
- 0,
- 0,
- 0
- );
-
- $objData .= pack('vv', 0x00C, 0x0014);
- $objData .= pack('H*', '0000000000000000640001000A00000010000100');
-
- $objData .= pack('vv', 0x0013, 0x1FEE);
- $objData .= pack('H*', '00000000010001030000020008005700');
- } else {
-
- $objData .=
- pack(
- 'vvvvvVVV',
- 0x0015,
- 0x0012,
- 0x0008,
- $i,
- 0x6011,
- 0,
- 0,
- 0
- );
- }
-
- $objData .=
- pack(
- 'vv',
- 0x0000,
- 0x0000
- );
- $length = strlen($objData);
- $header = pack('vv', $record, $length);
- $this->append($header . $objData);
- }
- }
- }
-
- private function writeDataValidity()
- {
-
- $dataValidationCollection = $this->phpSheet->getDataValidationCollection();
-
- if (!empty($dataValidationCollection)) {
-
- $record = 0x01B2;
- $length = 0x0012;
- $grbit = 0x0000;
- $horPos = 0x00000000;
- $verPos = 0x00000000;
- $objId = 0xFFFFFFFF;
- $header = pack('vv', $record, $length);
- $data = pack('vVVVV', $grbit, $horPos, $verPos, $objId, count($dataValidationCollection));
- $this->append($header.$data);
-
- $record = 0x01BE;
- foreach ($dataValidationCollection as $cellCoordinate => $dataValidation) {
-
- $data = '';
-
- $options = 0x00000000;
-
- $type = $dataValidation->getType();
- switch ($type) {
- case PHPExcel_Cell_DataValidation::TYPE_NONE:
- $type = 0x00;
- break;
- case PHPExcel_Cell_DataValidation::TYPE_WHOLE:
- $type = 0x01;
- break;
- case PHPExcel_Cell_DataValidation::TYPE_DECIMAL:
- $type = 0x02;
- break;
- case PHPExcel_Cell_DataValidation::TYPE_LIST:
- $type = 0x03;
- break;
- case PHPExcel_Cell_DataValidation::TYPE_DATE:
- $type = 0x04;
- break;
- case PHPExcel_Cell_DataValidation::TYPE_TIME:
- $type = 0x05;
- break;
- case PHPExcel_Cell_DataValidation::TYPE_TEXTLENGTH:
- $type = 0x06;
- break;
- case PHPExcel_Cell_DataValidation::TYPE_CUSTOM:
- $type = 0x07;
- break;
- }
- $options |= $type << 0;
-
- $errorStyle = $dataValidation->getType();
- switch ($errorStyle) {
- case PHPExcel_Cell_DataValidation::STYLE_STOP:
- $errorStyle = 0x00;
- break;
- case PHPExcel_Cell_DataValidation::STYLE_WARNING:
- $errorStyle = 0x01;
- break;
- case PHPExcel_Cell_DataValidation::STYLE_INFORMATION:
- $errorStyle = 0x02;
- break;
- }
- $options |= $errorStyle << 4;
-
- if ($type == 0x03 && preg_match('/^\".*\"$/', $dataValidation->getFormula1())) {
- $options |= 0x01 << 7;
- }
-
- $options |= $dataValidation->getAllowBlank() << 8;
-
- $options |= (!$dataValidation->getShowDropDown()) << 9;
-
- $options |= $dataValidation->getShowInputMessage() << 18;
-
- $options |= $dataValidation->getShowErrorMessage() << 19;
-
- $operator = $dataValidation->getOperator();
- switch ($operator) {
- case PHPExcel_Cell_DataValidation::OPERATOR_BETWEEN:
- $operator = 0x00;
- break;
- case PHPExcel_Cell_DataValidation::OPERATOR_NOTBETWEEN:
- $operator = 0x01;
- break;
- case PHPExcel_Cell_DataValidation::OPERATOR_EQUAL:
- $operator = 0x02;
- break;
- case PHPExcel_Cell_DataValidation::OPERATOR_NOTEQUAL:
- $operator = 0x03;
- break;
- case PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHAN:
- $operator = 0x04;
- break;
- case PHPExcel_Cell_DataValidation::OPERATOR_LESSTHAN:
- $operator = 0x05;
- break;
- case PHPExcel_Cell_DataValidation::OPERATOR_GREATERTHANOREQUAL:
- $operator = 0x06;
- break;
- case PHPExcel_Cell_DataValidation::OPERATOR_LESSTHANOREQUAL:
- $operator = 0x07;
- break;
- }
- $options |= $operator << 20;
- $data = pack('V', $options);
-
- $promptTitle = $dataValidation->getPromptTitle() !== '' ?
- $dataValidation->getPromptTitle() : chr(0);
- $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($promptTitle);
-
- $errorTitle = $dataValidation->getErrorTitle() !== '' ?
- $dataValidation->getErrorTitle() : chr(0);
- $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($errorTitle);
-
- $prompt = $dataValidation->getPrompt() !== '' ?
- $dataValidation->getPrompt() : chr(0);
- $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($prompt);
-
- $error = $dataValidation->getError() !== '' ?
- $dataValidation->getError() : chr(0);
- $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($error);
-
- try {
- $formula1 = $dataValidation->getFormula1();
- if ($type == 0x03) {
- $formula1 = str_replace(',', chr(0), $formula1);
- }
- $this->parser->parse($formula1);
- $formula1 = $this->parser->toReversePolish();
- $sz1 = strlen($formula1);
- } catch (PHPExcel_Exception $e) {
- $sz1 = 0;
- $formula1 = '';
- }
- $data .= pack('vv', $sz1, 0x0000);
- $data .= $formula1;
-
- try {
- $formula2 = $dataValidation->getFormula2();
- if ($formula2 === '') {
- throw new PHPExcel_Writer_Exception('No formula2');
- }
- $this->parser->parse($formula2);
- $formula2 = $this->parser->toReversePolish();
- $sz2 = strlen($formula2);
- } catch (PHPExcel_Exception $e) {
- $sz2 = 0;
- $formula2 = '';
- }
- $data .= pack('vv', $sz2, 0x0000);
- $data .= $formula2;
-
- $data .= pack('v', 0x0001);
- $data .= $this->writeBIFF8CellRangeAddressFixed($cellCoordinate);
- $length = strlen($data);
- $header = pack("vv", $record, $length);
- $this->append($header . $data);
- }
- }
- }
-
- private static function mapErrorCode($errorCode)
- {
- switch ($errorCode) {
- case '#NULL!':
- return 0x00;
- case '#DIV/0!':
- return 0x07;
- case '#VALUE!':
- return 0x0F;
- case '#REF!':
- return 0x17;
- case '#NAME?':
- return 0x1D;
- case '#NUM!':
- return 0x24;
- case '#N/A':
- return 0x2A;
- }
- return 0;
- }
-
- private function writePageLayoutView()
- {
- $record = 0x088B;
- $length = 0x0010;
- $rt = 0x088B;
- $grbitFrt = 0x0000;
- $reserved = 0x0000000000000000;
- $wScalvePLV = $this->phpSheet->getSheetView()->getZoomScale();
-
- if ($this->phpSheet->getSheetView()->getView() == PHPExcel_Worksheet_SheetView::SHEETVIEW_PAGE_LAYOUT) {
- $fPageLayoutView = 1;
- } else {
- $fPageLayoutView = 0;
- }
- $fRulerVisible = 0;
- $fWhitespaceHidden = 0;
- $grbit = $fPageLayoutView;
- $grbit |= $fRulerVisible << 1;
- $grbit |= $fWhitespaceHidden << 3;
- $header = pack("vv", $record, $length);
- $data = pack("vvVVvv", $rt, $grbitFrt, 0x00000000, 0x00000000, $wScalvePLV, $grbit);
- $this->append($header . $data);
- }
-
- private function writeCFRule(PHPExcel_Style_Conditional $conditional)
- {
- $record = 0x01B1;
-
-
- if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_EXPRESSION) {
- $type = 0x02;
- $operatorType = 0x00;
- } elseif ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS) {
- $type = 0x01;
- switch ($conditional->getOperatorType()) {
- case PHPExcel_Style_Conditional::OPERATOR_NONE:
- $operatorType = 0x00;
- break;
- case PHPExcel_Style_Conditional::OPERATOR_EQUAL:
- $operatorType = 0x03;
- break;
- case PHPExcel_Style_Conditional::OPERATOR_GREATERTHAN:
- $operatorType = 0x05;
- break;
- case PHPExcel_Style_Conditional::OPERATOR_GREATERTHANOREQUAL:
- $operatorType = 0x07;
- break;
- case PHPExcel_Style_Conditional::OPERATOR_LESSTHAN:
- $operatorType = 0x06;
- break;
- case PHPExcel_Style_Conditional::OPERATOR_LESSTHANOREQUAL:
- $operatorType = 0x08;
- break;
- case PHPExcel_Style_Conditional::OPERATOR_NOTEQUAL:
- $operatorType = 0x04;
- break;
- case PHPExcel_Style_Conditional::OPERATOR_BETWEEN:
- $operatorType = 0x01;
- break;
-
- }
- }
-
-
- $arrConditions = $conditional->getConditions();
- $numConditions = sizeof($arrConditions);
- if ($numConditions == 1) {
- $szValue1 = ($arrConditions[0] <= 65535 ? 3 : 0x0000);
- $szValue2 = 0x0000;
- $operand1 = pack('Cv', 0x1E, $arrConditions[0]);
- $operand2 = null;
- } elseif ($numConditions == 2 && ($conditional->getOperatorType() == PHPExcel_Style_Conditional::OPERATOR_BETWEEN)) {
- $szValue1 = ($arrConditions[0] <= 65535 ? 3 : 0x0000);
- $szValue2 = ($arrConditions[1] <= 65535 ? 3 : 0x0000);
- $operand1 = pack('Cv', 0x1E, $arrConditions[0]);
- $operand2 = pack('Cv', 0x1E, $arrConditions[1]);
- } else {
- $szValue1 = 0x0000;
- $szValue2 = 0x0000;
- $operand1 = null;
- $operand2 = null;
- }
-
-
- $bAlignHz = ($conditional->getStyle()->getAlignment()->getHorizontal() == null ? 1 : 0);
- $bAlignVt = ($conditional->getStyle()->getAlignment()->getVertical() == null ? 1 : 0);
- $bAlignWrapTx = ($conditional->getStyle()->getAlignment()->getWrapText() == false ? 1 : 0);
- $bTxRotation = ($conditional->getStyle()->getAlignment()->getTextRotation() == null ? 1 : 0);
- $bIndent = ($conditional->getStyle()->getAlignment()->getIndent() == 0 ? 1 : 0);
- $bShrinkToFit = ($conditional->getStyle()->getAlignment()->getShrinkToFit() == false ? 1 : 0);
- if ($bAlignHz == 0 || $bAlignVt == 0 || $bAlignWrapTx == 0 || $bTxRotation == 0 || $bIndent == 0 || $bShrinkToFit == 0) {
- $bFormatAlign = 1;
- } else {
- $bFormatAlign = 0;
- }
-
- $bProtLocked = ($conditional->getStyle()->getProtection()->getLocked() == null ? 1 : 0);
- $bProtHidden = ($conditional->getStyle()->getProtection()->getHidden() == null ? 1 : 0);
- if ($bProtLocked == 0 || $bProtHidden == 0) {
- $bFormatProt = 1;
- } else {
- $bFormatProt = 0;
- }
-
- $bBorderLeft = ($conditional->getStyle()->getBorders()->getLeft()->getColor()->getARGB() == PHPExcel_Style_Color::COLOR_BLACK
- && $conditional->getStyle()->getBorders()->getLeft()->getBorderStyle() == PHPExcel_Style_Border::BORDER_NONE ? 1 : 0);
- $bBorderRight = ($conditional->getStyle()->getBorders()->getRight()->getColor()->getARGB() == PHPExcel_Style_Color::COLOR_BLACK
- && $conditional->getStyle()->getBorders()->getRight()->getBorderStyle() == PHPExcel_Style_Border::BORDER_NONE ? 1 : 0);
- $bBorderTop = ($conditional->getStyle()->getBorders()->getTop()->getColor()->getARGB() == PHPExcel_Style_Color::COLOR_BLACK
- && $conditional->getStyle()->getBorders()->getTop()->getBorderStyle() == PHPExcel_Style_Border::BORDER_NONE ? 1 : 0);
- $bBorderBottom = ($conditional->getStyle()->getBorders()->getBottom()->getColor()->getARGB() == PHPExcel_Style_Color::COLOR_BLACK
- && $conditional->getStyle()->getBorders()->getBottom()->getBorderStyle() == PHPExcel_Style_Border::BORDER_NONE ? 1 : 0);
- if ($bBorderLeft == 0 || $bBorderRight == 0 || $bBorderTop == 0 || $bBorderBottom == 0) {
- $bFormatBorder = 1;
- } else {
- $bFormatBorder = 0;
- }
-
- $bFillStyle = ($conditional->getStyle()->getFill()->getFillType() == null ? 0 : 1);
- $bFillColor = ($conditional->getStyle()->getFill()->getStartColor()->getARGB() == null ? 0 : 1);
- $bFillColorBg = ($conditional->getStyle()->getFill()->getEndColor()->getARGB() == null ? 0 : 1);
- if ($bFillStyle == 0 || $bFillColor == 0 || $bFillColorBg == 0) {
- $bFormatFill = 1;
- } else {
- $bFormatFill = 0;
- }
-
- if ($conditional->getStyle()->getFont()->getName() != null
- || $conditional->getStyle()->getFont()->getSize() != null
- || $conditional->getStyle()->getFont()->getBold() != null
- || $conditional->getStyle()->getFont()->getItalic() != null
- || $conditional->getStyle()->getFont()->getSuperScript() != null
- || $conditional->getStyle()->getFont()->getSubScript() != null
- || $conditional->getStyle()->getFont()->getUnderline() != null
- || $conditional->getStyle()->getFont()->getStrikethrough() != null
- || $conditional->getStyle()->getFont()->getColor()->getARGB() != null) {
- $bFormatFont = 1;
- } else {
- $bFormatFont = 0;
- }
-
- $flags = 0;
- $flags |= (1 == $bAlignHz ? 0x00000001 : 0);
- $flags |= (1 == $bAlignVt ? 0x00000002 : 0);
- $flags |= (1 == $bAlignWrapTx ? 0x00000004 : 0);
- $flags |= (1 == $bTxRotation ? 0x00000008 : 0);
-
- $flags |= (1 == 1 ? 0x00000010 : 0);
- $flags |= (1 == $bIndent ? 0x00000020 : 0);
- $flags |= (1 == $bShrinkToFit ? 0x00000040 : 0);
-
- $flags |= (1 == 1 ? 0x00000080 : 0);
-
- $flags |= (1 == $bProtLocked ? 0x00000100 : 0);
- $flags |= (1 == $bProtHidden ? 0x00000200 : 0);
-
- $flags |= (1 == $bBorderLeft ? 0x00000400 : 0);
- $flags |= (1 == $bBorderRight ? 0x00000800 : 0);
- $flags |= (1 == $bBorderTop ? 0x00001000 : 0);
- $flags |= (1 == $bBorderBottom ? 0x00002000 : 0);
- $flags |= (1 == 1 ? 0x00004000 : 0);
- $flags |= (1 == 1 ? 0x00008000 : 0);
-
- $flags |= (1 == $bFillStyle ? 0x00010000 : 0);
- $flags |= (1 == $bFillColor ? 0x00020000 : 0);
- $flags |= (1 == $bFillColorBg ? 0x00040000 : 0);
- $flags |= (1 == 1 ? 0x00380000 : 0);
-
- $flags |= (1 == $bFormatFont ? 0x04000000 : 0);
-
- $flags |= (1 == $bFormatAlign ? 0x08000000 : 0);
-
- $flags |= (1 == $bFormatBorder ? 0x10000000 : 0);
-
- $flags |= (1 == $bFormatFill ? 0x20000000 : 0);
-
- $flags |= (1 == $bFormatProt ? 0x40000000 : 0);
-
- $flags |= (1 == 0 ? 0x80000000 : 0);
-
- if ($bFormatFont == 1) {
-
- if ($conditional->getStyle()->getFont()->getName() == null) {
- $dataBlockFont = pack('VVVVVVVV', 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000);
- $dataBlockFont .= pack('VVVVVVVV', 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00000000);
- } else {
- $dataBlockFont = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($conditional->getStyle()->getFont()->getName());
- }
-
- if ($conditional->getStyle()->getFont()->getSize() == null) {
- $dataBlockFont .= pack('V', 20 * 11);
- } else {
- $dataBlockFont .= pack('V', 20 * $conditional->getStyle()->getFont()->getSize());
- }
-
- $dataBlockFont .= pack('V', 0);
-
- if ($conditional->getStyle()->getFont()->getBold() == true) {
- $dataBlockFont .= pack('v', 0x02BC);
- } else {
- $dataBlockFont .= pack('v', 0x0190);
- }
-
- if ($conditional->getStyle()->getFont()->getSubScript() == true) {
- $dataBlockFont .= pack('v', 0x02);
- $fontEscapement = 0;
- } elseif ($conditional->getStyle()->getFont()->getSuperScript() == true) {
- $dataBlockFont .= pack('v', 0x01);
- $fontEscapement = 0;
- } else {
- $dataBlockFont .= pack('v', 0x00);
- $fontEscapement = 1;
- }
-
- switch ($conditional->getStyle()->getFont()->getUnderline()) {
- case PHPExcel_Style_Font::UNDERLINE_NONE:
- $dataBlockFont .= pack('C', 0x00);
- $fontUnderline = 0;
- break;
- case PHPExcel_Style_Font::UNDERLINE_DOUBLE:
- $dataBlockFont .= pack('C', 0x02);
- $fontUnderline = 0;
- break;
- case PHPExcel_Style_Font::UNDERLINE_DOUBLEACCOUNTING:
- $dataBlockFont .= pack('C', 0x22);
- $fontUnderline = 0;
- break;
- case PHPExcel_Style_Font::UNDERLINE_SINGLE:
- $dataBlockFont .= pack('C', 0x01);
- $fontUnderline = 0;
- break;
- case PHPExcel_Style_Font::UNDERLINE_SINGLEACCOUNTING:
- $dataBlockFont .= pack('C', 0x21);
- $fontUnderline = 0;
- break;
- default: $dataBlockFont .= pack('C', 0x00);
- $fontUnderline = 1;
- break;
- }
-
- $dataBlockFont .= pack('vC', 0x0000, 0x00);
-
- switch ($conditional->getStyle()->getFont()->getColor()->getRGB()) {
- case '000000':
- $colorIdx = 0x08;
- break;
- case 'FFFFFF':
- $colorIdx = 0x09;
- break;
- case 'FF0000':
- $colorIdx = 0x0A;
- break;
- case '00FF00':
- $colorIdx = 0x0B;
- break;
- case '0000FF':
- $colorIdx = 0x0C;
- break;
- case 'FFFF00':
- $colorIdx = 0x0D;
- break;
- case 'FF00FF':
- $colorIdx = 0x0E;
- break;
- case '00FFFF':
- $colorIdx = 0x0F;
- break;
- case '800000':
- $colorIdx = 0x10;
- break;
- case '008000':
- $colorIdx = 0x11;
- break;
- case '000080':
- $colorIdx = 0x12;
- break;
- case '808000':
- $colorIdx = 0x13;
- break;
- case '800080':
- $colorIdx = 0x14;
- break;
- case '008080':
- $colorIdx = 0x15;
- break;
- case 'C0C0C0':
- $colorIdx = 0x16;
- break;
- case '808080':
- $colorIdx = 0x17;
- break;
- case '9999FF':
- $colorIdx = 0x18;
- break;
- case '993366':
- $colorIdx = 0x19;
- break;
- case 'FFFFCC':
- $colorIdx = 0x1A;
- break;
- case 'CCFFFF':
- $colorIdx = 0x1B;
- break;
- case '660066':
- $colorIdx = 0x1C;
- break;
- case 'FF8080':
- $colorIdx = 0x1D;
- break;
- case '0066CC':
- $colorIdx = 0x1E;
- break;
- case 'CCCCFF':
- $colorIdx = 0x1F;
- break;
- case '000080':
- $colorIdx = 0x20;
- break;
- case 'FF00FF':
- $colorIdx = 0x21;
- break;
- case 'FFFF00':
- $colorIdx = 0x22;
- break;
- case '00FFFF':
- $colorIdx = 0x23;
- break;
- case '800080':
- $colorIdx = 0x24;
- break;
- case '800000':
- $colorIdx = 0x25;
- break;
- case '008080':
- $colorIdx = 0x26;
- break;
- case '0000FF':
- $colorIdx = 0x27;
- break;
- case '00CCFF':
- $colorIdx = 0x28;
- break;
- case 'CCFFFF':
- $colorIdx = 0x29;
- break;
- case 'CCFFCC':
- $colorIdx = 0x2A;
- break;
- case 'FFFF99':
- $colorIdx = 0x2B;
- break;
- case '99CCFF':
- $colorIdx = 0x2C;
- break;
- case 'FF99CC':
- $colorIdx = 0x2D;
- break;
- case 'CC99FF':
- $colorIdx = 0x2E;
- break;
- case 'FFCC99':
- $colorIdx = 0x2F;
- break;
- case '3366FF':
- $colorIdx = 0x30;
- break;
- case '33CCCC':
- $colorIdx = 0x31;
- break;
- case '99CC00':
- $colorIdx = 0x32;
- break;
- case 'FFCC00':
- $colorIdx = 0x33;
- break;
- case 'FF9900':
- $colorIdx = 0x34;
- break;
- case 'FF6600':
- $colorIdx = 0x35;
- break;
- case '666699':
- $colorIdx = 0x36;
- break;
- case '969696':
- $colorIdx = 0x37;
- break;
- case '003366':
- $colorIdx = 0x38;
- break;
- case '339966':
- $colorIdx = 0x39;
- break;
- case '003300':
- $colorIdx = 0x3A;
- break;
- case '333300':
- $colorIdx = 0x3B;
- break;
- case '993300':
- $colorIdx = 0x3C;
- break;
- case '993366':
- $colorIdx = 0x3D;
- break;
- case '333399':
- $colorIdx = 0x3E;
- break;
- case '333333':
- $colorIdx = 0x3F;
- break;
- default:
- $colorIdx = 0x00;
- break;
- }
- $dataBlockFont .= pack('V', $colorIdx);
-
- $dataBlockFont .= pack('V', 0x00000000);
-
- $optionsFlags = 0;
- $optionsFlagsBold = ($conditional->getStyle()->getFont()->getBold() == null ? 1 : 0);
- $optionsFlags |= (1 == $optionsFlagsBold ? 0x00000002 : 0);
- $optionsFlags |= (1 == 1 ? 0x00000008 : 0);
- $optionsFlags |= (1 == 1 ? 0x00000010 : 0);
- $optionsFlags |= (1 == 0 ? 0x00000020 : 0);
- $optionsFlags |= (1 == 1 ? 0x00000080 : 0);
- $dataBlockFont .= pack('V', $optionsFlags);
-
- $dataBlockFont .= pack('V', $fontEscapement);
-
- $dataBlockFont .= pack('V', $fontUnderline);
-
- $dataBlockFont .= pack('V', 0x00000000);
-
- $dataBlockFont .= pack('V', 0x00000000);
-
- $dataBlockFont .= pack('VV', 0x00000000, 0x00000000);
-
- $dataBlockFont .= pack('v', 0x0001);
- }
- if ($bFormatAlign == 1) {
- $blockAlign = 0;
-
- switch ($conditional->getStyle()->getAlignment()->getHorizontal()) {
- case PHPExcel_Style_Alignment::HORIZONTAL_GENERAL:
- $blockAlign = 0;
- break;
- case PHPExcel_Style_Alignment::HORIZONTAL_LEFT:
- $blockAlign = 1;
- break;
- case PHPExcel_Style_Alignment::HORIZONTAL_RIGHT:
- $blockAlign = 3;
- break;
- case PHPExcel_Style_Alignment::HORIZONTAL_CENTER:
- $blockAlign = 2;
- break;
- case PHPExcel_Style_Alignment::HORIZONTAL_CENTER_CONTINUOUS:
- $blockAlign = 6;
- break;
- case PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY:
- $blockAlign = 5;
- break;
- }
- if ($conditional->getStyle()->getAlignment()->getWrapText() == true) {
- $blockAlign |= 1 << 3;
- } else {
- $blockAlign |= 0 << 3;
- }
- switch ($conditional->getStyle()->getAlignment()->getVertical()) {
- case PHPExcel_Style_Alignment::VERTICAL_BOTTOM:
- $blockAlign = 2 << 4;
- break;
- case PHPExcel_Style_Alignment::VERTICAL_TOP:
- $blockAlign = 0 << 4;
- break;
- case PHPExcel_Style_Alignment::VERTICAL_CENTER:
- $blockAlign = 1 << 4;
- break;
- case PHPExcel_Style_Alignment::VERTICAL_JUSTIFY:
- $blockAlign = 3 << 4;
- break;
- }
- $blockAlign |= 0 << 7;
-
- $blockRotation = $conditional->getStyle()->getAlignment()->getTextRotation();
-
- $blockIndent = $conditional->getStyle()->getAlignment()->getIndent();
- if ($conditional->getStyle()->getAlignment()->getShrinkToFit() == true) {
- $blockIndent |= 1 << 4;
- } else {
- $blockIndent |= 0 << 4;
- }
- $blockIndent |= 0 << 6;
-
- $blockIndentRelative = 255;
- $dataBlockAlign = pack('CCvvv', $blockAlign, $blockRotation, $blockIndent, $blockIndentRelative, 0x0000);
- }
- if ($bFormatBorder == 1) {
- $blockLineStyle = 0;
- switch ($conditional->getStyle()->getBorders()->getLeft()->getBorderStyle()) {
- case PHPExcel_Style_Border::BORDER_NONE:
- $blockLineStyle |= 0x00;
- break;
- case PHPExcel_Style_Border::BORDER_THIN:
- $blockLineStyle |= 0x01;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02;
- break;
- case PHPExcel_Style_Border::BORDER_DASHED:
- $blockLineStyle |= 0x03;
- break;
- case PHPExcel_Style_Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04;
- break;
- case PHPExcel_Style_Border::BORDER_THICK:
- $blockLineStyle |= 0x05;
- break;
- case PHPExcel_Style_Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06;
- break;
- case PHPExcel_Style_Border::BORDER_HAIR:
- $blockLineStyle |= 0x07;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C;
- break;
- case PHPExcel_Style_Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D;
- break;
- }
- switch ($conditional->getStyle()->getBorders()->getRight()->getBorderStyle()) {
- case PHPExcel_Style_Border::BORDER_NONE:
- $blockLineStyle |= 0x00 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_THIN:
- $blockLineStyle |= 0x01 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_DASHED:
- $blockLineStyle |= 0x03 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_THICK:
- $blockLineStyle |= 0x05 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_HAIR:
- $blockLineStyle |= 0x07 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09 << 4;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A << 4;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B << 4;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C << 4;
- break;
- case PHPExcel_Style_Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D << 4;
- break;
- }
- switch ($conditional->getStyle()->getBorders()->getTop()->getBorderStyle()) {
- case PHPExcel_Style_Border::BORDER_NONE:
- $blockLineStyle |= 0x00 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_THIN:
- $blockLineStyle |= 0x01 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_DASHED:
- $blockLineStyle |= 0x03 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_THICK:
- $blockLineStyle |= 0x05 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_HAIR:
- $blockLineStyle |= 0x07 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09 << 8;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A << 8;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B << 8;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C << 8;
- break;
- case PHPExcel_Style_Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D << 8;
- break;
- }
- switch ($conditional->getStyle()->getBorders()->getBottom()->getBorderStyle()) {
- case PHPExcel_Style_Border::BORDER_NONE:
- $blockLineStyle |= 0x00 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_THIN:
- $blockLineStyle |= 0x01 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUM:
- $blockLineStyle |= 0x02 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_DASHED:
- $blockLineStyle |= 0x03 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_DOTTED:
- $blockLineStyle |= 0x04 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_THICK:
- $blockLineStyle |= 0x05 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_DOUBLE:
- $blockLineStyle |= 0x06 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_HAIR:
- $blockLineStyle |= 0x07 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHED:
- $blockLineStyle |= 0x08 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOT:
- $blockLineStyle |= 0x09 << 12;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT:
- $blockLineStyle |= 0x0A << 12;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOTDOT:
- $blockLineStyle |= 0x0B << 12;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT:
- $blockLineStyle |= 0x0C << 12;
- break;
- case PHPExcel_Style_Border::BORDER_SLANTDASHDOT:
- $blockLineStyle |= 0x0D << 12;
- break;
- }
-
-
-
-
- $blockColor = 0;
-
-
-
- switch ($conditional->getStyle()->getBorders()->getDiagonal()->getBorderStyle()) {
- case PHPExcel_Style_Border::BORDER_NONE:
- $blockColor |= 0x00 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_THIN:
- $blockColor |= 0x01 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUM:
- $blockColor |= 0x02 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_DASHED:
- $blockColor |= 0x03 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_DOTTED:
- $blockColor |= 0x04 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_THICK:
- $blockColor |= 0x05 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_DOUBLE:
- $blockColor |= 0x06 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_HAIR:
- $blockColor |= 0x07 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHED:
- $blockColor |= 0x08 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOT:
- $blockColor |= 0x09 << 21;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOT:
- $blockColor |= 0x0A << 21;
- break;
- case PHPExcel_Style_Border::BORDER_DASHDOTDOT:
- $blockColor |= 0x0B << 21;
- break;
- case PHPExcel_Style_Border::BORDER_MEDIUMDASHDOTDOT:
- $blockColor |= 0x0C << 21;
- break;
- case PHPExcel_Style_Border::BORDER_SLANTDASHDOT:
- $blockColor |= 0x0D << 21;
- break;
- }
- $dataBlockBorder = pack('vv', $blockLineStyle, $blockColor);
- }
- if ($bFormatFill == 1) {
-
- $blockFillPatternStyle = 0;
- switch ($conditional->getStyle()->getFill()->getFillType()) {
- case PHPExcel_Style_Fill::FILL_NONE:
- $blockFillPatternStyle = 0x00;
- break;
- case PHPExcel_Style_Fill::FILL_SOLID:
- $blockFillPatternStyle = 0x01;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_MEDIUMGRAY:
- $blockFillPatternStyle = 0x02;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_DARKGRAY:
- $blockFillPatternStyle = 0x03;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRAY:
- $blockFillPatternStyle = 0x04;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_DARKHORIZONTAL:
- $blockFillPatternStyle = 0x05;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_DARKVERTICAL:
- $blockFillPatternStyle = 0x06;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_DARKDOWN:
- $blockFillPatternStyle = 0x07;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_DARKUP:
- $blockFillPatternStyle = 0x08;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_DARKGRID:
- $blockFillPatternStyle = 0x09;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_DARKTRELLIS:
- $blockFillPatternStyle = 0x0A;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_LIGHTHORIZONTAL:
- $blockFillPatternStyle = 0x0B;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_LIGHTVERTICAL:
- $blockFillPatternStyle = 0x0C;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_LIGHTDOWN:
- $blockFillPatternStyle = 0x0D;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_LIGHTUP:
- $blockFillPatternStyle = 0x0E;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_LIGHTGRID:
- $blockFillPatternStyle = 0x0F;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_LIGHTTRELLIS:
- $blockFillPatternStyle = 0x10;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_GRAY125:
- $blockFillPatternStyle = 0x11;
- break;
- case PHPExcel_Style_Fill::FILL_PATTERN_GRAY0625:
- $blockFillPatternStyle = 0x12;
- break;
- case PHPExcel_Style_Fill::FILL_GRADIENT_LINEAR:
- $blockFillPatternStyle = 0x00;
- break;
- case PHPExcel_Style_Fill::FILL_GRADIENT_PATH:
- $blockFillPatternStyle = 0x00;
- break;
- default:
- $blockFillPatternStyle = 0x00;
- break;
- }
-
- switch ($conditional->getStyle()->getFill()->getStartColor()->getRGB()) {
- case '000000':
- $colorIdxBg = 0x08;
- break;
- case 'FFFFFF':
- $colorIdxBg = 0x09;
- break;
- case 'FF0000':
- $colorIdxBg = 0x0A;
- break;
- case '00FF00':
- $colorIdxBg = 0x0B;
- break;
- case '0000FF':
- $colorIdxBg = 0x0C;
- break;
- case 'FFFF00':
- $colorIdxBg = 0x0D;
- break;
- case 'FF00FF':
- $colorIdxBg = 0x0E;
- break;
- case '00FFFF':
- $colorIdxBg = 0x0F;
- break;
- case '800000':
- $colorIdxBg = 0x10;
- break;
- case '008000':
- $colorIdxBg = 0x11;
- break;
- case '000080':
- $colorIdxBg = 0x12;
- break;
- case '808000':
- $colorIdxBg = 0x13;
- break;
- case '800080':
- $colorIdxBg = 0x14;
- break;
- case '008080':
- $colorIdxBg = 0x15;
- break;
- case 'C0C0C0':
- $colorIdxBg = 0x16;
- break;
- case '808080':
- $colorIdxBg = 0x17;
- break;
- case '9999FF':
- $colorIdxBg = 0x18;
- break;
- case '993366':
- $colorIdxBg = 0x19;
- break;
- case 'FFFFCC':
- $colorIdxBg = 0x1A;
- break;
- case 'CCFFFF':
- $colorIdxBg = 0x1B;
- break;
- case '660066':
- $colorIdxBg = 0x1C;
- break;
- case 'FF8080':
- $colorIdxBg = 0x1D;
- break;
- case '0066CC':
- $colorIdxBg = 0x1E;
- break;
- case 'CCCCFF':
- $colorIdxBg = 0x1F;
- break;
- case '000080':
- $colorIdxBg = 0x20;
- break;
- case 'FF00FF':
- $colorIdxBg = 0x21;
- break;
- case 'FFFF00':
- $colorIdxBg = 0x22;
- break;
- case '00FFFF':
- $colorIdxBg = 0x23;
- break;
- case '800080':
- $colorIdxBg = 0x24;
- break;
- case '800000':
- $colorIdxBg = 0x25;
- break;
- case '008080':
- $colorIdxBg = 0x26;
- break;
- case '0000FF':
- $colorIdxBg = 0x27;
- break;
- case '00CCFF':
- $colorIdxBg = 0x28;
- break;
- case 'CCFFFF':
- $colorIdxBg = 0x29;
- break;
- case 'CCFFCC':
- $colorIdxBg = 0x2A;
- break;
- case 'FFFF99':
- $colorIdxBg = 0x2B;
- break;
- case '99CCFF':
- $colorIdxBg = 0x2C;
- break;
- case 'FF99CC':
- $colorIdxBg = 0x2D;
- break;
- case 'CC99FF':
- $colorIdxBg = 0x2E;
- break;
- case 'FFCC99':
- $colorIdxBg = 0x2F;
- break;
- case '3366FF':
- $colorIdxBg = 0x30;
- break;
- case '33CCCC':
- $colorIdxBg = 0x31;
- break;
- case '99CC00':
- $colorIdxBg = 0x32;
- break;
- case 'FFCC00':
- $colorIdxBg = 0x33;
- break;
- case 'FF9900':
- $colorIdxBg = 0x34;
- break;
- case 'FF6600':
- $colorIdxBg = 0x35;
- break;
- case '666699':
- $colorIdxBg = 0x36;
- break;
- case '969696':
- $colorIdxBg = 0x37;
- break;
- case '003366':
- $colorIdxBg = 0x38;
- break;
- case '339966':
- $colorIdxBg = 0x39;
- break;
- case '003300':
- $colorIdxBg = 0x3A;
- break;
- case '333300':
- $colorIdxBg = 0x3B;
- break;
- case '993300':
- $colorIdxBg = 0x3C;
- break;
- case '993366':
- $colorIdxBg = 0x3D;
- break;
- case '333399':
- $colorIdxBg = 0x3E;
- break;
- case '333333':
- $colorIdxBg = 0x3F;
- break;
- default:
- $colorIdxBg = 0x41;
- break;
- }
-
- switch ($conditional->getStyle()->getFill()->getEndColor()->getRGB()) {
- case '000000':
- $colorIdxFg = 0x08;
- break;
- case 'FFFFFF':
- $colorIdxFg = 0x09;
- break;
- case 'FF0000':
- $colorIdxFg = 0x0A;
- break;
- case '00FF00':
- $colorIdxFg = 0x0B;
- break;
- case '0000FF':
- $colorIdxFg = 0x0C;
- break;
- case 'FFFF00':
- $colorIdxFg = 0x0D;
- break;
- case 'FF00FF':
- $colorIdxFg = 0x0E;
- break;
- case '00FFFF':
- $colorIdxFg = 0x0F;
- break;
- case '800000':
- $colorIdxFg = 0x10;
- break;
- case '008000':
- $colorIdxFg = 0x11;
- break;
- case '000080':
- $colorIdxFg = 0x12;
- break;
- case '808000':
- $colorIdxFg = 0x13;
- break;
- case '800080':
- $colorIdxFg = 0x14;
- break;
- case '008080':
- $colorIdxFg = 0x15;
- break;
- case 'C0C0C0':
- $colorIdxFg = 0x16;
- break;
- case '808080':
- $colorIdxFg = 0x17;
- break;
- case '9999FF':
- $colorIdxFg = 0x18;
- break;
- case '993366':
- $colorIdxFg = 0x19;
- break;
- case 'FFFFCC':
- $colorIdxFg = 0x1A;
- break;
- case 'CCFFFF':
- $colorIdxFg = 0x1B;
- break;
- case '660066':
- $colorIdxFg = 0x1C;
- break;
- case 'FF8080':
- $colorIdxFg = 0x1D;
- break;
- case '0066CC':
- $colorIdxFg = 0x1E;
- break;
- case 'CCCCFF':
- $colorIdxFg = 0x1F;
- break;
- case '000080':
- $colorIdxFg = 0x20;
- break;
- case 'FF00FF':
- $colorIdxFg = 0x21;
- break;
- case 'FFFF00':
- $colorIdxFg = 0x22;
- break;
- case '00FFFF':
- $colorIdxFg = 0x23;
- break;
- case '800080':
- $colorIdxFg = 0x24;
- break;
- case '800000':
- $colorIdxFg = 0x25;
- break;
- case '008080':
- $colorIdxFg = 0x26;
- break;
- case '0000FF':
- $colorIdxFg = 0x27;
- break;
- case '00CCFF':
- $colorIdxFg = 0x28;
- break;
- case 'CCFFFF':
- $colorIdxFg = 0x29;
- break;
- case 'CCFFCC':
- $colorIdxFg = 0x2A;
- break;
- case 'FFFF99':
- $colorIdxFg = 0x2B;
- break;
- case '99CCFF':
- $colorIdxFg = 0x2C;
- break;
- case 'FF99CC':
- $colorIdxFg = 0x2D;
- break;
- case 'CC99FF':
- $colorIdxFg = 0x2E;
- break;
- case 'FFCC99':
- $colorIdxFg = 0x2F;
- break;
- case '3366FF':
- $colorIdxFg = 0x30;
- break;
- case '33CCCC':
- $colorIdxFg = 0x31;
- break;
- case '99CC00':
- $colorIdxFg = 0x32;
- break;
- case 'FFCC00':
- $colorIdxFg = 0x33;
- break;
- case 'FF9900':
- $colorIdxFg = 0x34;
- break;
- case 'FF6600':
- $colorIdxFg = 0x35;
- break;
- case '666699':
- $colorIdxFg = 0x36;
- break;
- case '969696':
- $colorIdxFg = 0x37;
- break;
- case '003366':
- $colorIdxFg = 0x38;
- break;
- case '339966':
- $colorIdxFg = 0x39;
- break;
- case '003300':
- $colorIdxFg = 0x3A;
- break;
- case '333300':
- $colorIdxFg = 0x3B;
- break;
- case '993300':
- $colorIdxFg = 0x3C;
- break;
- case '993366':
- $colorIdxFg = 0x3D;
- break;
- case '333399':
- $colorIdxFg = 0x3E;
- break;
- case '333333':
- $colorIdxFg = 0x3F;
- break;
- default:
- $colorIdxFg = 0x40;
- break;
- }
- $dataBlockFill = pack('v', $blockFillPatternStyle);
- $dataBlockFill .= pack('v', $colorIdxFg | ($colorIdxBg << 7));
- }
- if ($bFormatProt == 1) {
- $dataBlockProtection = 0;
- if ($conditional->getStyle()->getProtection()->getLocked() == PHPExcel_Style_Protection::PROTECTION_PROTECTED) {
- $dataBlockProtection = 1;
- }
- if ($conditional->getStyle()->getProtection()->getHidden() == PHPExcel_Style_Protection::PROTECTION_PROTECTED) {
- $dataBlockProtection = 1 << 1;
- }
- }
- $data = pack('CCvvVv', $type, $operatorType, $szValue1, $szValue2, $flags, 0x0000);
- if ($bFormatFont == 1) {
- $data .= $dataBlockFont;
- }
- if ($bFormatAlign == 1) {
- $data .= $dataBlockAlign;
- }
- if ($bFormatBorder == 1) {
- $data .= $dataBlockBorder;
- }
- if ($bFormatFill == 1) {
- $data .= $dataBlockFill;
- }
- if ($bFormatProt == 1) {
- $data .= $dataBlockProtection;
- }
- if (!is_null($operand1)) {
- $data .= $operand1;
- }
- if (!is_null($operand2)) {
- $data .= $operand2;
- }
- $header = pack('vv', $record, strlen($data));
- $this->append($header . $data);
- }
-
- private function writeCFHeader()
- {
- $record = 0x01B0;
- $length = 0x0016;
- $numColumnMin = null;
- $numColumnMax = null;
- $numRowMin = null;
- $numRowMax = null;
- $arrConditional = array();
- foreach ($this->phpSheet->getConditionalStylesCollection() as $cellCoordinate => $conditionalStyles) {
- foreach ($conditionalStyles as $conditional) {
- if ($conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_EXPRESSION
- || $conditional->getConditionType() == PHPExcel_Style_Conditional::CONDITION_CELLIS) {
- if (!in_array($conditional->getHashCode(), $arrConditional)) {
- $arrConditional[] = $conditional->getHashCode();
- }
-
- $arrCoord = PHPExcel_Cell::coordinateFromString($cellCoordinate);
- if (!is_numeric($arrCoord[0])) {
- $arrCoord[0] = PHPExcel_Cell::columnIndexFromString($arrCoord[0]);
- }
- if (is_null($numColumnMin) || ($numColumnMin > $arrCoord[0])) {
- $numColumnMin = $arrCoord[0];
- }
- if (is_null($numColumnMax) || ($numColumnMax < $arrCoord[0])) {
- $numColumnMax = $arrCoord[0];
- }
- if (is_null($numRowMin) || ($numRowMin > $arrCoord[1])) {
- $numRowMin = $arrCoord[1];
- }
- if (is_null($numRowMax) || ($numRowMax < $arrCoord[1])) {
- $numRowMax = $arrCoord[1];
- }
- }
- }
- }
- $needRedraw = 1;
- $cellRange = pack('vvvv', $numRowMin-1, $numRowMax-1, $numColumnMin-1, $numColumnMax-1);
- $header = pack('vv', $record, $length);
- $data = pack('vv', count($arrConditional), $needRedraw);
- $data .= $cellRange;
- $data .= pack('v', 0x0001);
- $data .= $cellRange;
- $this->append($header . $data);
- }
- }
|