gpt4 book ai didi

phpExcel,如何在excel中写上标

转载 作者:行者123 更新时间:2023-12-04 00:46:47 32 4
gpt4 key购买 nike

我正在使用 PHPExcel 类,在 excel 文件中写入。

我的问题是:如果我的值为( M<sup>3</sup>),如何在带有上标的单元格中写入数据到 M3(在 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/

最佳答案

试试这个:

      $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']);

}

关于phpExcel,如何在excel中写上标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8503577/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com