Issue has been marked stale, but ... Sylk read sets worksheet title to filename (minus .slk). If that is >31 characters, PhpSpreadsheet throws Exception. This change truncates sheet title, as Excel does, to 31 characters.
This commit is contained in:
parent
d90d05077f
commit
e0feeca555
|
@ -9,6 +9,7 @@ use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
||||||
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
||||||
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
||||||
|
|
||||||
class Slk extends BaseReader
|
class Slk extends BaseReader
|
||||||
{
|
{
|
||||||
|
@ -516,7 +517,7 @@ class Slk extends BaseReader
|
||||||
$spreadsheet->createSheet();
|
$spreadsheet->createSheet();
|
||||||
}
|
}
|
||||||
$spreadsheet->setActiveSheetIndex($this->sheetIndex);
|
$spreadsheet->setActiveSheetIndex($this->sheetIndex);
|
||||||
$spreadsheet->getActiveSheet()->setTitle(basename($pFilename, '.slk'));
|
$spreadsheet->getActiveSheet()->setTitle(substr(basename($pFilename, '.slk'), 0, Worksheet::SHEET_TITLE_MAXIMUM_LENGTH));
|
||||||
|
|
||||||
// Loop through file
|
// Loop through file
|
||||||
$column = $row = '';
|
$column = $row = '';
|
||||||
|
|
|
@ -4,6 +4,7 @@ namespace PhpOffice\PhpSpreadsheetTests\Reader;
|
||||||
|
|
||||||
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
use PhpOffice\PhpSpreadsheet\Reader\Exception as ReaderException;
|
||||||
use PhpOffice\PhpSpreadsheet\Reader\Slk;
|
use PhpOffice\PhpSpreadsheet\Reader\Slk;
|
||||||
|
use PhpOffice\PhpSpreadsheet\Shared\File;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Border;
|
use PhpOffice\PhpSpreadsheet\Style\Border;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
use PhpOffice\PhpSpreadsheet\Style\Fill;
|
||||||
use PhpOffice\PhpSpreadsheet\Style\Font;
|
use PhpOffice\PhpSpreadsheet\Style\Font;
|
||||||
|
@ -12,6 +13,16 @@ class SlkTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
private static $testbook = __DIR__ . '/../../../samples/templates/SylkTest.slk';
|
private static $testbook = __DIR__ . '/../../../samples/templates/SylkTest.slk';
|
||||||
|
|
||||||
|
private $filename = '';
|
||||||
|
|
||||||
|
protected function teardown(): void
|
||||||
|
{
|
||||||
|
if ($this->filename) {
|
||||||
|
unlink($this->filename);
|
||||||
|
$this->filename = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function testInfo(): void
|
public function testInfo(): void
|
||||||
{
|
{
|
||||||
$reader = new Slk();
|
$reader = new Slk();
|
||||||
|
@ -131,4 +142,17 @@ class SlkTest extends \PHPUnit\Framework\TestCase
|
||||||
|
|
||||||
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
|
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLongName(): void
|
||||||
|
{
|
||||||
|
$contents = file_get_contents(self::$testbook);
|
||||||
|
$this->filename = File::sysGetTempDir()
|
||||||
|
. '/123456789a123456789b123456789c12345.slk';
|
||||||
|
file_put_contents($this->filename, $contents);
|
||||||
|
$reader = new Slk();
|
||||||
|
$spreadsheet = $reader->load($this->filename);
|
||||||
|
$sheet = $spreadsheet->getActiveSheet();
|
||||||
|
self::assertEquals('123456789a123456789b123456789c1', $sheet->getTitle());
|
||||||
|
self::assertEquals('FFFF0000', $sheet->getCell('A1')->getStyle()->getFont()->getColor()->getARGB());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue