Skip to content
This repository has been archived by the owner on May 26, 2022. It is now read-only.

Added support for cell formats when writing Excel files #668

Merged
merged 4 commits into from
Oct 1, 2019

Conversation

eisberg
Copy link

@eisberg eisberg commented Jul 10, 2019

Added support for cell formats when writing Excel files

Example:

$style = (new StyleBuilder())
            ->setFontBold()
            ->setFormat('0.00')//Builtin format
            ->build();

$style2 = (new StyleBuilder())
            ->setFontBold()
            ->setFormat('0.000')
            ->build();

@boxcla
Copy link

boxcla commented Jul 10, 2019

Verified that @eisberg has signed the CLA. Thanks for the pull request!

@amiri27
Copy link

amiri27 commented Sep 28, 2019

Any update regarding this?!

@eisberg
Copy link
Author

eisberg commented Sep 29, 2019

I'm really looking forward to the confirmation of this request, too.

} else {
$this->registeredFormats[$format] = $styleId;

if (isset(self::$builtinNumFormatToIdMapping[$format])) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: can be simplified $id = self::$builtinNumFormatToIdMapping[$format] ?? $this->formatIndex++;

*/
public function getFormatIdForStyleId($styleId)
{
return (isset($this->styleIdToFormatsMappingTable[$styleId])) ?
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: can be simplified: return $this->styleIdToFormatsMappingTable[$styleId] ?? null;

$this->assertEquals(
1,
$formatsDomElement->getAttribute('count'),
'There should be 2 formats, including the 1 default ones'
Copy link
Collaborator

Choose a reason for hiding this comment

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

including the default one

*
* @param Style $style
*/
protected function registerFormat(Style $style)
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a test here? See StyleRegistryTest.php for examples

@@ -88,6 +88,9 @@ private function mergeCellProperties(Style $styleToUpdate, Style $style, Style $
if (!$style->getBorder() && $baseStyle->shouldApplyBorder()) {
$styleToUpdate->setBorder($baseStyle->getBorder());
}
if (!$style->getFormat() && $baseStyle->shouldApplyFormat()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe add a test in StyleBuilderTest?

@eisberg eisberg force-pushed the feature/cells_formats branch from 6c011a3 to 29bb8d3 Compare September 29, 2019 15:33
@adrilo adrilo merged commit 52312b7 into box:master Oct 1, 2019
@adrilo
Copy link
Collaborator

adrilo commented Oct 1, 2019

Thanks for the PR!

@amiri27
Copy link

amiri27 commented Oct 1, 2019

Thanks @adrilo and well done @eisberg ..

@adrilo
Copy link
Collaborator

adrilo commented Oct 2, 2019

As a follow-up, we need to update the documentation.

@madflow
Copy link
Contributor

madflow commented Oct 2, 2019

Is this a XSLX only feature? Does ODS not have cell formats?

@adrilo
Copy link
Collaborator

adrilo commented Oct 3, 2019

Right! We should also add that feature to ODS. Though I figured that asking people to implement both XLSX and ODS for every feature is too demanding. Usually people only need a feature for a specific file format. That's why I merged that one.

See #687

@madflow
Copy link
Contributor

madflow commented Oct 4, 2019

@adrilo Okay. I respect that - but I disagree. I do not think it is to demanding do expect a fully implemented feature and docs in a PR. This repo has > 2600 stars and is heavily used. We can demand something ;)

Usually people only need a feature for a specific file format.

We use XLSX and ODS.

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

Successfully merging this pull request may close these issues.

5 participants