Created
July 23, 2025 23:22
-
-
Save rafaehlers/2004f647fe2045abb1d43659c0432dcf to your computer and use it in GitHub Desktop.
This code snippet will format field id 6 on form 2 as a date field in excel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // DO NOT COPY THIS LINE | |
$binder = new \PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder(); | |
add_filter( 'gfexcel_renderer_cell_properties_2', function ( \PhpOffice\PhpSpreadsheet\Cell\Cell $cell, \GFExcel\Values\BaseValue $value ) use ( $binder ) { | |
if ( $value->getFieldId() == 6 && $cell->getRow() > 1 ) { | |
$old_binder = \PhpOffice\PhpSpreadsheet\Cell\Cell::getValueBinder(); | |
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( $binder ); | |
$cell->setValue( $value->getValue() ); | |
$cell | |
->getStyle() | |
->getNumberFormat() | |
->setFormatCode( \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_YYYYMMDD ); | |
\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( $old_binder ); | |
} | |
}, 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace the form ID in the filter name:
gfexcel_renderer_cell_properties_2
the 2 at the end here is meant to target the form ID = 2.The '6' here on line 5 is to target the date field
if ( $value->getFieldId() == 6
Here's where to add this code: https://docs.gravitykit.com/article/210-where-to-put-code-samples