## export data into excel using php excel library into yii2 framework ##
<?php
foreach ($data as $key => $value) {
if ($key == 'other') {
$objRichText = new \PHPExcel_RichText();
$lines = explode("\n", $data[$key]);
$cnt = 0;
foreach ($lines as $k => $v) {
$cnt++;
if ($k < 50) {
if (preg_match("/red/", $v)) {
$run = $objRichText->createTextRun($v);
$run->getFont()->setColor(new
PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_RED));
} else {
$objRichText->createText(addslashes($v));
}
//$run[2] = $objRichText->createTextRun('blueaddress ipv6 2405:200:a10:fc00::/64');
//$run[2]->getFont()->setColor(new PHPExcel_Style_Color(PHPExcel_Style_Color::COLOR_BLUE));
}
//$k++;
$objPHPExcel->getActiveSheet()->SetCellValue('BA' . $cnt, $objRichText);
}
/*$objPHPExcel->getActiveSheet()->mergeCells('BA1:BA'.$cnt);
$cell = $objPHPExcel->getActiveSheet()->getCellByColumnAndRow('BA1');
$style = $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow('BA1');
$dstCell = \PHPExcel_Cell::stringFromColumnIndex($cell_name) . (string)($rowNo);
$objPHPExcel->getActiveSheet()->setCellValue($dstCell, $cell->getValue());
$objPHPExcel->getActiveSheet()->duplicateStyle($style, $dstCell);*/
//$objPHPExcel->getActiveSheet()->getCell('BA1')->getValue();
//$objPHPExcel->getActiveSheet()->removeColumn('BA');
//$objPHPExcel->getActiveSheet()->SetCellValue($cell_name . $rowNo, $objRichText);
//$data[$key] = implode("\n",$lines);
} else {
$objPHPExcel->getActiveSheet()->SetCellValue($cell_name . $rowNo, $value);
}
$cell_name++;
}
?>
red-admin config t
red-crypto key generate rsa
red-yes
red-1024
black-banner login
black-UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED
black-You must have explicit, authorized permission to access or configure
black-device
black-Unauthorized attempts and actions to access or use this system may
black-in civil and/or criminal penalties
black-All activities performed on this device are logged and monitored
black-GCTv20.7
black-banner motd
black-UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED
black-key chain ISIS-KEY
black-key 1
red-key-string clear R4G_IsIs_P33r.2O14
black-accept-lifetime 01:00:00 january 01 2014 infinite
black-send-lifetime 01:00:00 january 01 2014 infinite
black-cryptographic-algorithm HMAC-MD5
black-allow SNMP peer
我正在尝试将数据导出到excel。虽然我的数据包含2种颜色 在一个单元格中,并且在一个单元格中包含很多字符和行 单细胞。数据是这样的,上面写着黑色和红色字体 应该在excel中以相应的颜色出现。以上是我的数据。我尝试了PHPExcel_RichText对象,如果超过50个字符,则无法正常工作