From 6ab27d2931c3a996e481cb7a226b56a72c670301 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Thu, 11 Jul 2024 20:05:16 -0700 Subject: [PATCH 1/2] Xlsx Writer Rich Text and TYPE_STRING Fix #476. Another in the "better late than never" series, closed as stale in June 2018. Xlsx Writer expects cells containing RichText to have DataType `TYPE_INLINE`; but the spreadsheet associated with the issue has the cell defined as `TYPE_STRING`. Change Writer to handle RichText TYPE_STRING appropriately. --- src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php | 2 +- .../Writer/Xlsx/Issue476Test.php | 30 ++++++++++++++++++ tests/data/Writer/XLSX/issue.476.xlsx | Bin 0 -> 9028 bytes 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/PhpSpreadsheetTests/Writer/Xlsx/Issue476Test.php create mode 100644 tests/data/Writer/XLSX/issue.476.xlsx diff --git a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php index a1940f329c..bd6eec367f 100644 --- a/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php +++ b/src/PhpSpreadsheet/Writer/Xlsx/Worksheet.php @@ -1528,7 +1528,7 @@ private function writeCell(XMLWriter $objWriter, PhpspreadsheetWorksheet $worksh break; case 's': // String - $this->writeCellString($objWriter, $mappedType, $cellValueString, $flippedStringTable); + $this->writeCellString($objWriter, $mappedType, ($cellValue instanceof RichText) ? $cellValue : $cellValueString, $flippedStringTable); break; case 'f': // Formula diff --git a/tests/PhpSpreadsheetTests/Writer/Xlsx/Issue476Test.php b/tests/PhpSpreadsheetTests/Writer/Xlsx/Issue476Test.php new file mode 100644 index 0000000000..513fe7940b --- /dev/null +++ b/tests/PhpSpreadsheetTests/Writer/Xlsx/Issue476Test.php @@ -0,0 +1,30 @@ +load('tests/data/Writer/XLSX/issue.476.xlsx'); + + $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Xlsx'); + $spreadsheet->disconnectWorksheets(); + + $sheet = $reloadedSpreadsheet->getActiveSheet(); + $richText = $sheet->getCell('A1')->getValue(); + self::assertInstanceOf(RichText::class, $richText); + $plainText = $richText->getPlainText(); + self::assertSame("Art. 1A of the Geneva Refugee Convention and Protocol or other international or national instruments.\n", $plainText); + + $reloadedSpreadsheet->disconnectWorksheets(); + } +} diff --git a/tests/data/Writer/XLSX/issue.476.xlsx b/tests/data/Writer/XLSX/issue.476.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..f76f2d227f50eb47cd663917d5c6b6b226b040cc GIT binary patch literal 9028 zcmeHNgWbFzQ5q!HP5rxGtcbbyJxTU{@z@=8Yrlw0CWH*003YFSnXxmn=t> zR1xChVdLUqq3`Qz1AWZv19oP}Lq%qP13*UH|G)8HyaMHkgW8?^gv#e?H;U^#>I*e; zm=AWtdWkt7$+UO9?kTl4&316O%Z|P#RLCWB6s;y6UGNt?9Ja4<0XKw2^)v%p}d?CkS2BM6eDAK}!pF8)qmV@6YT1==fjE z!9Trvd4iTsCqFK1U+pHc?|f=8o=`!|b zom{wyCmSWMx$`-VtPg5sH(MFd=gfF|c@Ly#FYfTpD%)Lx$=BkkbNjJUMjOeG03Pkk zJ|L4Y@rB^1YA@@X(_oW2;lsf!-!4(C&a%FP{;*j3;w6NK`a4NNWfD`45i8P!Ajv%d zCX$ac-|sx}hPXRfK_E^)z1P1vgM@Hl2r2*Fqa3KE(Zx^Lf^!?m@15aAMl|ce$Fu|5 zCcx~k-~jGICvXD4$^- zeY~;N@*Q#N$iKqipmSNcFY0Or9E*{4b$%#i^7nwQoL+J}26Tn})x%^z_Op6uJM z_xDaMBX;`lDl@qyFvy7l08n5600f9T5GwO$WhnW3%+&pi{IKa7?30YMDXfbYvy2t7UFG3 z$-I&#c~|qglo=i7NdMhj0Jsekn5dU0g*l87@s35smz_W9TYRb4knHh2m7h7vibp`s zLiFP_iHYhm$~2Lu=!s0yV*eVgDrgNdmdc9Ic={MLET6(80-Ha%S5_=nh|!Oq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G0gW*B!3zqP?HWEh~6o^oT@XtzT>FWAFokJ+wzeZ+4hs*rW)(XlQe%RiNOc!>ToWY~FTz)g} z01y4`Y$S;8YlL;(>(36Vdr>&jFyX=yyfw`hb9FZ3J8sR(3p3%RNFt?lb~c-tK5{sB zJyniTAiQ@V@PtRlXuaa{LLTC-nc8njW_L!jhPpkIx#^M>09zr0SsTQ2ikOAL6M zdr9?r&XU3NF-R0UE+V(%8)p{Y*Yyuuo55Nc_86^4A0=7QMXq>R_qhq%J_mS<^b(sA zTf~vK7(gEhEt2m#d3gvX864|Fczn!is~tKhCbwGN&=bLO!R=qIJao$Fc)Gb`uDh+9 zlULEO@x|(Q7$q^gj1=b+pI7TVtMQHU-&b0Th?MzOOy;dMKsiD%WPLu%-HVRTON|j8 z4SS|BlEobNRkb-(^RC@|q*@h*<%fQ+NMj>pt@E-}c4)d!{$u^)N> zE>2Nyk(TR$-NB_!pz^XuQnmD&UobHJotOM>$zfzZ*=Gyf5b~*_m|$;%iLJo=VF+R? ze)rKx$UKOe;y<5P`1gkWd;W*h3%VMA74X;2>c4?M=M)4h{?upv75LX~)1QGK5iQ*R zzxVX3oL^fIe@NO#9Le~lA@M8t*Fx(bU=`foz<(>d{wm?uis2s;+7Ouw;_<)M4}TT# zYp(N$02Q*||H6MVpI@QBhFE_VFHkewFf9*ZGGGgam2;;BSufSNLCz;Gf~U dw10yC%OvV*pdoe_0Ki6kLJ+>XlHupK{{!OgnrQ$4 literal 0 HcmV?d00001 From d76481f668b84a78115dc17bc7128f3cc6126ba6 Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 17 Jul 2024 17:41:14 -0700 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 12b5959339..abdee5b3d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,8 @@ and this project adheres to [Semantic Versioning](https://semver.org). - Problem rendering line chart with missing plot label. [PR #4074](https://github.com/PHPOffice/PhpSpreadsheet/pull/4074) - More RTL in Xlsx/Html Comments [Issue #4004](https://github.com/PHPOffice/PhpSpreadsheet/issues/4004) [PR #4065](https://github.com/PHPOffice/PhpSpreadsheet/pull/4065) - Empty String in sharedStrings. [Issue #4063](https://github.com/PHPOffice/PhpSpreadsheet/issues/4063) [PR #4064](https://github.com/PHPOffice/PhpSpreadsheet/pull/4064) +- Xlsx Writer RichText and TYPE_STRING. [Issue #476](https://github.com/PHPOffice/PhpSpreadsheet/issues/476) [PR #4094](https://github.com/PHPOffice/PhpSpreadsheet/pull/4094) +- Ods boolean data. [Issue #460](https://github.com/PHPOffice/PhpSpreadsheet/issues/460) [PR #4093](https://github.com/PHPOffice/PhpSpreadsheet/pull/4093) ## 2024-05-11 - 2.1.0