Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new sheet to XLSX with Header-Row #124

Merged
merged 7 commits into from
Nov 9, 2022

Conversation

red-freak
Copy link
Contributor

The processingFirstRow property of the writer prevents the writer to automatically add a header row an newly created sheets by the underlaying writer. So this PR adds the method to the SimpleWriter and resets the processingFirstRow-property.

…ewrite a header with the new sheet.

 - also added the possibility to name the sheet
@freekmurze
Copy link
Member

Could you add tests for this and add an example to the readme?

@red-freak
Copy link
Contributor Author

red-freak commented Nov 6, 2022

@freekmurze there seems to be an issue with your assertMatchesFileSnapshot or I do not get how to use it.

Even if the files are copied, the following code will produce an assertion-error, if used for a xlsx. For a csv it works fine.

/** @test */
	public function it_can_write_a_csv_without_a_header2()
	{
		SimpleExcelWriter::create($this->pathToXlsx)
						 ->noHeaderRow()
						 ->addRow([
							 'first_name' => 'John',
							 'last_name' => 'Doe',
						 ])
						 ->addRow([
							 'first_name' => 'Jane',
							 'last_name' => 'Doe',
						 ]);

		$this->assertMatchesFileSnapshot($this->pathToXlsx);
	}

@red-freak
Copy link
Contributor Author

I see yopu changed to pest, but still the same

it('can write a regular XLSX', function () {
    SimpleExcelWriter::create($this->pathToXlsx)
                     ->addRow([
                         'first_name' => 'John',
                         'last_name' => 'Doe',
                     ])
                     ->addRow([
                         'first_name' => 'Jane',
                         'last_name' => 'Doe',
                     ]);

    assertMatchesFileSnapshot($this->pathToXlsx);
});

is not working

@red-freak red-freak changed the title Add new Sheet with header again Add new sheet to XMLS with Header-Row Nov 6, 2022
@red-freak
Copy link
Contributor Author

@freekmurze wrote a test with the limitations mentioned above (there are in general no tests for xlsx as I can see), wrote an example for the README.md and added comments. Please review again.

@red-freak red-freak changed the title Add new sheet to XMLS with Header-Row Add new sheet to XLSX with Header-Row Nov 6, 2022
@freekmurze freekmurze merged commit d00c17c into spatie:main Nov 9, 2022
@freekmurze
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants