angular - 以角度将具有结构的HTML表格复制到剪贴板
问题描述
我正在尝试将整个 HTML 表格及其结构复制到有角度的剪贴板。复制部分工作正常,但没有遵循确切的表格布局。
似乎它正确地遵循了标题的布局,但数据布局是错误的。
用来实现这个东西的方法
selectNode(node){
let range = document.createRange();
range.selectNodeContents(node)
let select = window.getSelection()
select.removeAllRanges()
select.addRange(range)
}
copy(){
this.selectNode(this.queryTable.nativeElement);
document.execCommand('copy');
}
HTML:
<table id="queryTable" class="table table-responsive-sm table-hover table-outline mb-0" #queryTable>
<thead class="text-center no-padding" style="background: #0042be;">
<tr class="querytableheaderstyling">
<th *ngFor="let key of debugQueryData">{{key}}</th>
</tr>
</thead>
<tbody class="text-center">
<tr *ngFor="let value of debugResult | filter : filters.searchUsersText">
<td *ngFor="let key of debugQueryData; index as i" style="padding:0px 10px !important"><div [innerHTML]="value[key]"></div></td>
</tr>
</tbody>
</table>
我做错了什么,我怎样才能让它发挥作用?
PS:由于几个原因,我不能在这种情况下使用 DataTable。我正在使用基于 HTML 的简单表格,因此请提供可以在这种情况下工作的解决方案。
解决方案
检查您复制的原始值,似乎您在那里/n
或类似的东西。
尝试添加nodeString.strip()
以删除数据中的任何特殊字符。
甚至像这样从复制的输入中删除所有特殊字符
str.replace(/[^a-zA-Z ]/g, "")
希望能帮助到你
推荐阅读
- java - 水平滚动条不适用于 JScrollPane
- azure-cognitive-search - 在天蓝色搜索中按多个字段分组/分面
- python - 用于检查特定键是否存在于列表和字典的字典中的 Python 代码
- memory - 操作系统
- database - 尝试加密我的 Access 数据库时,它会冻结,并在 10 分钟后显示“系统资源超出”
- java - .jar 文件 FileNotFoundException 使用 getClass().getResource()
- ios - Swift 无法将 NSNumber 桥接到 Int
- android - 如何更改 TimePicker 字体颜色
- gmail - 如何从我的主要 gmail 帐户中删除连接的 gmail 帐户
- javascript - 为 JS 文档指定 errorpage.html.getElementById('link_id').value + '.html'; 如果在目录中找不到值?