Merge branch 'master' into custom-column-widths
This commit is contained in:
commit
ad78049da1
5 files changed
+130
-3
No files matched your search
@@ -393,6 +393,52 @@ class WriterTest extends TestCase
|
||||
$this->assertInlineDataWasWrittenToSheet($fileName, 1, 't="e"><v>#DIV/0</v>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testAddRowShouldSupportFloatValuesInDifferentLocale()
|
||||
{
|
||||
$previousLocale = \setlocale(LC_ALL, 0);
|
||||
$valueToWrite = 1234.5; // needs to be defined before changing the locale as PHP8 would expect 1234,5
|
||||
|
||||
try {
|
||||
// Pick a supported locale whose decimal point is a comma.
|
||||
// Installed locales differ from one system to another, so we can't pick
|
||||
// a given locale.
|
||||
$supportedLocales = explode("\n", shell_exec('locale -a'));
|
||||
foreach ($supportedLocales as $supportedLocale) {
|
||||
\setlocale(LC_ALL, $supportedLocale);
|
||||
if (\localeconv()['decimal_point'] === ',') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertEquals(',', \localeconv()['decimal_point']);
|
||||
|
||||
var_dump("Cell value before: " . $valueToWrite);
|
||||
$cellValue = str_replace(
|
||||
[\localeconv()['thousands_sep'], \localeconv()['decimal_point']],
|
||||
['', '.'],
|
||||
$valueToWrite
|
||||
);
|
||||
var_dump("Cell value after: " . $cellValue);
|
||||
var_dump("Thousands sep: " . \localeconv()['thousands_sep']);
|
||||
var_dump("Decimal point: " . \localeconv()['decimal_point']);
|
||||
|
||||
$fileName = 'test_add_row_should_support_float_values_in_different_locale.xlsx';
|
||||
$dataRows = $this->createRowsFromValues([
|
||||
[$valueToWrite],
|
||||
]);
|
||||
|
||||
$this->writeToXLSXFile($dataRows, $fileName, $shouldUseInlineStrings = false);
|
||||
|
||||
$this->assertInlineDataWasNotWrittenToSheet($fileName, 1, "1234,5");
|
||||
$this->assertInlineDataWasWrittenToSheet($fileName, 1, "1234.5");
|
||||
} finally {
|
||||
// reset locale
|
||||
\setlocale(LC_ALL, $previousLocale);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user