这个问题已被问过其他一些帖子,但没有提供解决方案.
我想从带有照片和文本的HTML表格中获取Excel输出.我找到了以下两个Excel输出插件(我认为最完整的插件):
和
CountryPopulationDate%gePhoto
Chinna1,363,480,000March 24, 201419.1




并导出为
我还包括一个带有图像的列,如this fiddle所示
如果我将此表导出到Excel,则图像不会显示.那么如何将这些图像与数据一起导出呢?应该使用什么样的输出?
如果在Excel输出中无法做到这一点,那么应该使用什么格式进行输出?
解决方法:
如果您不需要原始Excel文件,而是需要在Excel中显示表格列的文件(并且可以在Excel或LibreOffice Calc或许多其他程序中编辑),则应考虑使用CSV (comma-separated values).
它易于创建和编辑,无需使用任何插件或库.
可能的输出
Column Name 1, Column Name 2, Column Name 3
'Row1Val1', 'Row1Val2', 'Row1Val3'
'Row2Val1', 'Row2Val2', 'Row2Val3'
'Row3Val1', 'Row3Val2', 'Row3Val3'
转换为Excel
但是如果你真的想要一个Excel文件,
PHPExcel将是你的朋友.它使用CSV文件创建完全可操作的Excel文件.
include 'PHPExcel/IOFactory.php';
$objReader = PHPExcel_IOFactory::createReader('CSV');
// If the files uses a delimiter other than a comma (e.g. a tab), then tell the reader
$objReader->setDelimiter("\t");
// If the files uses an encoding other than UTF-8 or ASCII, then tell the reader
$objReader->setInputEncoding('UTF-16LE');
$objPHPExcel = $objReader->load('MyCSVFile.csv');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('MyExcelFile.xls');
图像插入
PHP Excel提供了包含图像的功能:
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setName('PHPExcel logo');
$objDrawing->setDescription('PHPExcel logo');
$objDrawing->setPath('./images/phpexcel_logo.gif'); // filesystem reference for the image file
$objDrawing->setHeight(36);
$objDrawing->setCoordinates('D24');
$objDrawing->setOffsetX(10);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
标签:html,export-to-excel,javascript,php,jquery
来源: https://codeday.me/bug/20191008/1873263.html