Allow custom sheet name in the XLSX writer
Added setter Added test Updated README
This commit is contained in:
1 parent
71d9c18a81
commit
d02013c82e
5 files changed
+66
-4
No files matched your search
@@ -343,6 +343,27 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInlineDataWasWrittenToSheet($fileName, 1, 'control's _x0015_ "character"');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testSetNameShouldCreateSheetWithCustomName()
|
||||
{
|
||||
$fileName = 'test_set_name_should_create_sheet_with_custom_name.xlsx';
|
||||
$this->createGeneratedFolderIfNeeded($fileName);
|
||||
$resourcePath = $this->getGeneratedResourcePath($fileName);
|
||||
|
||||
$writer = WriterFactory::create(Type::XLSX);
|
||||
$writer->openToFile($resourcePath);
|
||||
|
||||
$customSheetName = 'CustomName';
|
||||
$sheet = $writer->getCurrentSheet();
|
||||
$sheet->setName($customSheetName);
|
||||
|
||||
$writer->addRow(['xlsx--11', 'xlsx--12']);
|
||||
$writer->close();
|
||||
|
||||
$this->assertSheetNameEquals($customSheetName, $resourcePath, "The sheet name should have been changed to '$customSheetName'");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $allRows
|
||||
@@ -445,4 +466,18 @@ class XLSXTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertContains($sharedString, $xmlContents, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expectedName
|
||||
* @param string $resourcePath
|
||||
* @param string $message
|
||||
* @return void
|
||||
*/
|
||||
private function assertSheetNameEquals($expectedName, $resourcePath, $message = '')
|
||||
{
|
||||
$pathToWorkbookFile = $resourcePath . '#xl/workbook.xml';
|
||||
$xmlContents = file_get_contents('zip://' . $pathToWorkbookFile);
|
||||
|
||||
$this->assertContains('<sheet name="' . $expectedName . '"', $xmlContents, $message);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user