将 html 表导出到一列上有 tinymce 的单词
Posted
技术标签:
【中文标题】将 html 表导出到一列上有 tinymce 的单词【英文标题】:Export html table to word that have tinymce on one column 【发布时间】:2019-11-23 20:01:17 【问题描述】:我有一个 html 视图,想将上面有 tinymce 的表格内容导出到 Microsoft Word 甚至 Microsoft Excel。 但是当我将它导出到 word 时,我会在 word 文件中得到 textarea 而不仅仅是列的文本。
提前致谢。
我的word文件:
我的 HTML 视图:
function export2Word(element)
var html, link, blob, url, css;
css = (
'<style>' +
'@page WordSection1size: 21cm 29.7cm;' +
'div.WordSection1 page: WordSection1;' +
'</style>'
);
html = element.innerHTML;
blob = new Blob(['\ufeff', css + html],
type: 'application/msword'
);
url = URL.createObjectURL(blob);
link = document.createElement('A');
link.href = url;
link.download = 'Document'; // default name without extension
document.body.appendChild(link);
if (navigator.msSaveOrOpenBlob) navigator.msSaveOrOpenBlob(blob, 'Document.doc'); // IE10-11
else link.click(); // other browsers
document.body.removeChild(link);
;
<body dir="rtl">
<button onclick="export2Word(window.docx)">Export</button>
<br>
<div id="docx">
<div class="WordSection1" dir="rtl">
<table border="1" align="center" style="text-align: center" id="testtable">
<thead>
<tr>
<td colspan="2" style="width: 10%">شهرت دریور</td>
<td rowspan="2" style="width: 10%">نوع واسطه</td>
<td rowspan="2" style="width: 10%">نمبر پلیت</td>
<td rowspan="2" style="width: 10%">نمبر پارچه عوارض</td>
<td rowspan="2" style="width: 25%;height: 90%">تثبیت عوارض</td>
<td rowspan="2" style="width: 10%">تاریخ تثبیت</td>
<td rowspan="2">شماره حکم</td>
<td rowspan="2">شماره صادر</td>
<td rowspan="2">پرزه جات خریداری شده</td>
<td rowspan="2">تعداد</td>
<td rowspan="2">قیمت فی واحد</td>
<td rowspan="2" style="text-wrap:inherit">قیمت عمومی</td>
<td rowspan="2">تاریخ</td>
<td rowspan="2">ملاحظات</td>
</tr>
<tr>
<td>اسم</td>
<td>ولد</td>
</tr>
</thead>
<tbody>
@foreach($result as $a=>$row)
<tr>
<td id="">$row->driver_name</td>
<td id="">$row->father_name</td>
<td id="">$row->vehicle_type</td>
<td id="">$row->plate_no</td>
<td id="">$row->serial_number</td>
<td><textarea class="checkkkkk" id="ddd$bbb">$row->description</textarea>
</td>
<td id="asdf$aaa">
<script type="text/javascript">
$(document).ready(function()
$("#asdf" +
$aaa
+ "").text(moment("$row->created_at").format('jYYYY/jM/jD'));
);
</script>
$aaa++
</td>
<td id="">$row->order_number</td>
<td id="">$row->export_number</td>
<td>$row->buy_parts</td>
<td id="">$row->quantity</td>
<td id="">$row->per_item_price</td>
<td id="">$row->total_price</td>
<td id="">$row->export_date</td>
<td id="">$row->remarks</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div>
</body>
或者是否有任何 javascript 库即使使用 tinymce 也可以做到这一点
【问题讨论】:
【参考方案1】:Follow this instruction for export Doc with Excel file
http://localhost/tableToDoc.php?rType=1&fName=test
-Copy this code and see
- First of all create the table by Microsoft office then go to 'Preview in Web Browser' then Ctrl+u. Copy this source code and past your html page. you can change this source code.
<!DOCTYPE html>
<html lang="bn">
<?php
$repFor = $_GET['rType'];
$fileName = $_GET['fName'];
header("Content-type: application/vnd.ms-word");
if($repFor == '1') // 2 = Export excel file
header("Content-Disposition: attachment;Filename=".$fileName.".xls");
if($repFor == '2') // 3 = Export word file
header("Content-Disposition: attachment;Filename=".$fileName.".doc");
echo "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=Windows-1252\">";
?>
<head>
<title>HTML Table to xls and doc file export</title>
<style type="text/css">
@page
size: landscape;
.tblBorder
border-top: 1px solid #000000;
border-bottom: 1px solid #000000;
border-left: 1px solid #000000;
border-right: none;
padding-top: 0.04in;
padding-bottom: 0.04in;
padding-left: 0.04in;
padding-right: 0in
.tblBorder2
border-top: none; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: none; padding-top: 0in; padding-bottom: 0.04in; padding-left: 0.04in; padding-right: 0in
</style>
</head>
<body lang="en-US" dir="ltr">
<table cellpadding="4" cellspacing="0">
<tr valign="top">
<td rowspan="2" class="tblBorder">
<p align="center">Name</p>
</td>
<td rowspan="2" class="tblBorder">
<p align="center">Website</p>
</td>
<td rowspan="2" class="tblBorder">
<p align="center">Sub-Table</p>
</td>
<td rowspan="2" class="tblBorder">
<p align="center">Subject</p>
</td>
<td colspan="2" style="border: 1px solid #000000; padding: 0.04in">
<p align="center">Group</p>
</td>
</tr>
<tr valign="top">
<td class="tblBorder2">
<p align="center">Science</p>
</td>
<td style="border-top: none; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding-top: 0in; padding-bottom: 0.04in; padding-left: 0.04in; padding-right: 0.04in">
<p align="center">Arts</p>
</td>
</tr>
<tr valign="top">
<td class="tblBorder2">
Bulbul
</td>
<td class="tblBorder2">
bdprescription.com
</td>
<td class="tblBorder2">
<div>
<table >
<tr>
<td class="tblBorder">Sub-Table</td>
<td class="tblBorder">Sub-Table</td>
</tr>
<tr>
<td class="tblBorder">Sub-Table</td>
<td class="tblBorder">Sub-Table</td>
</tr>
</table>
</div>
</td>
<td class="tblBorder2">
Match
</td>
<td class="tblBorder2">
Yes
</td>
<td style="border-top: none; border-bottom: 1px solid #000000; border-left: 1px solid #000000; border-right: 1px solid #000000; padding-top: 0in; padding-bottom: 0.04in; padding-left: 0.04in; padding-right: 0.04in">
No
</td>
</tr>
</table>
</body>
</html>
【讨论】:
感谢您的重播,但我想要与您所说的相反,我想将 html 表格导出为 word 或 excel,并在其上添加 tinymce 欢迎您,如果您在每个您可以在表中使用direction:rtl
,它会为您修复该逆向
css =
"<style>" +
"@page WordSection1size: 841.95pt 595.35pt;mso-page-orientation: landscape;" +
"div.WordSection1 page: WordSection1; dir:rtl " +
" table border-collapse: collapse;width: 100%;direction:rtl;" +
"</style>";
【讨论】:
以上是关于将 html 表导出到一列上有 tinymce 的单词的主要内容,如果未能解决你的问题,请参考以下文章
Python Dataframe:在一列上使用Groupby计算R ^ 2和RMSE