This article introduces the implementation method of automatic line wrapping in PHP exported excel cells. Spreadsheet Excel Writer can export data into Excel files and set the font, color, cell size and other formats. Friends in need can refer to it.
Spreadsheet Excel Writer can export data into Excel files and set formats such as fonts, colors, cell sizes, etc. $workbook = new Spreadsheet_Excel_Writer(); $filename = date('YmdHis').'.xls';//csv $workbook->send($filename); // 发送 Excel 文件名供下载 $workbook->setVersion( 8 ); $sheet = &$workbook->addWorksheet("Sheet1"); // 创建工作表 $sheet->setInputEncoding('utf-8'); // 字符集 $dataFormat = &$workbook->addFormat(array('Size' => 10, 'Align' => 'left', 'Border' => '1', 'Color' => 'black', 'FgColor'=> 'cyan'));//定义格式 $sheet->write(0, 0, "数据", $dataFormat); // 工作表写入数据,使用预定义的格式 (bbs.it-home.org 脚本学堂) Copy after login The Format::setTextWrap() method provided by the software package is used to set the automatic word wrapping of cells, but there is no description of the automatic word wrapping property in the documentation of Workbook::&addFormat(). Try adding TextWrap => 1 to the Workbook::&addFormat() parameter, which can also wrap lines and has the same effect as Format::setTextWrap(). $dataFormat = &$workbook->addFormat(array('Size' => 10, 'Align' => 'left', 'Border' => '1', 'Color' => 'black', 'FgColor'=> 'cyan', 'TextWrap' => 1));//定义格式 Copy after login |