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 support for headerFooter, fitToHeight/Width, printTitleRows (xlsx only) #208

Merged
merged 16 commits into from
Jan 9, 2024

Conversation

tekku-taro
Copy link
Contributor

Add support for headerFooter, fitToHeight/Width, printTitleRows (xlsx only)

headerFooter

Header and footer can be set via Options::setHeaderFooter()

$options = new Options();
$options->setHeaderFooter(new HeaderFooter(
    'oddHeader',
    'oddFooter',
    'evenHeader',
    'evenFooter',
    true  // differentOddEven, default value is false
));

fitToHeight/Width

Add new arguments for fitToHeight and fitToWidth to the PageSetup constructor.

$options = new Options();
$options->setPageSetup(new PageSetup(
    PageOrientation::LANDSCAPE,
    PaperSize::A4,
    0, // ?int fitToHeight
    1  // ?int fitToWidth
));

printTitleRows

Print title rows can be set at the sheet level for XLSX writers.

$writer = new Writer($options);
$sheet = $writer->getCurrentSheet();
$sheet->setPrintTitleRows('$2:$2');

Examples (preview images)

image1
image2
image3

@@ -329,7 +332,9 @@ public function createContentFiles(Options $options, array $worksheets): self
fwrite($worksheetFilePointer, '<sheetPr filterMode="false"><pageSetUpPr fitToPage="false"/></sheetPr>');
fwrite($worksheetFilePointer, sprintf('<dimension ref="%s"/>', $range));
}

if (isset($pageSetup) && $pageSetup->fitToPage) {
fwrite($worksheetFilePointer, '<sheetPr><pageSetUpPr fitToPage="true"/></sheetPr>');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sheetPr tag is already written within the autofilter if few lines above: we need to handle the case where both are used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand, when both autofilter and fitToPage are turned on, the fitToPage attribute will be true, right?

Copy link
Contributor Author

@tekku-taro tekku-taro Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed it to handle the case.
b826464

@@ -6,8 +6,16 @@

final class PageSetup
{
public bool $fitToPage = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public bool $fitToPage = false;
public readonly bool $fitToPage = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, this can't be accepted. The following error occurs:

$fitToPage cannot have default value

Besides, fitToPage value depends on fitToHeight and fitToWidth, which is passed to the constructor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just remove the default value and set it in the constructor as

$this->fitToPage = null !== $fitToHeight || null !== $fitToWidth;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it.

@tekku-taro tekku-taro requested a review from Slamdunk December 16, 2023 04:46
@Slamdunk Slamdunk merged commit be090ef into openspout:4.x Jan 9, 2024
15 checks passed
@Slamdunk
Copy link
Contributor

Slamdunk commented Jan 9, 2024

Thank you @tekku-taro 💪

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.

None yet

2 participants