找回密码
 立即注册

QQ登录

只需一步,快速开始

junhaha

注册会员

2

主题

9

帖子

27

积分

注册会员

积分
27
最新发帖
junhaha
注册会员   /  发表于:2016-10-18 10:11  /   查看:5814  /  回复:10
本帖最后由 junhaha 于 2016-10-18 10:17 编辑

想用A4纸横向打印一页内容。设置总是不成功,使用的谷歌浏览器

为了演示效果,用了官网上打印的例子,稍作修改(横向添加了三列数据,这样纵向分两页是情理之中的,但是横向打印应该在一页啊),代码如下

<!doctype html>
<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="spreadjs culture" content="zh-cn" />


    <link href="http://demo.gcpowertools.com.cn/SpreadJS/TutorialSample/external/spreadjs/css/gcspread.sheets.excel2013white.9.40.20161.0.css" rel="stylesheet" type="text/css" />

    <script src="http://demo.gcpowertools.com.cn/SpreadJS/TutorialSample/external/external/jquery-1.8.2.min.js" type="text/javascript"></script>

    <script type="text/javascript" src="http://demo.gcpowertools.com.cn/SpreadJS/TutorialSample/external/spreadjs/gcspread.sheets.all.9.40.20161.0.min.js"></script>


    <script type="text/javascript" src="http://cdn.grapecity.com/spreadjs/hosted/scripts/pluggable/gcspread.sheets.print.9.40.20161.0.min.js"></script>








    <style type="text/css">
        .demo-options, .option-row {
            margin-top: 10px;
        }

    </style>
    <script type="text/javascript">

    $(document).ready(function () {
        var spread = new GcSpread.Sheets.Spread(document.getElementById("ss"));

        initSpread(spread);

        $("#btnPrint").click(function () {
            // used to adjust print range, should set with printInfo (refer custom print for detail)
            spread.sheets[0].setText(31, 11, " ");


              //这里是添加的几行代码
                        var sheet = spread.getActiveSheet();
                        var printInfo = sheet.printInfo();
                        printInfo.paperSize(new GcSpread.Sheets.PaperSize(GcSpread.Sheets.PaperKind.A4));
                        printInfo.orientation(GcSpread.Sheets.PrintPageOrientation.Landscape);

            spread.print();
        });
    });

    function initSpread(spread) {
        var sheet = spread.getActiveSheet();

        sheet.isPaintSuspended(true);
        sheet.allowCellOverflow(true);
        sheet.setName("Demo");

        sheet.addSpan(1, 1, 1, 3);
        sheet.setValue(1, 1, "Store");
        sheet.addSpan(1, 4, 1, 7);
        sheet.setValue(1, 4, "Goods");
        sheet.addSpan(2, 1, 1, 2);
        sheet.setValue(2, 1, "Area");
        sheet.addSpan(2, 3, 2, 1);
        sheet.setValue(2, 3, "ID");
        sheet.addSpan(2, 4, 1, 2);
        sheet.setValue(2, 4, "Fruits");
        sheet.addSpan(2, 6, 1, 2);
        sheet.setValue(2, 6, "Vegetables");
        sheet.addSpan(2, 8, 1, 2);
        sheet.setValue(2, 8, "Foods");
        sheet.addSpan(2, 10, 2, 1);
        sheet.setValue(2, 10, "Total");

        sheet.setValue(3, 1, "State");
        sheet.setValue(3, 2, "City");
        sheet.setValue(3, 4, "Grape");
        sheet.setValue(3, 5, "Apple");
        sheet.setValue(3, 6, "Potato");
        sheet.setValue(3, 7, "Tomato");
        sheet.setValue(3, 8, "SandWich");
        sheet.setValue(3, 9, "Hamburger");

        sheet.addSpan(4, 1, 7, 1);
        sheet.addSpan(4, 2, 3, 1);
        sheet.addSpan(7, 2, 3, 1);
        sheet.addSpan(10, 2, 1, 2);
        sheet.setValue(10, 2, "Sub Total:");
        sheet.addSpan(11, 1, 7, 1);
        sheet.addSpan(11, 2, 3, 1);
        sheet.addSpan(14, 2, 3, 1);
        sheet.addSpan(17, 2, 1, 2);
        sheet.setValue(17, 2, "Sub Total:");
        sheet.addSpan(18, 1, 1, 3);
        sheet.setValue(18, 1, "Total:");

        sheet.setValue(4, 1, "NC");
        sheet.setValue(4, 2, "Raleigh");
        sheet.setValue(7, 2, "Charlotte");
        sheet.setValue(4, 3, "001");
        sheet.setValue(5, 3, "002");
        sheet.setValue(6, 3, "003");
        sheet.setValue(7, 3, "004");
        sheet.setValue(8, 3, "005");
        sheet.setValue(9, 3, "006");
        sheet.setValue(11, 1, "PA");
        sheet.setValue(11, 2, "Philadelphia");
        sheet.setValue(14, 2, "Pittsburgh");
        sheet.setValue(11, 3, "007");
        sheet.setValue(12, 3, "008");
        sheet.setValue(13, 3, "009");
        sheet.setValue(14, 3, "010");
        sheet.setValue(15, 3, "011");
        sheet.setValue(16, 3, "012");

        sheet.setFormula(10, 4, "=SUM(E5:E10)");
        sheet.setFormula(10, 5, "=SUM(F5:F10)");
        sheet.setFormula(10, 6, "=SUM(G5:G10)");
        sheet.setFormula(10, 7, "=SUM(H5:H10)");
        sheet.setFormula(10, 8, "=SUM(I5:I10)");
        sheet.setFormula(10, 9, "=SUM(J5:J10)");

        sheet.setFormula(17, 4, "=SUM(E12:E17)");
        sheet.setFormula(17, 5, "=SUM(F12:F17)");
        sheet.setFormula(17, 6, "=SUM(G12:G17)");
        sheet.setFormula(17, 7, "=SUM(H12:H17)");
        sheet.setFormula(17, 8, "=SUM(I12:I17)");
        sheet.setFormula(17, 9, "=SUM(J12:J17)");

        for (var i = 0; i < 14; i++) {
            sheet.setFormula(4 + i, 10, "=SUM(E" + (5 + i).toString() + ":J" + (5 + i).toString() + ")");
        }

        sheet.setFormula(18, 4, "=E11+E18");
        sheet.setFormula(18, 5, "=F11+F18");
        sheet.setFormula(18, 6, "=G11+G18");
        sheet.setFormula(18, 7, "=H11+H18");
        sheet.setFormula(18, 8, "=I11+I18");
        sheet.setFormula(18, 9, "=J11+J18");
        sheet.setFormula(18, 10, "=K11+K18");

        sheet.getCells(1, 1, 3, 10).backColor("#D9D9FF");
        sheet.getCells(4, 1, 18, 3).backColor("#D9FFD9");
        sheet.getCells(1, 1, 3, 10).hAlign(GcSpread.Sheets.HorizontalAlign.center);

        sheet.setBorder(new GcSpread.Sheets.Range(1, 1, 18, 10), new GcSpread.Sheets.LineBorder("Black", GcSpread.Sheets.LineStyle.thin), { all: true });
        sheet.setBorder(new GcSpread.Sheets.Range(4, 4, 3, 6), new GcSpread.Sheets.LineBorder("Black", GcSpread.Sheets.LineStyle.dotted), { inside: true });
        sheet.setBorder(new GcSpread.Sheets.Range(7, 4, 3, 6), new GcSpread.Sheets.LineBorder("Black", GcSpread.Sheets.LineStyle.dotted), { inside: true });
        sheet.setBorder(new GcSpread.Sheets.Range(11, 4, 3, 6), new GcSpread.Sheets.LineBorder("Black", GcSpread.Sheets.LineStyle.dotted), { inside: true });
        sheet.setBorder(new GcSpread.Sheets.Range(14, 4, 3, 6), new GcSpread.Sheets.LineBorder("Black", GcSpread.Sheets.LineStyle.dotted), { inside: true });

        fillSampleData(sheet, new GcSpread.Sheets.Range(4, 4, 6, 10));
        fillSampleData(sheet, new GcSpread.Sheets.Range(11, 4, 6, 10));

        sheet.setColumnWidth(0, 40);
        sheet.setColumnWidth(1, 40);
        sheet.setColumnWidth(3, 40);
        sheet.setColumnWidth(4, 40);
        sheet.setColumnWidth(11, 40);

      // addFigures(sheet);//这里去掉了饼状图,去掉多余的影响因素

        sheet.isPaintSuspended(false);
    }

    function fillSampleData(sheet, range) {
        for (var i = 0; i < range.rowCount; i++) {
            for (var j = 0; j < range.colCount; j++) {
                sheet.setValue(range.row + i, range.col + j, Math.ceil(Math.random() * 300));
            }
        }
    }

    function addFigures(sheet) {
        sheet.setFormula(20, 1, "=SUM(K5:K7)");
        sheet.setFormula(20, 2, "=SUM(K8:K10)");
        sheet.setFormula(20, 3, "=SUM(K12:K14)");
        sheet.setFormula(20, 4, "=SUM(K15:K17)");

        sheet.getRow(20).visible(false);
        sheet.addSpan(21, 5, 10, 4);
        sheet.setFormula(21, 5, '=PIESPARKLINE(B21:E21, "#0000FF","#FF0000","#00FF00","#FFFF00")');
        sheet.addSpan(31, 5, 1, 4);
        sheet.getCell(31, 5).text("Figure 1").hAlign(1);
    }

    </script>
