我正在使用PHPExcel生成列表。
问题是文本溢出了单元格B的宽度。
如何自动放置固定宽度和长度,以使其不会溢出?
附件:
代码:
$objPHPExcel = new PHPExcel();
$objPHPExcel->
getProperties()
->setCreator("TEDnologia.com")
->setLastModifiedBy("TEDnologia.com")
->setTitle("Exportar Excel con PHP")
->setSubject("Documento de prueba")
->setDescription("Documento generado con PHPExcel")
->setKeywords("usuarios phpexcel")
->setCategory("reportes");
$query = mysql_query('select * from articulos');
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue('A1', 'Nombre')
->setCellValue('B1', 'E-mail')
->setCellValue('C1', 'E-mail')
;
$i=2;
while($row = mysql_fetch_assoc($query)){
$xx = "A".$i;
$xxx = "B".$i;
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(10);
$objPHPExcel->setActiveSheetIndex(0)
->setCellValue($xx, $row["cod"])
->setCellValue($xxx, $row["descripcion"]);
;
$xxxx = "C".$i;
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('Logo');
$objDrawing->setDescription('Logo');
$objDrawing->setPath('archivos/articulos/'.$row["imagen"].'');
$objDrawing->setCoordinates($xxxx);
$objDrawing->setHeight(36);
$objDrawing->setWidth(36);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$i++;
}
$objPHPExcel->getActiveSheet()->setTitle('Usuarios');
$objPHPExcel->setActiveSheetIndex(0);
header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="01simple.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
答案 0 :(得分:1)
$objPHPExcel->getActiveSheet()->getStyle('D1')->getAlignment()->setWrapText(true);