通过javascript导出表格html以使用文本和图像来表现出色 [英] export table html to excel with text and images by javascript

查看:49
本文介绍了通过javascript导出表格html以使用文本和图像来表现出色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是图像!!!我将此表格html导出到excel,但是图像未导出到表格中.

 < table class ="order-table table sortable" id ="tableadmin">< thead>< tr>< th style ="width:8px; min-width:8px; max-width:8px;"> ID</th><thélpro</th第RDV日期/第RDV日期.< Heure RDV< th< fiche</th>< th style ="width:170px; min-width:170px; max-width:170px;"> Compterendu</th>< th style ="width:250px; min-width:250px;"> Commentaire commercial</th></tr></thead>< tbody id ="changetable" class ="new">< tr>< td><?php echo $ id?></td>< td><?php echo $ login?></td>< td><?php echo $ date?></td>< td><?php echo $ heure?></td>< td>< img src ="../img/fiche.png"/></td>< td><?php echo $ compterendu?></td>< td><?php echo $ comment?></td></tr></tbody></table>  

我的问题是图片!!!!

解决方案

使用phpexcel类将图像写入excel工作表是一个很棒的功能,使用这种方法,我们可以在excel列中绘制图像,看起来很不错带有说明的图片.

在使用导入/导出系统时,我注意到PHPExcel的这种工具确实非常好用,很容易,但是Ok让我们检查一下使用PHPExcel将图像写到excel工作表中的代码.

  include'PHPExcel.php';//创建新的PHPExcel对象$ objPHPExcel =新的PHPExcel();//设置属性$ objPHPExcel-> getProperties()-> setCreator("Jobin Jose");$ objPHPExcel-> getProperties()-> setLastModifiedBy("Jobin Jose");$ objPHPExcel-> getProperties()-> setTitle("Office 2007 XLSX测试文档");$ objPHPExcel-> getProperties()-> setSubject("Office 2007 XLSX测试文档");$ objPHPExcel-> getProperties()-> setDescription("Office 2007 XLSX的测试文档,使用PHPExcel类生成.")//添加一些数据//echo date('H:i:s').添加一些数据\ n";$ objPHPExcel-> setActiveSheetIndex(0);$ objPHPExcel-> getActiveSheet()-> SetCellValue('A1','Hello');$ objPHPExcel-> getActiveSheet()-> SetCellValue('B2','world!');//$ objPHPExcel-> getActiveSheet()-> SetCellValue('C1','Hello');$ objPHPExcel-> getActiveSheet()-> SetCellValue('D2','world!');$ objPHPExcel-> getActiveSheet()-> setTitle('Simple');$ gdImage = imagecreatefromjpeg('uploads/t12.jpg');//将图形添加到工作表中echo date('H:i:s').将图形添加到工作表\ n";$ objDrawing =新的PHPExcel_Worksheet_MemoryDrawing();$ objDrawing-> setName('样本图片');$ objDrawing-> setDescription('样本图片');$ objDrawing-> setImageResource($ gdImage);$ objDrawing-> setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing :: RENDERING_JPEG);$ objDrawing-> setMimeType(PHPExcel_Worksheet_MemoryDrawing :: MIMETYPE_DEFAULT);$ objDrawing-> setHeight(150);$ objDrawing-> setCoordinates('C1');$ objDrawing-> setWorksheet($ objPHPExcel-> getActiveSheet());$ objWriter = PHPExcel_IOFactory :: createWriter($ objPHPExcel,'Excel2007');$ objWriter-> save(str_replace('.php','.xlsx',__FILE__));//回声完成echo date('H:i:s').写文件完成.\ r \ n";输出结果如下. 

使用PHPExcel将图像写入Excel

上面的代码将创建一个"xlsx"格式的文件,因为它使用2007 excel类.如果要"xls"格式,请仅尝试使用2005类,不要在使用2005时将文件格式更改为"xls"./p>

my problem is images !!!! i export table this table html to excel but the images aren't exported in the table .

   <table class="order-table table sortable" id="tableadmin">
    <thead>
        <tr>
            <th style="width:8px; min-width:8px; max-width:8px;">ID</th>
            <th>Télépro</th>
            <th>Date RDV</th>
            <th>Heure RDV</th>
            <th>Fiche</th>
            <th style="width:170px; min-width:170px; max-width:170px;">Compterendu</th>
            <th style="width:250px; min-width:250px;">Commentaire commercial</th>
        </tr>
    </thead>
    <tbody id="changetable" class="new">
        <tr>
            <td>
                <?php echo $id ?>
            </td>
            <td>
                <?php echo $login ?>
            </td>
            <td>
                <?php echo $date ?>
            </td>
            <td>
                <?php echo $heure ?>
            </td>
            <td><img src="../img/fiche.png" />
            </td>
            <td>
                <?php echo $compterendu ?>
            </td>
            <td>
                <?php echo $comment ?>
            </td>
        </tr>
    </tbody>
</table>

my problem is images !!!!

解决方案

Writing images to the excel sheet using phpexcel class is a great feature , using this method we can draw the images inside the excel column it looks good and nice to have images with some descriptions.

While working on an Import/Export system I have noticed this facility of PHPExcel its really good and easy, Ok lets check the code for writing images to the excel sheet using PHPExcel.

include 'PHPExcel.php';
// Create new PHPExcel object
$objPHPExcel = new PHPExcel();
// Set properties
$objPHPExcel->getProperties()->setCreator("Jobin Jose");
$objPHPExcel->getProperties()->setLastModifiedBy("Jobin Jose");
$objPHPExcel->getProperties()->setTitle("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setSubject("Office 2007 XLSX Test Document");
$objPHPExcel->getProperties()->setDescription("Test document for Office 2007 XLSX, generated using PHPExcel classes.");
// Add some data
// echo date('H:i:s') . " Add some data\n";
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->SetCellValue('A1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('B2', 'world!');
//$objPHPExcel->getActiveSheet()->SetCellValue('C1', 'Hello');
$objPHPExcel->getActiveSheet()->SetCellValue('D2', 'world!');
$objPHPExcel->getActiveSheet()->setTitle('Simple');
$gdImage = imagecreatefromjpeg('uploads/t12.jpg');
// Add a drawing to the worksheetecho date('H:i:s') . " Add a drawing to the worksheet\n";
$objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
$objDrawing->setName('Sample image');
$objDrawing->setDescription('Sample image');
$objDrawing->setImageResource($gdImage);
$objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
$objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
$objDrawing->setHeight(150);
$objDrawing->setCoordinates('C1');
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save(str_replace('.php', '.xlsx', __FILE__));
// Echo done
echo date('H:i:s') . " Done writing file.\r\n";
The out put will be like as follows.

Writing Images to Excel Using PHPExcel

The above code will create an "xlsx" formatted file because it uses 2007 excel classes If you want "xls" format just try with 2005 class do not for get to change the file format to "xls" while using 2005.

这篇关于通过javascript导出表格html以使用文本和图像来表现出色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