2011-12-14 26 views
2

PHPExcelクラスを使用して、Excelファイルに書き込む方法です。
phpExcel、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/

答えて

2

がこの方法を試してください。

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

    } 
+0

すごい.. thx !!条件付き動的に!thx! – Dezigo

1

(Excelで)3 M から(M<sup>3</sup>)であれば、上付き文字とセルにデータを書き込む方法リッチテキストでセルを埋め込む:

$objRichText = new PHPExcel_RichText(); 
$objRichText->createText('M'); 

$objCubed = $objRichText->createTextRun('3'); 
$objCubed->getFont()->setSuperScript(true); 

$objPHPExcel->getActiveSheet()->getCell('A18')->setValue($objRichText); 
+0

はいそれ 'sが作業していて、データベースに、私の値は、このM のようなHTMLタグの内容です..私は動的に – Dezigo

+0

それをやりたいhtmlタグを変換します to superscript .. – Dezigo

+0

HTMLマークアップをリッチテキストに変換する方法はPHPExcelで利用できないので、自分で書く必要があります –

関連する問題