gpt4 book ai didi

html - 打印一个非常宽的 HTML 表格而不裁剪右侧

转载 作者:技术小花猫 更新时间:2023-10-29 12:10:33 25 4
gpt4 key购买 nike

我有一个包含多个列的表格。

具体问题

当您打印此类表格时,右侧的列将不会打印,即使您横向打印时也是如此。

期望的行为

浏览器应该打印整个表格,必要时使用多张表格。 CSS/JavaScript 解决方案是可以接受的。

重现问题所需的最短代码

点击以下演示中的打印按钮。在打印预览窗口中查看页面的右侧。

$(function() {
$("input:first").click(function() {
window.print();
});
$(".description").each(function() {
var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla placerat malesuada sodales. Nulla convallis neque lorem, ac varius enim. Ut dapibus, orci at feugiat eleifend, dui mi lobortis tortor, ac egestas neque enim et neque. Donec tempus mi quis tellus dapibus eu blandit magna sagittis. Curabitur ac ultrices tortor. Aliquam id tincidunt urna. Nunc id neque ac urna congue convallis. Etiam eget massa vitae justo aliquam pulvinar vitae ut diam.";
text = text.substr(0, Math.ceil(Math.random() * 100));
$(this).text(text);
});
$(".number").each(function() {
var text = (Math.random() * 1000).toFixed(2);
$(this).text(text);
});
});
@media screen {
input {
width: 100%;
margin: 1em 0;
}
}
@media print {
input {
display: none;
}
}
th {
font: bold 12px sans-serif;
border: 1px solid;
white-space: nowrap;
}
td {
font: 12px sans-serif;
border: 1px dotted;
}
td.description {
min-width: 200px;
border-style: solid;
}
td.number {
padding-left: 20px;
text-align: right;
border-style: solid;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<input type="button" value="Print">

<table>
<tr>
<td></td>
<td></td>
<th colspan="12">2009</th>
<th colspan="12">2010</th>
<td></td>
</tr>
<tr>
<td></td>
<th>Description</th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
<th>Jan</th>
<th>Feb</th>
<th>Mar</th>
<th>Apr</th>
<th>May</th>
<th>Jun</th>
<th>Jul</th>
<th>Aug</th>
<th>Sep</th>
<th>Oct</th>
<th>Nov</th>
<th>Dec</th>
<th>Total</th>
</tr>
<tr>
<th rowspan="2">Batch number 1</th>
<td rowspan="2" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th rowspan="4">Batch number 2</th>
<td rowspan="4" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th rowspan="4">Batch number 3</th>
<td rowspan="4" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th rowspan="2">Batch number 4</th>
<td rowspan="2" class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
<tr>
<th>Total</th>
<td class="description"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
<td class="number"></td>
</tr>
</table>

最佳答案

这是我的做法:

我所做的是:

  • 创建适合 A4 尺寸页面的固定宽度的 div
  • 将表格复制到该 div 中
  • 滚动表格 x 像素以使用 CSS 定位将所需部分置于“焦点”中
  • 重复此过程 y

示例:如果表格宽度为 2000 像素,页面宽度设置为 600 像素,则 y 应为 4x 将为 0、600、12001800

关于html - 打印一个非常宽的 HTML 表格而不裁剪右侧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8891944/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com