Format a CSV cell.

@param string|object $cell

@return string
426435
private function formatCell($cell)
    {
        // Cast cell data to a string.
        $cell = (string) $cell;

        // Enclose the cell in double quotes, if necessary.
        if (strpbrk($cell, '"' . $this->lineBreak . $this->delimiter) !== false) {
            $cell = '"' . str_replace('"', '""', $cell) . '"';
        }

        // Standardize line breaks.
        $cell = preg_replace('/\R/u', $this->lineBreak, $cell);

        return $cell;
    }
139071
public function formatOfficeLocation(string $office): string
    {
        $office = strtoupper(trim($office));
        $rightAlpha = preg_replace('/[^A-Z]/', '', substr($office, -1));
        $numbersOnly = substr('0000'.($this->getNumbersOnly($office) * 1), -4);

        $numbersOnly = substr($numbersOnly, 0, 2) === '04'
            ? 'B'.substr($numbersOnly, 1, 4)
            : $numbersOnly;

        return ('' === $office || 'NONE' === $office)
            ? 'None'
            : sprintf('%s %s%s', 'AP&M', $numbersOnly, $rightAlpha);
    }
460373
function formatCSV(values) {
    if (values instanceof Array) {
        return values.map(v => formatValue(v)).join();
    }
    if (typeof values === 'object' && values !== null) {
        return Object.keys(values).map(v => formatValue(values[v])).join();
    }
    return values === undefined ? '' : formatValue(values);
}
1303779
protected function formatRow($row)
    {
        foreach ($row as &$column) {
            if (!is_scalar($column)) {
                $column = $this->serialize($column);
            }
            switch ($this->quoting) {
                case self::QUOTE_NONE:
                    // do nothing... no quoting is happening here
                    break;
                case self::QUOTE_ALL:
                    $column = $this->quote($this->escape($column));
                    break;
                case self::QUOTE_NONNUMERIC:
                    if (preg_match("/[^0-9]/", $column)) {
                        $column = $this->quote($this->escape($column));
                    }
                    break;
                case self::QUOTE_MINIMAL:
                default:
                    if ($this->containsSpecialChars($column)) {
                        $column = $this->quote($this->escape($column));
                    }
                    break;
            }
        }

        return $row;
    }
436339
public function format(): Format\Format
    {
        if (null === $this->format) {
            $this->format = Format\Format::fromJson($this);
        }

        return $this->format;
    }
400655
private function renderCell(array $row, $column, $cellFormat)
    {
        $cell = isset($row[$column]) ? $row[$column] : '';
        $width = $this->effectiveColumnWidths[$column];
        if ($cell instanceof TableCell && $cell->getColspan() > 1) {
            // add the width of the following columns(numbers of colspan).
            foreach (range($column + 1, $column + $cell->getColspan() - 1) as $nextColumn) {
                $width += $this->getColumnSeparatorWidth() + $this->effectiveColumnWidths[$nextColumn];
            }
        }

        // str_pad won't work properly with multi-byte strings, we need to fix the padding
        if (false !== $encoding = mb_detect_encoding($cell, null, true)) {
            $width += strlen($cell) - mb_strwidth($cell, $encoding);
        }

        $style = $this->getColumnStyle($column);

        if ($cell instanceof TableSeparator) {
            return sprintf($style->getBorderFormat(), str_repeat($style->getHorizontalBorderChar(), $width));
        }

        $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
        $content = sprintf($style->getCellRowContentFormat(), $cell);

        return sprintf($cellFormat, str_pad($content, $width, $style->getPaddingChar(), $style->getPadType()));
    }
1315718
protected function formatDateCellValue($node)
    {
        // The XML node looks like this:
        // <table:table-cell calcext:value-type="date" office:date-value="2016-05-19T16:39:00" office:value-type="date">
        //   <text:p>05/19/16 04:39 PM</text:p>
        // </table:table-cell>

        if ($this->shouldFormatDates) {
            // The date is already formatted in the "p" tag
            $nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0);
            return $nodeWithValueAlreadyFormatted->nodeValue;
        } else {
            // otherwise, get it from the "date-value" attribute
            try {
                $nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_DATE_VALUE);
                return new \DateTime($nodeValue);
            } catch (\Exception $e) {
                return null;
            }
        }
    }