</head>
<body>
    <div class="sample-turtorial">
        <div id="ss" style="width:100%; height:580px;border: 1px solid gray;"></div>
    </div>
    <br />
    <input type="button" value="Print" id="btnPrint">
</body>
</html>


求帮助,看看哪里设置有问题

10 个回复

倒序浏览
junhaha
注册会员   /  发表于:2016-10-18 10:51:47
沙发
在线等,急,谢谢各位帅哥
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-10-18 11:37:03
板凳
您好,问题已重现,当选择横向打印时,无法将多于的行打印到同一页中,中间会插入空白页。
正在寻找解决方法。

回复 使用道具 举报
junhaha
注册会员   /  发表于:2016-10-18 11:53:28
地板
Lenka.Guo 发表于 2016-10-18 11:37
您好,问题已重现,当选择横向打印时,无法将多于的行打印到同一页中,中间会插入空白页。
正在寻找解决方 ...

应该不是多余的行的问题
我又简化了代码做了测试,我只打印两三行,同样会出现第二页是空白的情况,html文件代码贴出来如下,为了简化,数据不设置了,打印时候只设定打印的行数和列数,打印效果如下图,选择横向还是两页,第二页是空白的

<!doctype html>
<html>
<head>
    <title></title>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="spreadjs culture" content="zh-cn" />


    <link href="http://demo.gcpowertools.com.cn/SpreadJS/TutorialSample/external/spreadjs/css/gcspread.sheets.excel2013white.9.40.20161.0.css" rel="stylesheet" type="text/css" />

    <script src="http://demo.gcpowertools.com.cn/SpreadJS/TutorialSample/external/external/jquery-1.8.2.min.js" type="text/javascript"></script>

    <script type="text/javascript" src="http://demo.gcpowertools.com.cn/SpreadJS/TutorialSample/external/spreadjs/gcspread.sheets.all.9.40.20161.0.min.js"></script>

    <script type="text/javascript" src="http://cdn.grapecity.com/spreadjs/hosted/scripts/pluggable/gcspread.sheets.print.9.40.20161.0.min.js"></script>

    <script type="text/javascript">

    $(document).ready(function () {
        var spread = new GcSpread.Sheets.Spread(document.getElementById("ss"));

        $("#btnPrint").click(function () {
                        var sheet = spread.getActiveSheet();
                        var printInfo = sheet.printInfo();
                        printInfo.rowStart(1);
                        printInfo.rowEnd(3);
                        printInfo.columnStart(1);
                        printInfo.columnEnd(3);

                        printInfo.orientation(GcSpread.Sheets.PrintPageOrientation.Portrait);
                        printInfo.paperSize(new GcSpread.Sheets.PaperSize(GcSpread.Sheets.PaperKind.A4));
                        printInfo.margin({top:0, bottom:0, left:0, right:0, header:0, footer:0});

            spread.print();
        });
    });
    </script>
