phpphpspreadsheet

Use the phpspreadsheet to set different colors in a cell, it will get error style on android and Mac


I use the follwing code to set different colors in a cell and export it

$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();

$rich_text = new RichText();
$rich_text->createText("P\n");
$text_run = $rich_text->createTextRun("A\n");
$text_run->getFont()->setColor( new \PhpOffice\PhpSpreadsheet\Style\Color( \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_GREEN ) );
$text_run = $rich_text->createTextRun("N\n");
$text_run->getFont()->setColor( new \PhpOffice\PhpSpreadsheet\Style\Color( \PhpOffice\PhpSpreadsheet\Style\Color::COLOR_RED ) );
$spreadsheet->getActiveSheet()->getCell('A1')->setValue($rich_text);
$sheet->getStyle('A1')->getAlignment()->setWrapText(true);

$obj_writer = IOFactory::createWriter($spreadsheet, 'Xlsx');
$obj_writer->save(dirname(__FILE__) . '/test.xlsx');

But open the file in different systems, I get different result, for example:

In windows, it looks normal:

enter image description here

In mobile(I just try open it in android), colored rich text is not displayed: enter image description here

In Mac, colored rich text has strikethrough: enter image description here

so, is it because of format compatibility? Do I need to set up anything?


Solution

  • I finally used two cells to show the contents of different colors.