Handle RAW strings to disable type detection
masterBy default, SimpleXLSXGen attempts to detect data types. To prevent this (e.g., to keep leading zeros in phone numbers or prevent dates from being parsed incorrectly), use one of the following methods:
- Prefix with null byte: Prepend
"\0"to your string. - Use
SimpleXLSXGen::raw(): Wrap the value in this method. - Use
SimpleXLSXGen::rawArray(): Pass the entire 2D array through this method before callingfromArray(). - Use
<raw>tag: Wrap the content in<raw>...</raw>tags.
// Option 1: Null byte prefix
$data = [["\0" . '+12345']];
// Option 2: ::raw() method
$data = [SimpleXLSXGen::raw('20- short term: <6 month')];
// Option 3: ::rawArray() method
$data = [['test', 'raw'], ['2025-01-01', '<tag>']];
$raw_data = SimpleXLSXGen::rawArray($data);
SimpleXLSXGen::fromArray($raw_data)->saveAs('test.xlsx');
// Option 4: <raw> tag
$data = [['<raw>+123456</raw>']];