diff --git a/docs/topics/reading-and-writing-to-file.md b/docs/topics/reading-and-writing-to-file.md
index abd7c5f3..13b62e01 100644
--- a/docs/topics/reading-and-writing-to-file.md
+++ b/docs/topics/reading-and-writing-to-file.md
@@ -703,43 +703,24 @@ echo $writer->generateSheetData();
echo $writer->generateHTMLFooter();
```
-#### Editing HTML During Save Via a Callback
+#### Editing HTML during save via a callback
You can also add a callback function to edit the generated html
-before saving. For example, you could add a webfont
-(not currently supported for Pdf) as follows:
+before saving. For example, you could change the gridlines
+from a thin solid black line:
``` php
-function webfont(string $html): string
+function changeGridlines(string $html): string
{
- $linktag = <<
-
-EOF;
- $html = preg_replace('@
-
-EOF;
-
- return preg_replace('@@', "$newstyle", $html);
-}
-
-$helper->log('Write to Dompdf');
-$writer = new Dompdf($spreadsheet);
-$filename = $helper->getFileName('21a_Pdf_dompdf.xlsx', 'pdf');
-$writer->setEditHtmlCallback('yellowBody');
-$writer->save($filename);
$helper->log('Write to Mpdf');
$writer = new Mpdf($spreadsheet);
$filename = $helper->getFileName('21a_Pdf_mpdf.xlsx', 'pdf');
-$writer->setEditHtmlCallback('yellowBody');
-$writer->save($filename);
-
-$helper->log('Write to Tcpdf');
-$writer = new Tcpdf($spreadsheet);
-$filename = $helper->getFileName('21a_Pdf_tcpdf.xlsx', 'pdf');
-$writer->setEditHtmlCallback('yellowBody');
+$writer->setEditHtmlCallback('changeGridlines');
$writer->save($filename);
diff --git a/src/PhpSpreadsheet/Writer/Html.php b/src/PhpSpreadsheet/Writer/Html.php
index 963b02d7..752f286f 100644
--- a/src/PhpSpreadsheet/Writer/Html.php
+++ b/src/PhpSpreadsheet/Writer/Html.php
@@ -134,9 +134,9 @@ class Html extends BaseWriter
/**
* Callback for editing generated html.
*
- * @var callable
+ * @var null|callable
*/
- protected $editHtmlCallback = '';
+ protected $editHtmlCallback;
/**
* Create a new HTML.
@@ -197,9 +197,9 @@ class Html extends BaseWriter
// Write footer
$html .= $this->generateHTMLFooter();
- $cbk = $this->editHtmlCallback;
- if ($cbk) {
- $html = $cbk($html);
+ $callback = $this->editHtmlCallback;
+ if ($callback) {
+ $html = $callback($html);
}
Calculation::setArrayReturnType($saveArrayReturnType);
@@ -208,16 +208,11 @@ class Html extends BaseWriter
return $html;
}
- public function setEditHtmlCallback(callable $cbk): void
+ public function setEditHtmlCallback(?callable $cbk): void
{
$this->editHtmlCallback = $cbk;
}
- public function resetEditHtmlCallback(): void
- {
- $this->editHtmlCallback = '';
- }
-
const VALIGN_ARR = [
Alignment::VERTICAL_BOTTOM => 'bottom',
Alignment::VERTICAL_TOP => 'top',
diff --git a/tests/PhpSpreadsheetTests/Writer/Html/CallbackTest.php b/tests/PhpSpreadsheetTests/Writer/Html/CallbackTest.php
index f712419c..388dbd0e 100644
--- a/tests/PhpSpreadsheetTests/Writer/Html/CallbackTest.php
+++ b/tests/PhpSpreadsheetTests/Writer/Html/CallbackTest.php
@@ -33,7 +33,7 @@ EOF;
$html1 = $writer->generateHTMLall();
$writer->setEditHtmlCallback([$this, 'yellowBody']);
$html2 = $writer->generateHTMLall();
- $writer->resetEditHtmlCallback();
+ $writer->setEditHtmlCallback(null);
$html3 = $writer->generateHTMLall();
self::assertFalse(strpos($html1, 'background-color: yellow'));