1071615
protected function format(string $string): string
	{
		$lineWidth = $this->width - (static::PADDING * 2);

		$lines = explode(PHP_EOL, PHP_EOL . $this->wordWrap($string, $lineWidth) . PHP_EOL);

		foreach($lines as $key => $value)
		{
			$value = $this->escape($value) . str_repeat(' ', $lineWidth - mb_strlen($value));

			$lines[$key] = sprintf('%1$s%2$s%1$s', str_repeat(' ', static::PADDING), $value);
		}

		return implode(PHP_EOL, $lines);
	}
1174527
function addFormat($properties = array())
    {
        $format = new Spreadsheet_Excel_Writer_Format($this->_BIFF_version, $this->_xf_index, $properties);
        $this->_xf_index += 1;
        $this->_formats[] = $format;
        return $format;
    }
1345968
protected function __cells():string{
		$abbr    = $this->getAttribute('abbr');
		$colspan = $this->getAttribute('colspan');
		$rowspan = $this->getAttribute('rowspan');

		if($colspan){
			$colspan = ' colspan="'.intval($colspan).'"';
		}

		if($rowspan){
			$rowspan = ' rowspan="'.intval($rowspan).'"';
		}

		if($this->tag === 'th' && $abbr){
			$abbr = ' abbr="'.$abbr.'"';
		}

		return '<'.$this->tag.$colspan.$rowspan.$abbr.$this->__getCellStyle().'>'.$this->eol($this->content, '<br/>').'</'.$this->tag.'>';
	}
574954
public function format(AbstractColumn $column)
    {
        $data = $this->getRowData();
        if ($this->isApply() === true) {
            return $this->getFormattedValue($column);
        }

        return $data[$column->getUniqueId()];
    }
659604
protected function formatInlineStringCellValue($node)
    {
        // inline strings are formatted this way:
        // <c r="A1" t="inlineStr"><is><t>[INLINE_STRING]</t></is></c>
        $tNode = $node->getElementsByTagName(self::XML_NODE_INLINE_STRING_VALUE)->item(0);
        $cellValue = $this->escaper->unescape($tNode->nodeValue);
        return $cellValue;
    }
490534
private function getCellWidth($cell)
    {
        $lineWidths = [0];
        foreach (explode(PHP_EOL, $cell) as $line) {
            $lineWidths[] = Helper::strlenWithoutDecoration($this->outputCopy->getFormatter(), $line);
        }
        $cellWidth = max($lineWidths);
        if ($cell instanceof TableCell && $cell->getColspan() > 1) {
            $cellWidth /= $cell->getColspan();
        }

        return $cellWidth;
    }
389325
public function cell(string $content = '') : ContentCell
    {
        $this->addCell($cell = new ContentCell);

        if ($content) {
            $cell->content($content);
        }

        return $cell;
    }
792403
public function format($data)
    {
        $data->loopThrough(function ($key, $value) use ($data) {
            if (!in_array($key, $this->fields)) {
                $data->setProperty($key, null);
            }
        });

        $data->unsetNull();

        return $data;
    }
41803
protected function collapseCell($cell, $column)
    {
        //compress a complex cell
        if (is_array($cell)) {
            $cell = isset($cell['data']) ? $cell['data'] : '';
        }

        if (!$this->format->html) {
            $cell = strip_tags($cell);
        }

        // Escape chars that conflice with delimiters
        if (!empty($this->format->escape)) {
            $escapeables = array($this->format->left, $this->format->right);
            $escapeables = array_filter(array_unique($escapeables));
            foreach ($escapeables as $find) {
                $cell = str_replace($find, $this->format->escape . $find, $cell);
            }
        }

        return $this->format->left . $cell . $this->format->right;
    }
600953
public String formatAsString(final ObjectCell<?> cell, final Locale locale) {
        return format(cell, locale).getText();
    }