/** * Read LABEL record * This record represents a cell that contains a string. In * BIFF8 it is usually replaced by the LABELSST record. * Excel still uses this record, if it copies unformatted * text cells to the clipboard. * * -- "OpenOffice.org's Documentation of the Microsoft * Excel File Format" */ private function _readLabel() { $length = $this->_GetInt2d($this->_data, $this->_pos + 2); $recordData = substr($this->_data, $this->_pos + 4, $length); // move stream pointer to next record $this->_pos += 4 + $length; // offset: 0; size: 2; index to row $row = $this->_GetInt2d($recordData, 0); // offset: 2; size: 2; index to column $column = $this->_GetInt2d($recordData, 2); $columnString = PHPExcel_Cell::stringFromColumnIndex($column); // Read cell? if (!is_null($this->getReadFilter()) && $this->getReadFilter()->readCell($columnString, $row + 1, $this->_phpSheet->getTitle())) { // offset: 4; size: 2; XF index $xfIndex = $this->_GetInt2d($recordData, 4); // add cell value // todo: what if string is very long? continue record if ($this->_version == self::XLS_BIFF8) { $string = $this->_readUnicodeStringLong(substr($recordData, 6)); $value = $string['value']; } else { $string = $this->_readByteStringLong(substr($recordData, 6)); $value = $string['value']; } $this->_phpSheet->setCellValueExplicit($columnString . ($row + 1), $value, PHPExcel_Cell_DataType::TYPE_STRING); // add cell style if (!$this->_readDataOnly) { $this->_phpSheet->getCell($columnString . ($row + 1))->setXfIndex($this->_mapCellXfIndex[$xfIndex]); } } }
/** * Write the content of the "DC Inventory" worksheet * * @param PHPExcel_Worksheet $worksheet * @param array $sheetProps properties of the worksheet * @param array $invData array with the inventory data */ function writeDCInvContent($worksheet, $sheetProps, $invData) { $colIdx = $sheetProps['ColIdx']; // first line is the header for the worksheet $worksheet->fromArray($invData, null, 'A2'); ReportStats::get()->report('Info', 'Number of Inventory entries ' . count($invData)); $highestRow = count($invData); foreach ($sheetProps['ExpStr'] as $colName) { $colLetter = $colIdx[$colName][1]; for ($row = 0; $row < $highestRow; $row++) { $worksheet->setCellValueExplicit($colLetter . ($row + 2), $invData[$row][$colName], PHPExcel_Cell_DataType::TYPE_STRING); } } // unset($invData); }
/** * Sets cells of a single row * * @param int $row * @param mixed $cell_values * @param boolean $header * @return Worksheet */ private function _set_row($row, &$data, $header = FALSE) { $column = 0; $format = NULL; $type = PHPExcel_Cell_DataType::TYPE_STRING; foreach ($this->columns as $key => $name) { $value = NULL; if (is_array($data)) { $value = $data[$key]; } elseif (is_object($data)) { if (method_exists($data, $key)) { $value = $data->{$key}(); } elseif (isset($data->{$key})) { $value = $data->{$key}; } } // Determine cell type and format if ($header === FALSE) { $type = Arr::get($this->types, $key); } // Set cell value $coordinates = PHPExcel_Cell::stringFromColumnIndex($column) . $row; if ($type !== NULL) { $this->_worksheet->setCellValueExplicit($coordinates, $value, $type); } else { $this->_worksheet->setCellValue($coordinates, $value); } $column++; } return $this; }
/** * Sets cells of a single row * * @param int $row * @param mixed $cell_values * @param boolean $header * @return Worksheet */ private function _set_row($row, &$data, $header = FALSE) { $column = 0; $type = PHPExcel_Cell_DataType::TYPE_STRING; foreach (array_keys($this->columns) as $key) { $value = NULL; if (is_array($data)) { $value = isset($data[$key]) ? $data[$key] : ''; } elseif (is_object($data)) { if (method_exists($data, $key)) { $value = $data->{$key}(); } elseif (isset($data->{$key})) { $value = $data->{$key}; } } // Determine cell type and format if ($header === FALSE) { $type = Arr::get($this->types, $key); } $coordinates = PHPExcel_Cell::stringFromColumnIndex($column) . $row; // Options if (is_array($value)) { $options = array_slice($value, 1); $validation = $this->_worksheet->getCell($coordinates)->getDataValidation(); $validation->setType(PHPExcel_Cell_DataValidation::TYPE_LIST); $validation->setAllowBlank(TRUE); $validation->setShowDropDown(TRUE); $validation->setFormula1('"' . join(',', $options) . '"'); $value = $value[0]; } // Set cell value if ($type !== NULL) { $this->_worksheet->setCellValueExplicit($coordinates, $value, $type); } else { $this->_worksheet->setCellValue($coordinates, $value); } $column++; } return $this; }