Esempio n. 1
0
 /**
  * @throws \Exception
  */
 public function testRich()
 {
     $sheet = $this->workbook->addWorksheet('New PC');
     $headerFormat = $this->getHeaderFormat();
     $sheet->writeRow(0, 0, array('Title', 'Count', 'Price', 'Amount'), $headerFormat);
     $cellFormat = $this->getCellFormat();
     $countFormat = $this->getCountFormat();
     $priceFormat = $this->getPriceFormat();
     $partNames = array('Intel Core i7 2600K', 'ASUS P8P67', 'DDR2-800 8Gb');
     $sheet->writeCol(1, 0, $partNames, $cellFormat);
     $sheet->writeCol(1, 1, array(1, 1, 4), $countFormat);
     $sheet->writeCol(1, 2, array(500, 325, 100.15), $priceFormat);
     //should be written as formulas
     $sheet->writeCol(1, 3, array('=B2*C2', '=B3*C3', '=B4*C4'), $priceFormat);
     $grandFormat = $this->getGrandTotalFormat();
     $this->assertTrue(NumberFormat::isBuiltIn($grandFormat->getNumFormat()));
     $sheet->writeRow(10, 0, array('Total', '', ''), $grandFormat);
     $sheet->mergeCells(10, 0, 10, 2);
     $sheet->writeFormula(10, 3, '=sum(D2:D10)', $this->getOldPriceFormat());
     $sheet->writeRow(11, 0, array('Grand total', '', ''), $grandFormat);
     $sheet->mergeCells(11, 0, 11, 2);
     //should be written as formula
     $sheet->write(11, 3, '=ROUND(D11-D11*0.2, 2)', $grandFormat);
     $sheet->write(11, 4, '20% скидка!', $this->getDiscountFormat());
     $sheet->write(11, 5, 'subscript', $this->getSubscriptFormat());
     $sheet->setColumnWidth(0, 20);
     $sheet->setColumnWidth(3, 15);
     $anotherSheet = $this->workbook->addWorksheet('Лист2');
     $anotherSheet->write(0, 0, 'Тест');
     $this->workbook->save($this->testFilePath);
     $this->assertTestFileEqualsTo('rich');
 }
Esempio n. 2
0
 /**
  * Store user defined numerical formats i.e. FORMAT records
  */
 protected function storeAllNumFormats()
 {
     $map = array();
     $index = 164;
     // Iterate through the XF objects and write a FORMAT record if it isn't a
     // built-in format type and if the FORMAT string hasn't already been used.
     foreach ($this->formats as $format) {
         $numFormat = $format->getNumFormat();
         if (NumberFormat::isBuiltIn($numFormat)) {
             $format->setNumFormatIndex($numFormat);
             continue;
         }
         if (!isset($map[$numFormat])) {
             // Add a new FORMAT
             $map[$numFormat] = 1;
             $format->setNumFormatIndex($index);
             $this->appendRecord('Format', array($numFormat, $index));
             $index++;
         }
     }
 }