douwen9534 2018-06-14 13:16
浏览 35

为什么字符串在phpexcel中被切入单元格

I am working on phpexcel i have string around 100 characters, and i am placing it in the cell value, when i download that excel file it is getting value cut, and when i am click on cell at that time it shows full string, i want to show that full string, rather than cut in cell, here i have added my code for that, can anyone please help me how can i resolve this issue ?

Current Result :

enter image description here

Expeected Result :

enter image description here

Code :

$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1','Report Date : '.date("F d, Y"));
$objPHPExcel->getActiveSheet()->setCellValue('B3','Starting Episodes : December, 2017 (Month)');
$objPHPExcel->getActiveSheet()->setCellValue('B4','Branches : Branches : Columbia , Concord , Madison , Ogden , Springfield , Unmatched ZipColumbia , Concord , Madison , Ogden , Springfield , Unmatched Zip');

$objPHPExcel->getActiveSheet()->getStyle("B3:H3")->getFont()->setSize(16);
$objPHPExcel->getActiveSheet()->getStyle('B3:H3')->getFont()->setBold(true);
$objPHPExcel->getActiveSheet()->mergeCells('A1:B1');
$objPHPExcel->getActiveSheet()->mergeCells('B3:H3');
$objPHPExcel->getActiveSheet()->mergeCells('B4:H4');

$excel_path =  dirname(__FILE__);   //$_SERVER['DOCUMENT_ROOT']; //dirname(__FILE__);
$save_file_path = $excel_path.'/../../results.xlsx'; 

//echo $save_file_path; die;

ob_clean(); 
//$output=$header."
".$data;
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//header('Content-Type: application/vnd.ms-excel');
//header("Content-Disposition: attachment; filename=".$name.".xls");
header("Content-Disposition: attachment; filename=\"$name.xlsx\"");
header("Cache-Control: max-age=0");
header('Content-Transfer-Encoding: binary');
header("Expires: 0");
header("Cache-Control: no-cache");
    header("Pragma: no-cache");
//header('Content-Length: ' . strlen($final_data));



//if (function_exists('mb_internal_encoding'))
//mb_internal_encoding($oldEncoding);

$objWriter->save($save_file_path);
$objWriter->save("php://output");
//ob_clean();   
die;
  • 写回答

1条回答 默认 最新

  • duanao6704 2018-06-14 13:51
    关注

    In row 3 and 4 of your spreadsheet, the code is merging columns together.

    $objPHPExcel->getActiveSheet()->mergeCells('B3:H3');
    $objPHPExcel->getActiveSheet()->mergeCells('B4:H4');
    

    To not cut off the text for row 4, merge more columns together.

    $objPHPExcel->getActiveSheet()->mergeCells('B4:Z4');
    

    You may also be able to write some logic to determine exactly how many columns you need to merge based on the length of the text.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line