I`m using the PHPExcel class ,to write in an excel file.
My question is: how to write a data in a cell with superscript,if my value is ( M<sup>3</sup>) to M3 (in excel)
// $data['dataLashing'][$i]['units_name'] - it`s a value from db in LOOP
$getExcelObject
->mergeCells("A$startRow:E$startRow")->setCellValue("A$startRow",$data['dataLashing'][$i]['material'])
->mergeCells("F$startRow:G$startRow")->setCellValue("F$startRow",$data['dataLashing'][$i]['units_name'])
->mergeCells("H$startRow:I$startRow")->setCellValue("H$startRow",$data['dataLashing'][$i]['quantity']);
http://phpexcel.codeplex.com/
Try this one:
$objRichText = new PHPExcel_RichText();
$objRichText->createText($data['dataLashing'][$i]['units_name']);
//condition your html tag
if(preg_match('/<sup>(.+)<\/sup>/i', $data['dataLashing'][$i]['units_name'],$result)) {
$objRichText = new PHPExcel_RichText();
$objCubed = $objRichText->createText(preg_replace('/<sup>(.+)<\/sup>/i', '', $data['dataLashing'][$i]['units_name']));
$objCubed = $objRichText->createTextRun($result[1]);
$objCubed->getFont()->setSuperScript(true);
}
$getExcelObject
->mergeCells("A$startRow:E$startRow")->setCellValue("A$startRow",$data['dataLashing'][$i]['material'])
->mergeCells("F$startRow:G$startRow")->setCellValue("F$startRow",$objRichText)
->mergeCells("H$startRow:I$startRow")->setCellValue("H$startRow",$data['dataLashing'][$i]['quantity']);
}
You need to populate the cell with rich text:
$objRichText = new PHPExcel_RichText();
$objRichText->createText('M');
$objCubed = $objRichText->createTextRun('3');
$objCubed->getFont()->setSuperScript(true);
$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With