Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 如何增加导出表的列宽_Jquery_Excel - Fatal编程技术网

Jquery 如何增加导出表的列宽

Jquery 如何增加导出表的列宽,jquery,excel,Jquery,Excel,我使用表格excel和它的工作良好,但我得到了宽度问题后,导出到excel。该列包含图像,在打开excel后,无法获得实际的html宽度。任何帮助都将不胜感激。 我正在使用来自()的jquery代码 var tableToExcel=(函数(){ var uri='data:application/vnd.ms excel;base64,' ,模板=“{table}” ,base64=函数{return window.btoa(unescape(encodeURIComponent))} ,f

我使用表格excel和它的工作良好,但我得到了宽度问题后,导出到excel。该列包含图像,在打开excel后,无法获得实际的html宽度。任何帮助都将不胜感激。 我正在使用来自()的jquery代码


var tableToExcel=(函数(){
var uri='data:application/vnd.ms excel;base64,'
,模板=“{table}”
,base64=函数{return window.btoa(unescape(encodeURIComponent))}
,format=函数(s,c){返回s.replace(/{(\w+)}/g,函数(m,p){返回c[p];})}
返回函数(表、名称){
如果(!table.nodeType)table=document.getElementById(table)
var ctx={工作表:名称| |'工作表',表:table.innerHTML}
window.location.href=uri+base64(格式(模板,ctx))
}
})()

在Excel中,图像不在单元格内。它们悬停在工作表上方的单独图层上。这就是为什么图像宽度不会自动增加单元格宽度。因此,必须在HTML代码中指定单元格宽度

例如:

<table id="testTable">
    <colgroup>
        <col width="150" style="vertical-align:middle;" />
        <col style="width:200px;" />
    </colgroup>
    <tr height="100">
        <td style="text-align:center; border:1px solid;">Text</td>
        <td><img src="https://www.gravatar.com/avatar/9a24eed042b7cb501ceb6ea73c09fc46?s=32&d=identicon&r=PG&f=1" width="200" height="80"/></td>
    </tr>
    <tr height="100">
        <td>Text</td>
        <td style="border:1px solid;"><img src="https://www.gravatar.com/avatar/9a24eed042b7cb501ceb6ea73c09fc46?s=32&d=identicon&r=PG&f=1" width="200" height="80"/></td>
    </tr>
</table>

正文
正文
JSFiddle:

一些设置来自HTML属性,其他设置仅来自内联CSS。有些在COL元素中有效,有些则不起作用。在这里,您必须尝试更有效的方法。

试试这个

<table border=\"0\" cellpadding=\"0\" cellspacinxg=\"0\" width=\"100%\" style=\"border-collapse: collapse;\">
        <thead>
            <tr>
                <th align=\"center\" style=\"background:#cccccc; font-weight:bold;border-collapse: collapse;font-family: &#39;Open Sans&#39;, sans-serif; padding-top:12px; padding-bottom:12px; padding-left:16px; padding-right:16px; color:#000;\">heading1</th>
            </tr>
        </thead>
        <tbody><tr>
<td align=\"center\" style=\"border-collapse: collapse;font-family: &#39;Open Sans&#39;, sans-serif; padding-top:12px; padding-bottom:12px; padding-left:16px; padding-right:16px; color:#000; border:1px solid #cccccc;\">content1</td>
            </tr>
</tbody>
</table>

标题1
内容1
<table border=\"0\" cellpadding=\"0\" cellspacinxg=\"0\" width=\"100%\" style=\"border-collapse: collapse;\">
        <thead>
            <tr>
                <th align=\"center\" style=\"background:#cccccc; font-weight:bold;border-collapse: collapse;font-family: &#39;Open Sans&#39;, sans-serif; padding-top:12px; padding-bottom:12px; padding-left:16px; padding-right:16px; color:#000;\">heading1</th>
            </tr>
        </thead>
        <tbody><tr>
<td align=\"center\" style=\"border-collapse: collapse;font-family: &#39;Open Sans&#39;, sans-serif; padding-top:12px; padding-bottom:12px; padding-left:16px; padding-right:16px; color:#000; border:1px solid #cccccc;\">content1</td>
            </tr>
</tbody>
</table>