</head>
<body>
    <div class="sample-turtorial">
        <div id="ss" style="width:100%; height:580px;border: 1px solid gray;"></div>
    </div>
    <br />
    <input type="button" value="Print" id="btnPrint">
</body>
</html>



lizi

lizi


回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-10-18 11:53:41
5#
本帖最后由 Lenka.Guo 于 2016-10-18 12:20 编辑

您好,纯前端控件本身是无法获知打印机设置横向打印的,如需横向排版可以通过设置PageSize来达到该效果,如果更改纸张的为A4横向,则打印正常,
代码:
printInfo.paperSize(new GcSpread.Sheets.PaperSize(GcSpread.Sheets.PaperKind.A4Rotated));
printInfo.orientation(GcSpread.Sheets.PrintPageOrientation.Landscape);

回复 使用道具 举报
junhaha
注册会员   /  发表于:2016-10-18 12:40:14
6#
本帖最后由 junhaha 于 2016-10-18 13:22 编辑
Lenka.Guo 发表于 2016-10-18 11:53
您好,纯前端控件本身是无法获知打印机设置横向打印的,如需横向排版可以通过设置PageSize来达到该效果,如 ...

我打印机设置的为横向

printInfo.paperSize(new GcSpread.Sheets.PaperSize(GcSpread.Sheets.PaperKind.A4Rotated));
printInfo.orientation(GcSpread.Sheets.PrintPageOrientation.Landscape);
好像还是不起效果

