123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681 |
- <?php
- class PHPExcel_Writer_Excel5_Worksheet extends PHPExcel_Writer_Excel5_BIFFwriter
- {
-
- private $_parser;
-
- public $_xls_strmax;
-
- public $_colinfo;
-
- public $_selection;
-
- public $_active_pane;
-
- public $_outline_on;
-
- public $_outline_style;
-
- public $_outline_below;
-
- public $_outline_right;
-
- public $_str_total;
-
- public $_str_unique;
-
- public $_str_table;
-
- private $_colors;
-
- private $_firstRowIndex;
-
- private $_lastRowIndex;
-
- private $_firstColumnIndex;
-
- private $_lastColumnIndex;
-
- public $_phpSheet;
-
- private $_countCellStyleXfs;
-
- private $_escher;
-
- public $_fntHashIndex;
-
- public function __construct(&$str_total, &$str_unique, &$str_table, &$colors,
- $parser, $preCalculateFormulas, $phpSheet)
- {
-
- parent::__construct();
-
- $this->_preCalculateFormulas = $preCalculateFormulas;
- $this->_str_total = &$str_total;
- $this->_str_unique = &$str_unique;
- $this->_str_table = &$str_table;
- $this->_colors = &$colors;
- $this->_parser = $parser;
- $this->_phpSheet = $phpSheet;
-
-
- $this->_xls_strmax = 255;
- $this->_colinfo = array();
- $this->_selection = array(0,0,0,0);
- $this->_active_pane = 3;
- $this->_print_headers = 0;
- $this->_outline_style = 0;
- $this->_outline_below = 1;
- $this->_outline_right = 1;
- $this->_outline_on = 1;
- $this->_fntHashIndex = 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());
- }
-
- 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->_colinfo[] = 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->_colinfo)) {
- $colcount = count($this->_colinfo);
- for ($i = 0; $i < $colcount; ++$i) {
- $this->_writeColinfo($this->_colinfo[$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->_fntHashIndex[$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);
- } else if ( 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
- ));
- }
-
- function getData()
- {
- $buffer = 4096;
-
- if (isset($this->_data)) {
- $tmp = $this->_data;
- unset($this->_data);
- return $tmp;
- }
-
- return false;
- }
-
- function printRowColHeaders($print = 1)
- {
- $this->_print_headers = $print;
- }
-
- function setOutline($visible = true, $symbols_below = true, $symbols_right = true, $auto_style = false)
- {
- $this->_outline_on = $visible;
- $this->_outline_below = $symbols_below;
- $this->_outline_right = $symbols_right;
- $this->_outline_style = $auto_style;
-
- if ($this->_outline_on) {
- $this->_outline_on = 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->_str_table[$str])) {
- $this->_str_table[$str] = $this->_str_unique++;
- }
- $this->_str_total++;
- $header = pack('vv', $record, $length);
- $data = pack('vvvV', $row, $col, $xfIndex, $this->_str_table[$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->_xls_strmax) {
- $str = substr($str, 0, $this->_xls_strmax);
- $length = 0x0008 + $this->_xls_strmax;
- $strlen = $this->_xls_strmax;
- $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->_str_table[$str])) {
- $this->_str_table[$str] = $this->_str_unique++;
- }
- $this->_str_total++;
- $header = pack('vv', $record, $length);
- $data = pack('vvvV', $row, $col, $xfIndex, $this->_str_table[$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);
- }
-
- 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));
- }
-
- 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));
- }
-
- 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;
- }
-
- 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;
- }
-
- 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->_outline_on;
- $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->_active_pane;
- $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->_active_pane = $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->_colinfo);
- for ($i = 0; $i < $colcount; ++$i) {
- $col_level = max($this->_colinfo[$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->_outline_style) {
- $grbit |= 0x0020;
- }
- if ($this->_phpSheet->getShowSummaryBelow()) {
- $grbit |= 0x0040;
- }
- if ($this->_phpSheet->getShowSummaryRight()) {
- $grbit |= 0x0080;
- }
- if ($this->_phpSheet->getPageSetup()->getFitToPage()) {
- $grbit |= 0x0100;
- }
- if ($this->_outline_on) {
- $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);
- }
-
- 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);
- }
-
- 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);
- }
-
- 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);
- }
-
- 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;
- } else if($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;
- } else if($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;
- } else if($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);
- }
- }
|