Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 22... Línea 22...
22
use OpenSpout\Writer\XLSX\Options;
22
use OpenSpout\Writer\XLSX\Options;
Línea 23... Línea 23...
23
 
23
 
24
/**
24
/**
25
 * @internal
25
 * @internal
26
 */
26
 */
27
final class WorksheetManager implements WorksheetManagerInterface
27
final readonly class WorksheetManager implements WorksheetManagerInterface
28
{
28
{
29
    /**
29
    /**
30
     * Maximum number of characters a cell can contain.
30
     * Maximum number of characters a cell can contain.
31
     *
31
     *
Línea 34... Línea 34...
34
     * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-ca36e2dc-1f09-4620-b726-67c00b05040f [Excel 2013/2016]
34
     * @see https://support.office.com/en-us/article/Excel-specifications-and-limits-ca36e2dc-1f09-4620-b726-67c00b05040f [Excel 2013/2016]
35
     */
35
     */
36
    public const MAX_CHARACTERS_PER_CELL = 32767;
36
    public const MAX_CHARACTERS_PER_CELL = 32767;
Línea 37... Línea 37...
37
 
37
 
38
    /** @var CommentsManager Manages comments */
38
    /** @var CommentsManager Manages comments */
Línea 39... Línea 39...
39
    private readonly CommentsManager $commentsManager;
39
    private CommentsManager $commentsManager;
Línea 40... Línea 40...
40
 
40
 
41
    private readonly Options $options;
41
    private Options $options;
Línea 42... Línea 42...
42
 
42
 
43
    /** @var StyleManager Manages styles */
43
    /** @var StyleManager Manages styles */
Línea 44... Línea 44...
44
    private readonly StyleManager $styleManager;
44
    private StyleManager $styleManager;
45
 
45
 
Línea 46... Línea 46...
46
    /** @var StyleMerger Helper to merge styles together */
46
    /** @var StyleMerger Helper to merge styles together */
47
    private readonly StyleMerger $styleMerger;
47
    private StyleMerger $styleMerger;
Línea 48... Línea 48...
48
 
48
 
49
    /** @var SharedStringsManager Helper to write shared strings */
49
    /** @var SharedStringsManager Helper to write shared strings */
Línea 50... Línea 50...
50
    private readonly SharedStringsManager $sharedStringsManager;
50
    private SharedStringsManager $sharedStringsManager;
51
 
51
 
52
    /** @var XLSXEscaper Strings escaper */
52
    /** @var XLSXEscaper Strings escaper */
53
    private readonly XLSXEscaper $stringsEscaper;
53
    private XLSXEscaper $stringsEscaper;
Línea 196... Línea 196...
196
        } elseif ($cell instanceof Cell\BooleanCell) {
196
        } elseif ($cell instanceof Cell\BooleanCell) {
197
            $cellXML .= ' t="b"><v>'.(int) $cell->getValue().'</v></c>';
197
            $cellXML .= ' t="b"><v>'.(int) $cell->getValue().'</v></c>';
198
        } elseif ($cell instanceof Cell\NumericCell) {
198
        } elseif ($cell instanceof Cell\NumericCell) {
199
            $cellXML .= '><v>'.$cell->getValue().'</v></c>';
199
            $cellXML .= '><v>'.$cell->getValue().'</v></c>';
200
        } elseif ($cell instanceof Cell\FormulaCell) {
200
        } elseif ($cell instanceof Cell\FormulaCell) {
201
            $cellXML .= '><f>'.substr($cell->getValue(), 1).'</f></c>';
201
            $cellXML .= '><f>'.$this->stringsEscaper->escape(substr($cell->getValue(), 1)).'</f></c>';
202
        } elseif ($cell instanceof Cell\DateTimeCell) {
202
        } elseif ($cell instanceof Cell\DateTimeCell) {
203
            $cellXML .= '><v>'.DateHelper::toExcel($cell->getValue()).'</v></c>';
203
            $cellXML .= '><v>'.DateHelper::toExcel($cell->getValue()).'</v></c>';
204
        } elseif ($cell instanceof Cell\DateIntervalCell) {
204
        } elseif ($cell instanceof Cell\DateIntervalCell) {
205
            $cellXML .= '><v>'.DateIntervalHelper::toExcel($cell->getValue()).'</v></c>';
205
            $cellXML .= '><v>'.DateIntervalHelper::toExcel($cell->getValue()).'</v></c>';
206
        } elseif ($cell instanceof Cell\ErrorCell) {
206
        } elseif ($cell instanceof Cell\ErrorCell) {
207
            // only writes the error value if it's a string
207
            // only writes the error value if it's a string
208
            $cellXML .= ' t="e"><v>'.$cell->getRawValue().'</v></c>';
208
            $cellXML .= ' t="e"><v>'.$this->stringsEscaper->escape($cell->getRawValue()).'</v></c>';
209
        } elseif ($cell instanceof Cell\EmptyCell) {
209
        } elseif ($cell instanceof Cell\EmptyCell) {
210
            if ($this->styleManager->shouldApplyStyleOnEmptyCell($styleId)) {
210
            if ($this->styleManager->shouldApplyStyleOnEmptyCell($styleId)) {
211
                $cellXML .= '/>';
211
                $cellXML .= '/>';
212
            } else {
212
            } else {
213
                // don't write empty cells that do no need styling
213
                // don't write empty cells that do no need styling