12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445 |
- <?php
- class PHPExcel_Writer_Excel5_Workbook extends PHPExcel_Writer_Excel5_BIFFwriter
- {
-
- private $parser;
-
- private $biffSize;
-
- private $xfWriters = array();
-
- private $palette;
-
- private $codepage;
-
- private $countryCode;
-
- private $phpExcel;
-
- private $fontWriters = array();
-
- private $addedFonts = array();
-
- private $numberFormats = array();
-
- private $addedNumberFormats = array();
-
- private $worksheetSizes = array();
-
- private $worksheetOffsets = array();
-
- private $stringTotal;
-
- private $stringUnique;
-
- private $stringTable;
-
- private $colors;
-
- private $escher;
-
- public function __construct(PHPExcel $phpExcel = null, &$str_total, &$str_unique, &$str_table, &$colors, $parser)
- {
-
- parent::__construct();
- $this->parser = $parser;
- $this->biffSize = 0;
- $this->palette = array();
- $this->countryCode = -1;
- $this->stringTotal = &$str_total;
- $this->stringUnique = &$str_unique;
- $this->stringTable = &$str_table;
- $this->colors = &$colors;
- $this->setPaletteXl97();
- $this->phpExcel = $phpExcel;
-
-
- $this->codepage = 0x04B0;
-
- $countSheets = $phpExcel->getSheetCount();
- for ($i = 0; $i < $countSheets; ++$i) {
- $phpSheet = $phpExcel->getSheet($i);
- $this->parser->setExtSheet($phpSheet->getTitle(), $i);
- $supbook_index = 0x00;
- $ref = pack('vvv', $supbook_index, $i, $i);
- $this->parser->references[] = $ref;
-
- if ($phpSheet->isTabColorSet()) {
- $this->addColor($phpSheet->getTabColor()->getRGB());
- }
- }
- }
-
- public function addXfWriter($style, $isStyleXf = false)
- {
- $xfWriter = new PHPExcel_Writer_Excel5_Xf($style);
- $xfWriter->setIsStyleXf($isStyleXf);
-
- $fontIndex = $this->addFont($style->getFont());
-
- $xfWriter->setFontIndex($fontIndex);
-
- $xfWriter->setFgColor($this->addColor($style->getFill()->getStartColor()->getRGB()));
- $xfWriter->setBgColor($this->addColor($style->getFill()->getEndColor()->getRGB()));
- $xfWriter->setBottomColor($this->addColor($style->getBorders()->getBottom()->getColor()->getRGB()));
- $xfWriter->setTopColor($this->addColor($style->getBorders()->getTop()->getColor()->getRGB()));
- $xfWriter->setRightColor($this->addColor($style->getBorders()->getRight()->getColor()->getRGB()));
- $xfWriter->setLeftColor($this->addColor($style->getBorders()->getLeft()->getColor()->getRGB()));
- $xfWriter->setDiagColor($this->addColor($style->getBorders()->getDiagonal()->getColor()->getRGB()));
-
- if ($style->getNumberFormat()->getBuiltInFormatCode() === false) {
- $numberFormatHashCode = $style->getNumberFormat()->getHashCode();
- if (isset($this->addedNumberFormats[$numberFormatHashCode])) {
- $numberFormatIndex = $this->addedNumberFormats[$numberFormatHashCode];
- } else {
- $numberFormatIndex = 164 + count($this->numberFormats);
- $this->numberFormats[$numberFormatIndex] = $style->getNumberFormat();
- $this->addedNumberFormats[$numberFormatHashCode] = $numberFormatIndex;
- }
- } else {
- $numberFormatIndex = (int) $style->getNumberFormat()->getBuiltInFormatCode();
- }
-
- $xfWriter->setNumberFormatIndex($numberFormatIndex);
- $this->xfWriters[] = $xfWriter;
- $xfIndex = count($this->xfWriters) - 1;
- return $xfIndex;
- }
-
- public function addFont(PHPExcel_Style_Font $font)
- {
- $fontHashCode = $font->getHashCode();
- if (isset($this->addedFonts[$fontHashCode])) {
- $fontIndex = $this->addedFonts[$fontHashCode];
- } else {
- $countFonts = count($this->fontWriters);
- $fontIndex = ($countFonts < 4) ? $countFonts : $countFonts + 1;
- $fontWriter = new PHPExcel_Writer_Excel5_Font($font);
- $fontWriter->setColorIndex($this->addColor($font->getColor()->getRGB()));
- $this->fontWriters[] = $fontWriter;
- $this->addedFonts[$fontHashCode] = $fontIndex;
- }
- return $fontIndex;
- }
-
- private function addColor($rgb)
- {
- if (!isset($this->colors[$rgb])) {
- if (count($this->colors) < 57) {
-
- $colorIndex = 8 + count($this->colors);
- $this->palette[$colorIndex] =
- array(
- hexdec(substr($rgb, 0, 2)),
- hexdec(substr($rgb, 2, 2)),
- hexdec(substr($rgb, 4)),
- 0
- );
- $this->colors[$rgb] = $colorIndex;
- } else {
-
- $colorIndex = 0;
- }
- } else {
-
- $colorIndex = $this->colors[$rgb];
- }
- return $colorIndex;
- }
-
- private function setPaletteXl97()
- {
- $this->palette = array(
- 0x08 => array(0x00, 0x00, 0x00, 0x00),
- 0x09 => array(0xff, 0xff, 0xff, 0x00),
- 0x0A => array(0xff, 0x00, 0x00, 0x00),
- 0x0B => array(0x00, 0xff, 0x00, 0x00),
- 0x0C => array(0x00, 0x00, 0xff, 0x00),
- 0x0D => array(0xff, 0xff, 0x00, 0x00),
- 0x0E => array(0xff, 0x00, 0xff, 0x00),
- 0x0F => array(0x00, 0xff, 0xff, 0x00),
- 0x10 => array(0x80, 0x00, 0x00, 0x00),
- 0x11 => array(0x00, 0x80, 0x00, 0x00),
- 0x12 => array(0x00, 0x00, 0x80, 0x00),
- 0x13 => array(0x80, 0x80, 0x00, 0x00),
- 0x14 => array(0x80, 0x00, 0x80, 0x00),
- 0x15 => array(0x00, 0x80, 0x80, 0x00),
- 0x16 => array(0xc0, 0xc0, 0xc0, 0x00),
- 0x17 => array(0x80, 0x80, 0x80, 0x00),
- 0x18 => array(0x99, 0x99, 0xff, 0x00),
- 0x19 => array(0x99, 0x33, 0x66, 0x00),
- 0x1A => array(0xff, 0xff, 0xcc, 0x00),
- 0x1B => array(0xcc, 0xff, 0xff, 0x00),
- 0x1C => array(0x66, 0x00, 0x66, 0x00),
- 0x1D => array(0xff, 0x80, 0x80, 0x00),
- 0x1E => array(0x00, 0x66, 0xcc, 0x00),
- 0x1F => array(0xcc, 0xcc, 0xff, 0x00),
- 0x20 => array(0x00, 0x00, 0x80, 0x00),
- 0x21 => array(0xff, 0x00, 0xff, 0x00),
- 0x22 => array(0xff, 0xff, 0x00, 0x00),
- 0x23 => array(0x00, 0xff, 0xff, 0x00),
- 0x24 => array(0x80, 0x00, 0x80, 0x00),
- 0x25 => array(0x80, 0x00, 0x00, 0x00),
- 0x26 => array(0x00, 0x80, 0x80, 0x00),
- 0x27 => array(0x00, 0x00, 0xff, 0x00),
- 0x28 => array(0x00, 0xcc, 0xff, 0x00),
- 0x29 => array(0xcc, 0xff, 0xff, 0x00),
- 0x2A => array(0xcc, 0xff, 0xcc, 0x00),
- 0x2B => array(0xff, 0xff, 0x99, 0x00),
- 0x2C => array(0x99, 0xcc, 0xff, 0x00),
- 0x2D => array(0xff, 0x99, 0xcc, 0x00),
- 0x2E => array(0xcc, 0x99, 0xff, 0x00),
- 0x2F => array(0xff, 0xcc, 0x99, 0x00),
- 0x30 => array(0x33, 0x66, 0xff, 0x00),
- 0x31 => array(0x33, 0xcc, 0xcc, 0x00),
- 0x32 => array(0x99, 0xcc, 0x00, 0x00),
- 0x33 => array(0xff, 0xcc, 0x00, 0x00),
- 0x34 => array(0xff, 0x99, 0x00, 0x00),
- 0x35 => array(0xff, 0x66, 0x00, 0x00),
- 0x36 => array(0x66, 0x66, 0x99, 0x00),
- 0x37 => array(0x96, 0x96, 0x96, 0x00),
- 0x38 => array(0x00, 0x33, 0x66, 0x00),
- 0x39 => array(0x33, 0x99, 0x66, 0x00),
- 0x3A => array(0x00, 0x33, 0x00, 0x00),
- 0x3B => array(0x33, 0x33, 0x00, 0x00),
- 0x3C => array(0x99, 0x33, 0x00, 0x00),
- 0x3D => array(0x99, 0x33, 0x66, 0x00),
- 0x3E => array(0x33, 0x33, 0x99, 0x00),
- 0x3F => array(0x33, 0x33, 0x33, 0x00),
- );
- }
-
- public function writeWorkbook($pWorksheetSizes = null)
- {
- $this->worksheetSizes = $pWorksheetSizes;
-
-
- $total_worksheets = $this->phpExcel->getSheetCount();
-
- $this->storeBof(0x0005);
- $this->writeCodepage();
- $this->writeWindow1();
- $this->writeDateMode();
- $this->writeAllFonts();
- $this->writeAllNumberFormats();
- $this->writeAllXfs();
- $this->writeAllStyles();
- $this->writePalette();
-
- $part3 = '';
- if ($this->countryCode != -1) {
- $part3 .= $this->writeCountry();
- }
- $part3 .= $this->writeRecalcId();
- $part3 .= $this->writeSupbookInternal();
-
- $part3 .= $this->writeExternalsheetBiff8();
- $part3 .= $this->writeAllDefinedNamesBiff8();
- $part3 .= $this->writeMsoDrawingGroup();
- $part3 .= $this->writeSharedStringsTable();
- $part3 .= $this->writeEof();
-
- $this->calcSheetOffsets();
- for ($i = 0; $i < $total_worksheets; ++$i) {
- $this->writeBoundSheet($this->phpExcel->getSheet($i), $this->worksheetOffsets[$i]);
- }
-
- $this->_data .= $part3;
- return $this->_data;
- }
-
- private function calcSheetOffsets()
- {
- $boundsheet_length = 10;
-
- $offset = $this->_datasize;
-
- $total_worksheets = count($this->phpExcel->getAllSheets());
- foreach ($this->phpExcel->getWorksheetIterator() as $sheet) {
- $offset += $boundsheet_length + strlen(PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($sheet->getTitle()));
- }
-
- for ($i = 0; $i < $total_worksheets; ++$i) {
- $this->worksheetOffsets[$i] = $offset;
- $offset += $this->worksheetSizes[$i];
- }
- $this->biffSize = $offset;
- }
-
- private function writeAllFonts()
- {
- foreach ($this->fontWriters as $fontWriter) {
- $this->append($fontWriter->writeFont());
- }
- }
-
- private function writeAllNumberFormats()
- {
- foreach ($this->numberFormats as $numberFormatIndex => $numberFormat) {
- $this->writeNumberFormat($numberFormat->getFormatCode(), $numberFormatIndex);
- }
- }
-
- private function writeAllXfs()
- {
- foreach ($this->xfWriters as $xfWriter) {
- $this->append($xfWriter->writeXf());
- }
- }
-
- private function writeAllStyles()
- {
- $this->writeStyle();
- }
-
- private function writeExternals()
- {
- $countSheets = $this->phpExcel->getSheetCount();
-
- $this->writeExternalCount($countSheets);
-
- for ($i = 0; $i < $countSheets; ++$i) {
- $this->writeExternalSheet($this->phpExcel->getSheet($i)->getTitle());
- }
- }
-
- private function writeNames()
- {
-
- $total_worksheets = $this->phpExcel->getSheetCount();
-
- for ($i = 0; $i < $total_worksheets; ++$i) {
- $sheetSetup = $this->phpExcel->getSheet($i)->getPageSetup();
-
- if ($sheetSetup->isPrintAreaSet()) {
-
- $printArea = PHPExcel_Cell::splitRange($sheetSetup->getPrintArea());
- $printArea = $printArea[0];
- $printArea[0] = PHPExcel_Cell::coordinateFromString($printArea[0]);
- $printArea[1] = PHPExcel_Cell::coordinateFromString($printArea[1]);
- $print_rowmin = $printArea[0][1] - 1;
- $print_rowmax = $printArea[1][1] - 1;
- $print_colmin = PHPExcel_Cell::columnIndexFromString($printArea[0][0]) - 1;
- $print_colmax = PHPExcel_Cell::columnIndexFromString($printArea[1][0]) - 1;
- $this->writeNameShort(
- $i,
- 0x06,
- $print_rowmin,
- $print_rowmax,
- $print_colmin,
- $print_colmax
- );
- }
- }
-
- for ($i = 0; $i < $total_worksheets; ++$i) {
- $sheetSetup = $this->phpExcel->getSheet($i)->getPageSetup();
-
- if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) {
- $repeat = $sheetSetup->getColumnsToRepeatAtLeft();
- $colmin = PHPExcel_Cell::columnIndexFromString($repeat[0]) - 1;
- $colmax = PHPExcel_Cell::columnIndexFromString($repeat[1]) - 1;
- $repeat = $sheetSetup->getRowsToRepeatAtTop();
- $rowmin = $repeat[0] - 1;
- $rowmax = $repeat[1] - 1;
- $this->writeNameLong(
- $i,
- 0x07,
- $rowmin,
- $rowmax,
- $colmin,
- $colmax
- );
-
- } elseif ($sheetSetup->isColumnsToRepeatAtLeftSet() || $sheetSetup->isRowsToRepeatAtTopSet()) {
-
- if ($sheetSetup->isColumnsToRepeatAtLeftSet()) {
- $repeat = $sheetSetup->getColumnsToRepeatAtLeft();
- $colmin = PHPExcel_Cell::columnIndexFromString($repeat[0]) - 1;
- $colmax = PHPExcel_Cell::columnIndexFromString($repeat[1]) - 1;
- } else {
- $colmin = 0;
- $colmax = 255;
- }
-
- if ($sheetSetup->isRowsToRepeatAtTopSet()) {
- $repeat = $sheetSetup->getRowsToRepeatAtTop();
- $rowmin = $repeat[0] - 1;
- $rowmax = $repeat[1] - 1;
- } else {
- $rowmin = 0;
- $rowmax = 65535;
- }
- $this->writeNameShort(
- $i,
- 0x07,
- $rowmin,
- $rowmax,
- $colmin,
- $colmax
- );
- }
- }
- }
-
- private function writeAllDefinedNamesBiff8()
- {
- $chunk = '';
-
- if (count($this->phpExcel->getNamedRanges()) > 0) {
-
- $namedRanges = $this->phpExcel->getNamedRanges();
- foreach ($namedRanges as $namedRange) {
-
- $range = PHPExcel_Cell::splitRange($namedRange->getRange());
- for ($i = 0; $i < count($range); $i++) {
- $range[$i][0] = '\'' . str_replace("'", "''", $namedRange->getWorksheet()->getTitle()) . '\'!' . PHPExcel_Cell::absoluteCoordinate($range[$i][0]);
- if (isset($range[$i][1])) {
- $range[$i][1] = PHPExcel_Cell::absoluteCoordinate($range[$i][1]);
- }
- }
- $range = PHPExcel_Cell::buildRange($range);
-
- try {
- $error = $this->parser->parse($range);
- $formulaData = $this->parser->toReversePolish();
-
- if (isset($formulaData{0}) and ($formulaData{0} == "\x7A" or $formulaData{0} == "\x5A")) {
- $formulaData = "\x3A" . substr($formulaData, 1);
- }
- if ($namedRange->getLocalOnly()) {
-
- $scope = $this->phpExcel->getIndex($namedRange->getScope()) + 1;
- } else {
-
- $scope = 0;
- }
- $chunk .= $this->writeData($this->writeDefinedNameBiff8($namedRange->getName(), $formulaData, $scope, false));
- } catch (PHPExcel_Exception $e) {
-
- }
- }
- }
-
- $total_worksheets = $this->phpExcel->getSheetCount();
-
- for ($i = 0; $i < $total_worksheets; ++$i) {
- $sheetSetup = $this->phpExcel->getSheet($i)->getPageSetup();
-
- if ($sheetSetup->isColumnsToRepeatAtLeftSet() && $sheetSetup->isRowsToRepeatAtTopSet()) {
- $repeat = $sheetSetup->getColumnsToRepeatAtLeft();
- $colmin = PHPExcel_Cell::columnIndexFromString($repeat[0]) - 1;
- $colmax = PHPExcel_Cell::columnIndexFromString($repeat[1]) - 1;
- $repeat = $sheetSetup->getRowsToRepeatAtTop();
- $rowmin = $repeat[0] - 1;
- $rowmax = $repeat[1] - 1;
-
- $formulaData = pack('Cv', 0x29, 0x17);
- $formulaData .= pack('Cvvvvv', 0x3B, $i, 0, 65535, $colmin, $colmax);
- $formulaData .= pack('Cvvvvv', 0x3B, $i, $rowmin, $rowmax, 0, 255);
- $formulaData .= pack('C', 0x10);
-
- $chunk .= $this->writeData($this->writeDefinedNameBiff8(pack('C', 0x07), $formulaData, $i + 1, true));
-
- } elseif ($sheetSetup->isColumnsToRepeatAtLeftSet() || $sheetSetup->isRowsToRepeatAtTopSet()) {
-
- if ($sheetSetup->isColumnsToRepeatAtLeftSet()) {
- $repeat = $sheetSetup->getColumnsToRepeatAtLeft();
- $colmin = PHPExcel_Cell::columnIndexFromString($repeat[0]) - 1;
- $colmax = PHPExcel_Cell::columnIndexFromString($repeat[1]) - 1;
- } else {
- $colmin = 0;
- $colmax = 255;
- }
-
- if ($sheetSetup->isRowsToRepeatAtTopSet()) {
- $repeat = $sheetSetup->getRowsToRepeatAtTop();
- $rowmin = $repeat[0] - 1;
- $rowmax = $repeat[1] - 1;
- } else {
- $rowmin = 0;
- $rowmax = 65535;
- }
-
- $formulaData = pack('Cvvvvv', 0x3B, $i, $rowmin, $rowmax, $colmin, $colmax);
-
- $chunk .= $this->writeData($this->writeDefinedNameBiff8(pack('C', 0x07), $formulaData, $i + 1, true));
- }
- }
-
- for ($i = 0; $i < $total_worksheets; ++$i) {
- $sheetSetup = $this->phpExcel->getSheet($i)->getPageSetup();
- if ($sheetSetup->isPrintAreaSet()) {
-
- $printArea = PHPExcel_Cell::splitRange($sheetSetup->getPrintArea());
- $countPrintArea = count($printArea);
- $formulaData = '';
- for ($j = 0; $j < $countPrintArea; ++$j) {
- $printAreaRect = $printArea[$j];
- $printAreaRect[0] = PHPExcel_Cell::coordinateFromString($printAreaRect[0]);
- $printAreaRect[1] = PHPExcel_Cell::coordinateFromString($printAreaRect[1]);
- $print_rowmin = $printAreaRect[0][1] - 1;
- $print_rowmax = $printAreaRect[1][1] - 1;
- $print_colmin = PHPExcel_Cell::columnIndexFromString($printAreaRect[0][0]) - 1;
- $print_colmax = PHPExcel_Cell::columnIndexFromString($printAreaRect[1][0]) - 1;
-
- $formulaData .= pack('Cvvvvv', 0x3B, $i, $print_rowmin, $print_rowmax, $print_colmin, $print_colmax);
- if ($j > 0) {
- $formulaData .= pack('C', 0x10);
- }
- }
-
- $chunk .= $this->writeData($this->writeDefinedNameBiff8(pack('C', 0x06), $formulaData, $i + 1, true));
- }
- }
-
- for ($i = 0; $i < $total_worksheets; ++$i) {
- $sheetAutoFilter = $this->phpExcel->getSheet($i)->getAutoFilter();
- $autoFilterRange = $sheetAutoFilter->getRange();
- if (!empty($autoFilterRange)) {
- $rangeBounds = PHPExcel_Cell::rangeBoundaries($autoFilterRange);
-
- $name = pack('C', 0x0D);
- $chunk .= $this->writeData($this->writeShortNameBiff8($name, $i + 1, $rangeBounds, true));
- }
- }
- return $chunk;
- }
-
- private function writeDefinedNameBiff8($name, $formulaData, $sheetIndex = 0, $isBuiltIn = false)
- {
- $record = 0x0018;
-
- $options = $isBuiltIn ? 0x20 : 0x00;
-
- $nlen = PHPExcel_Shared_String::CountCharacters($name);
-
- $name = substr(PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($name), 2);
-
- $sz = strlen($formulaData);
-
- $data = pack('vCCvvvCCCC', $options, 0, $nlen, $sz, 0, $sheetIndex, 0, 0, 0, 0)
- . $name . $formulaData;
- $length = strlen($data);
- $header = pack('vv', $record, $length);
- return $header . $data;
- }
-
- private function writeShortNameBiff8($name, $sheetIndex = 0, $rangeBounds, $isHidden = false)
- {
- $record = 0x0018;
-
- $options = ($isHidden ? 0x21 : 0x00);
- $extra = pack(
- 'Cvvvvv',
- 0x3B,
- $sheetIndex - 1,
- $rangeBounds[0][1] - 1,
- $rangeBounds[1][1] - 1,
- $rangeBounds[0][0] - 1,
- $rangeBounds[1][0] - 1
- );
-
- $sz = strlen($extra);
-
- $data = pack('vCCvvvCCCCC', $options, 0, 1, $sz, 0, $sheetIndex, 0, 0, 0, 0, 0)
- . $name . $extra;
- $length = strlen($data);
- $header = pack('vv', $record, $length);
- return $header . $data;
- }
-
- private function writeCodepage()
- {
- $record = 0x0042;
- $length = 0x0002;
- $cv = $this->codepage;
- $header = pack('vv', $record, $length);
- $data = pack('v', $cv);
- $this->append($header . $data);
- }
-
- private function writeWindow1()
- {
- $record = 0x003D;
- $length = 0x0012;
- $xWn = 0x0000;
- $yWn = 0x0000;
- $dxWn = 0x25BC;
- $dyWn = 0x1572;
- $grbit = 0x0038;
-
- $ctabsel = 1;
- $wTabRatio = 0x0258;
-
- $itabFirst = 0;
- $itabCur = $this->phpExcel->getActiveSheetIndex();
- $header = pack("vv", $record, $length);
- $data = pack("vvvvvvvvv", $xWn, $yWn, $dxWn, $dyWn, $grbit, $itabCur, $itabFirst, $ctabsel, $wTabRatio);
- $this->append($header . $data);
- }
-
- private function writeBoundSheet($sheet, $offset)
- {
- $sheetname = $sheet->getTitle();
- $record = 0x0085;
-
- switch ($sheet->getSheetState()) {
- case PHPExcel_Worksheet::SHEETSTATE_VISIBLE:
- $ss = 0x00;
- break;
- case PHPExcel_Worksheet::SHEETSTATE_HIDDEN:
- $ss = 0x01;
- break;
- case PHPExcel_Worksheet::SHEETSTATE_VERYHIDDEN:
- $ss = 0x02;
- break;
- default:
- $ss = 0x00;
- break;
- }
-
- $st = 0x00;
- $grbit = 0x0000;
- $data = pack("VCC", $offset, $ss, $st);
- $data .= PHPExcel_Shared_String::UTF8toBIFF8UnicodeShort($sheetname);
- $length = strlen($data);
- $header = pack("vv", $record, $length);
- $this->append($header . $data);
- }
-
- private function writeSupbookInternal()
- {
- $record = 0x01AE;
- $length = 0x0004;
- $header = pack("vv", $record, $length);
- $data = pack("vv", $this->phpExcel->getSheetCount(), 0x0401);
- return $this->writeData($header . $data);
- }
-
- private function writeExternalsheetBiff8()
- {
- $totalReferences = count($this->parser->references);
- $record = 0x0017;
- $length = 2 + 6 * $totalReferences;
- $supbook_index = 0;
- $header = pack("vv", $record, $length);
- $data = pack('v', $totalReferences);
- for ($i = 0; $i < $totalReferences; ++$i) {
- $data .= $this->parser->references[$i];
- }
- return $this->writeData($header . $data);
- }
-
- private function writeStyle()
- {
- $record = 0x0293;
- $length = 0x0004;
- $ixfe = 0x8000;
- $BuiltIn = 0x00;
- $iLevel = 0xff;
- $header = pack("vv", $record, $length);
- $data = pack("vCC", $ixfe, $BuiltIn, $iLevel);
- $this->append($header . $data);
- }
-
- private function writeNumberFormat($format, $ifmt)
- {
- $record = 0x041E;
- $numberFormatString = PHPExcel_Shared_String::UTF8toBIFF8UnicodeLong($format);
- $length = 2 + strlen($numberFormatString);
- $header = pack("vv", $record, $length);
- $data = pack("v", $ifmt) . $numberFormatString;
- $this->append($header . $data);
- }
-
- private function writeDateMode()
- {
- $record = 0x0022;
- $length = 0x0002;
- $f1904 = (PHPExcel_Shared_Date::getExcelCalendar() == PHPExcel_Shared_Date::CALENDAR_MAC_1904)
- ? 1
- : 0;
- $header = pack("vv", $record, $length);
- $data = pack("v", $f1904);
- $this->append($header . $data);
- }
-
- private function writeExternalCount($cxals)
- {
- $record = 0x0016;
- $length = 0x0002;
- $header = pack("vv", $record, $length);
- $data = pack("v", $cxals);
- $this->append($header . $data);
- }
-
- private function writeExternalSheet($sheetname)
- {
- $record = 0x0017;
- $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 writeNameShort($index, $type, $rowmin, $rowmax, $colmin, $colmax)
- {
- $record = 0x0018;
- $length = 0x0024;
- $grbit = 0x0020;
- $chKey = 0x00;
- $cch = 0x01;
- $cce = 0x0015;
- $ixals = $index + 1;
- $itab = $ixals;
- $cchCustMenu = 0x00;
- $cchDescription = 0x00;
- $cchHelptopic = 0x00;
- $cchStatustext = 0x00;
- $rgch = $type;
- $unknown03 = 0x3b;
- $unknown04 = 0xffff - $index;
- $unknown05 = 0x0000;
- $unknown06 = 0x0000;
- $unknown07 = 0x1087;
- $unknown08 = 0x8005;
- $header = pack("vv", $record, $length);
- $data = pack("v", $grbit);
- $data .= pack("C", $chKey);
- $data .= pack("C", $cch);
- $data .= pack("v", $cce);
- $data .= pack("v", $ixals);
- $data .= pack("v", $itab);
- $data .= pack("C", $cchCustMenu);
- $data .= pack("C", $cchDescription);
- $data .= pack("C", $cchHelptopic);
- $data .= pack("C", $cchStatustext);
- $data .= pack("C", $rgch);
- $data .= pack("C", $unknown03);
- $data .= pack("v", $unknown04);
- $data .= pack("v", $unknown05);
- $data .= pack("v", $unknown06);
- $data .= pack("v", $unknown07);
- $data .= pack("v", $unknown08);
- $data .= pack("v", $index);
- $data .= pack("v", $index);
- $data .= pack("v", $rowmin);
- $data .= pack("v", $rowmax);
- $data .= pack("C", $colmin);
- $data .= pack("C", $colmax);
- $this->append($header . $data);
- }
-
- private function writeNameLong($index, $type, $rowmin, $rowmax, $colmin, $colmax)
- {
- $record = 0x0018;
- $length = 0x003d;
- $grbit = 0x0020;
- $chKey = 0x00;
- $cch = 0x01;
- $cce = 0x002e;
- $ixals = $index + 1;
- $itab = $ixals;
- $cchCustMenu = 0x00;
- $cchDescription = 0x00;
- $cchHelptopic = 0x00;
- $cchStatustext = 0x00;
- $rgch = $type;
- $unknown01 = 0x29;
- $unknown02 = 0x002b;
- $unknown03 = 0x3b;
- $unknown04 = 0xffff-$index;
- $unknown05 = 0x0000;
- $unknown06 = 0x0000;
- $unknown07 = 0x1087;
- $unknown08 = 0x8008;
- $header = pack("vv", $record, $length);
- $data = pack("v", $grbit);
- $data .= pack("C", $chKey);
- $data .= pack("C", $cch);
- $data .= pack("v", $cce);
- $data .= pack("v", $ixals);
- $data .= pack("v", $itab);
- $data .= pack("C", $cchCustMenu);
- $data .= pack("C", $cchDescription);
- $data .= pack("C", $cchHelptopic);
- $data .= pack("C", $cchStatustext);
- $data .= pack("C", $rgch);
- $data .= pack("C", $unknown01);
- $data .= pack("v", $unknown02);
-
- $data .= pack("C", $unknown03);
- $data .= pack("v", $unknown04);
- $data .= pack("v", $unknown05);
- $data .= pack("v", $unknown06);
- $data .= pack("v", $unknown07);
- $data .= pack("v", $unknown08);
- $data .= pack("v", $index);
- $data .= pack("v", $index);
- $data .= pack("v", 0x0000);
- $data .= pack("v", 0x3fff);
- $data .= pack("C", $colmin);
- $data .= pack("C", $colmax);
-
- $data .= pack("C", $unknown03);
- $data .= pack("v", $unknown04);
- $data .= pack("v", $unknown05);
- $data .= pack("v", $unknown06);
- $data .= pack("v", $unknown07);
- $data .= pack("v", $unknown08);
- $data .= pack("v", $index);
- $data .= pack("v", $index);
- $data .= pack("v", $rowmin);
- $data .= pack("v", $rowmax);
- $data .= pack("C", 0x00);
- $data .= pack("C", 0xff);
-
- $data .= pack("C", 0x10);
- $this->append($header . $data);
- }
-
- private function writeCountry()
- {
- $record = 0x008C;
- $length = 4;
- $header = pack('vv', $record, $length);
-
- $data = pack('vv', $this->countryCode, $this->countryCode);
-
- return $this->writeData($header . $data);
- }
-
- private function writeRecalcId()
- {
- $record = 0x01C1;
- $length = 8;
- $header = pack('vv', $record, $length);
-
- $data = pack('VV', 0x000001C1, 0x00001E667);
- return $this->writeData($header . $data);
- }
-
- private function writePalette()
- {
- $aref = $this->palette;
- $record = 0x0092;
- $length = 2 + 4 * count($aref);
- $ccv = count($aref);
- $data = '';
-
- foreach ($aref as $color) {
- foreach ($color as $byte) {
- $data .= pack("C", $byte);
- }
- }
- $header = pack("vvv", $record, $length, $ccv);
- $this->append($header . $data);
- }
-
- private function writeSharedStringsTable()
- {
-
- $continue_limit = 8224;
-
- $recordDatas = array();
-
- $recordData = pack("VV", $this->stringTotal, $this->stringUnique);
-
- foreach (array_keys($this->stringTable) as $string) {
-
-
- $headerinfo = unpack("vlength/Cencoding", $string);
-
- $encoding = $headerinfo["encoding"];
-
- $finished = false;
- while ($finished === false) {
-
-
-
- if (strlen($recordData) + strlen($string) <= $continue_limit) {
-
- $recordData .= $string;
- if (strlen($recordData) + strlen($string) == $continue_limit) {
-
- $recordDatas[] = $recordData;
- $recordData = '';
- }
-
- $finished = true;
- } else {
-
-
-
- $space_remaining = $continue_limit - strlen($recordData);
-
-
-
- $min_space_needed = ($encoding == 1) ? 5 : 4;
-
-
-
-
-
-
- if ($space_remaining < $min_space_needed) {
-
- $recordDatas[] = $recordData;
-
- $recordData = '';
-
- } else {
-
- $effective_space_remaining = $space_remaining;
-
- if ($encoding == 1 && (strlen($string) - $space_remaining) % 2 == 1) {
- --$effective_space_remaining;
- }
-
- $recordData .= substr($string, 0, $effective_space_remaining);
- $string = substr($string, $effective_space_remaining);
- $recordDatas[] = $recordData;
-
- $recordData = pack('C', $encoding);
- }
- }
- }
- }
-
-
- if (strlen($recordData) > 0) {
- $recordDatas[] = $recordData;
- }
-
- $chunk = '';
- foreach ($recordDatas as $i => $recordData) {
-
- $record = ($i == 0) ? 0x00FC : 0x003C;
- $header = pack("vv", $record, strlen($recordData));
- $data = $header . $recordData;
- $chunk .= $this->writeData($data);
- }
- return $chunk;
- }
-
- private function writeMsoDrawingGroup()
- {
-
- if (isset($this->escher)) {
- $writer = new PHPExcel_Writer_Excel5_Escher($this->escher);
- $data = $writer->close();
- $record = 0x00EB;
- $length = strlen($data);
- $header = pack("vv", $record, $length);
- return $this->writeData($header . $data);
- } else {
- return '';
- }
- }
-
- public function getEscher()
- {
- return $this->escher;
- }
-
- public function setEscher(PHPExcel_Shared_Escher $pValue = null)
- {
- $this->escher = $pValue;
- }
- }
|