似乎只要打印机设置为横向,无论代码如何调整,都是两页,第二页是空白页。
我认为代码中设置为横向A4,打印机也设置为横向A4,不应该分两页的啊,因为打印设置就打印两行数据,两列数据
回复 使用道具 举报
junhaha
注册会员   /  发表于:2016-10-18 13:39:59
7#
本帖最后由 junhaha 于 2016-10-18 19:29 编辑
Lenka.Guo 发表于 2016-10-18 11:53
您好,纯前端控件本身是无法获知打印机设置横向打印的,如需横向排版可以通过设置PageSize来达到该效果,如 ...

排版时候 A4纸,横向
然后高度要再减少35,这样打印预览的时候,是一张纸上,不知道为什么要减少这一点,

var pSize = new GcSpread.Sheets.PaperSize(GcSpread.Sheets.PaperKind.A4Rotated);
var w = pSize._width;
var h = pSize._height;
var pSize2 = new GcSpread.Sheets.PaperSize(w,h-35);
printInfo.paperSize(pSize2);
这几行代码,执行后解决了插空白页的问题
回复 使用道具 举报
Lenka.Guo讲师达人认证 悬赏达人认证
超级版主   /  发表于:2016-10-18 14:20:48
8#
回复 使用道具 举报
junhaha
注册会员   /  发表于:2016-10-18 14:48:58
9#

你给的这个链接中的例子是横向打印超过一页的情况下,接下来打印怎么连续的问题

我现在的疑问是printInfo.paperSize(new GcSpread.Sheets.PaperSize(GcSpread.Sheets.PaperKind.A4Rotated));

个人感觉这个官方的横向排版是不正确的,有个误差35,不手动减去这个高度,就不正常
不知道是不是这样子
回复 使用道具 举报
junhaha
注册会员   /  发表于:2016-10-18 15:28:12
10#
junhaha 发表于 2016-10-18 14:48
你给的这个链接中的例子是横向打印超过一页的情况下,接下来打印怎么连续的问题

我现在的疑问是printI ...

感觉这个误差35根marginprintInfo.margin 对象的right值有关,默认right值是70,当调整这个right值时候,这个误差值会跟着变
margin的left值也是70,但是调整的时候这个误差值不会变。

所以认为这个跟margin的right值有关,而且70正好是35的二倍,不知道是不是巧合还是真的有联系。。。。
回复 使用道具 举报
12下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部