I have a table with several columns.
When you print such table, the columns on right will not print, not even when you print in landsc
Here is my go at this:
What I did was:
Example: if the table is 2000px wide and page width is set to 600px then y should be 4 and x will be 0, 600, 1200 and 1800.
use
@media print{@page {size: landscape}}
See this question: Print Stylesheets for pages with long horizontal tables
The point is that you can't get a browser to print horizontal tables the same way as excel does. You have to switch to something that is at most one page wide.
The answer provided by @(Salman A) worked well for me on Chrome and Firefox. I modified it to break at column boundaries with the following:
var acSplitTable = function() {
var table = $(".ac-print .ac-grid>table"),
tableWidth = table.outerWidth(),
pageWidth = 600,
pageCount = Math.ceil(tableWidth / pageWidth),
printWrap = $("<div></div>").insertAfter(table),
i,
printPage;
$(".ac-print .ac-grid>table .ac-hidden").remove();
var positions = [];
var lastOuterWidth = 0;
$(".ac-print .ac-grid>table th").each(function() {
positions.push($(this).position().left);
lastOuterWidth = $(this).outerWidth;
});
var pageWidths = [];
var endColumns = [];
var lastPosition = 0;
for (i = 1; i < positions.length; i++) {
if ((positions[i] - lastPosition) > pageWidth) {
pageWidths.push(positions[i - 1] - lastPosition);
lastPosition = positions[i - 1];
endColumns.push(i - 1);
}
if (i == (positions.length - 1)) {
pageWidths.push(positions[i] + lastOuterWidth - lastPosition);
lastPosition = positions[i];
endColumns.push(i);
}
}
pageCount = pageWidths.length;
var lastEndColumn = 0;
for (i = 0; i < pageCount; i++) {
var thisPageWidth = pageWidth; //pageWidths[i];
var styleString = "overflow: hidden; width:" + thisPageWidth + "px; page-break-before: " + (i === 0 ? "auto" : "always") + ";";
var newTable = table.clone().attr("id", "ac-print-page-" + i);
newTable.attr("style", styleString);
newTable.appendTo("#formpoint");
//remove columns either side of our page
for (var j = positions.length - 1; j >= 0; j--) {
if (j > endColumns[i] || j <= lastEndColumn) {
var index = j + 1;
var heading = $(newTable).find("tr th:nth-child(" + index + ")");
$(newTable).find("tr th:nth-child(" + index + ")").remove();
$(newTable).find("tr td:nth-child(" + index + ")").remove();
}
}
lastEndColumn = endColumns[i];
}
table.hide();
$(this).prop("disabled", true);
window.print();
setTimeout(window.close, 0);
};