我在代码中有一个表要打印,它看起来像这样:
当我尝试打印表格时,它的打印格式如下所示:
我需要更改打印 View 中文本的字体大小,还需要更改打印 View 中的列大小。另外,如果我可以删除 Web 表的打印 View 中的边框。
我使用 javascript 来打印表格。我已经使用了表 ID。
<script type="text/javascript">
function PrintPage()
{
var TableToPrint = document.getElementById('thisIDisforprinting2');
newWin = window.open("");
newWin.document.write(TableToPrint.outerHTML);
newWin.print();
newWin.close();
}
</script>
最佳答案
您可以使用 document.write 添加 css 标签,并使用“打印”媒体查询根据需要设置表格样式。
函数 PrintPage() {
var TableToPrint = document.getElementById('thisIDisforprinting2');
newWin = window.open("");
newWin.document.write(TableToPrint.outerHTML);
newWin.document.write('<style type="text/css"> @media print { #thisIDisforprinting2 { font-size: 24px; } }</style>');
newWin.print();
newWin.close();
}
低于设置列高并删除边框的版本
newWin.document.write('<style type="text/css"> @media print { #thisIDisforprinting2 { font-size: 24px; border: none; } #thisIDisforprinting2 td { height: 150px; border: none; } } </style>');
关于html - 打印 asp.net、javascript 后更改表格的字体大小和列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52488834/