<commit_before><?php
namespace Imtigger\OneExcel\Writer;

use Imtigger\OneExcel\OneExcelWriterInterface;

class LibXLWriter extends OneExcelWriter implements OneExcelWriterInterface
{
    public static $input_format_supported = [self::FORMAT_XLSX, self::FORMAT_XLS];
    public static $output_format_supported = [self::FORMAT_XLSX, self::FORMAT_XLS];
    public static $input_output_same_format = true;
    private $book;
    private $sheet;
    private $input_format;
    private $output_format;

    public function create($output_format = self::FORMAT_XLSX)
    {
        $this->checkFormatSupported($output_format);
        $this->output_format = $output_format;
        $this->book = new \ExcelBook(null, null, $this->output_format == self::FORMAT_XLSX);
        $this->book->setLocale('UTF-8');
        $this->sheet = $this->book->addSheet('Sheet1');
    }

    public function load($filename, $output_format = self::FORMAT_XLSX, $input_format = self::FORMAT_AUTO)
    {
        $this->autoDetectInputFormat($filename, $input_format);
        $this->checkFormatSupported($output_format, $input_format);

        $this->input_format = $input_format;
        $this->output_format = $output_format;

        $this->book = new \ExcelBook(null, null, $this->output_format == self::FORMAT_XLSX);
        $this->book->loadFile($filename);
        $this->book->setLocale('UTF-8');
        $this->sheet = $this->book->getSheet(0);
    }

    public function writeCell($row_num, $column_num, $data, $data_type = self::COLUMN_TYPE_STRING)
    {
        $this->sheet->write($row_num - 1, $column_num, $data, null, $this->getColumnFormat($data_type));
    }

    public function save($path)
    {
        $this->book->save($path);
    }

    public function download($filename)
    {
        header('Content-Type: ' . $this->getFormatMime($this->output_format));
        header('Content-Disposition: attachment; filename="libxl-' . $filename . '.' . $this->output_format . '"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Pragma: no-cache');

        $this->save('php://output');
        exit;
    }

    public function getColumnFormat($internal_format)
    {
        switch ($internal_format) {
            case self::COLUMN_TYPE_STRING:
                return -1;
            case self::COLUMN_TYPE_NUMERIC:
                return ExcelFormat::AS_NUMERIC_STRING;
            case self::COLUMN_TYPE_FORMULA:
                return ExcelFormat::AS_FORMULA;
        }
        return -1;
    }
}<commit_msg>Fixed error for LibXL<commit_after><?php
namespace Imtigger\OneExcel\Writer;

use Imtigger\OneExcel\OneExcelWriterInterface;

class LibXLWriter extends OneExcelWriter implements OneExcelWriterInterface
{
    public static $input_format_supported = [self::FORMAT_XLSX, self::FORMAT_XLS];
    public static $output_format_supported = [self::FORMAT_XLSX, self::FORMAT_XLS];
    public static $input_output_same_format = true;
    private $book;
    private $sheet;
    private $input_format;
    private $output_format;

    public function create($output_format = self::FORMAT_XLSX)
    {
        $this->checkFormatSupported($output_format);
        $this->output_format = $output_format;
        $this->book = new \ExcelBook(null, null, $this->output_format == self::FORMAT_XLSX);
        $this->book->setLocale('UTF-8');
        $this->sheet = $this->book->addSheet('Sheet1');
    }

    public function load($filename, $output_format = self::FORMAT_XLSX, $input_format = self::FORMAT_AUTO)
    {
        $this->autoDetectInputFormat($filename, $input_format);
        $this->checkFormatSupported($output_format, $input_format);

        $this->input_format = $input_format;
        $this->output_format = $output_format;

        $this->book = new \ExcelBook(null, null, $this->output_format == self::FORMAT_XLSX);
        $this->book->loadFile($filename);
        $this->book->setLocale('UTF-8');
        $this->sheet = $this->book->getSheet(0);
    }

    public function writeCell($row_num, $column_num, $data, $data_type = self::COLUMN_TYPE_STRING)
    {
        $this->sheet->write($row_num - 1, $column_num, $data, null, $this->getColumnFormat($data_type));
    }

    public function save($path)
    {
        $this->book->save($path);
    }

    public function download($filename)
    {
        header('Content-Type: ' . $this->getFormatMime($this->output_format));
        header('Content-Disposition: attachment; filename="libxl-' . $filename . '.' . $this->output_format . '"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Pragma: no-cache');

        $this->save('php://output');
        exit;
    }

    public function getColumnFormat($internal_format)
    {
        switch ($internal_format) {
            case self::COLUMN_TYPE_STRING:
                return -1;
            case self::COLUMN_TYPE_NUMERIC:
                return \ExcelFormat::AS_NUMERIC_STRING;
            case self::COLUMN_TYPE_FORMULA:
                return \ExcelFormat::AS_FORMULA;
        }
        return -1;
    }
}
{'fraction_non_alphanumeric': 0.140625, 'fraction_numerical': 0.003125, 'mean_word_length': 3.1165594855305465, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 65, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4895170', 'n_tokens_mistral': 1590, 'n_tokens_neox': 1547, 'n_words': 259}