彩票走势图

纯前端表格控件SpreadJS示例教程:纳税单示例

转帖|使用教程|编辑:鲍佳佳|2021-03-01 11:17:28.453|阅读 130 次

概述:下面的示例展示了如何用SpreadJS轻松地创建复杂输入表单,比如1040表单(美国个人所得税的纳税申报表)。

# 慧都年终大促·界面/图表报表/文档/IDE等千款热门软控件火热促销中 >>

相关链接:

SpreadJS 是一款基于 HTML5 的纯前端电子表格控件,兼容 450 种以上的 Excel 公式,具有 “高性能、跨平台、与 Excel 高度兼容”的产品特性SpreadJS 为用户带来亲切的 Excel 使用体验的同时,满足 Web Excel 组件开发、表格文档协同编辑、数据填报、Excel 类报表设计等业务场景,极大降低了企业研发成本和项目交付风险。下面我们将讲述在使用SpreadJS进行开发时如何应用Excel主题。

下载最新版SpreadJS

下面的示例展示了如何用SpreadJS轻松地创建复杂输入表单,比如1040表单(美国个人所得税的纳税申报表)。

这个示例主要使用了锁定单元格来阻止编辑行为、竖直对齐,还通过fromJSON加载了预定义的模板。

app.js:

window.onload = function () {
            var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 });
            initSpread(spread);
        };

        function initSpread(spread) {
            var sd = data;
            if (sd.length > 0) {
                if (!spread) {
                    return;
                }
                spread.suspendPaint();
                spread.fromJSON(sd[0]);
                spread.options.tabStripVisible = false;

                var sheet = spread.getSheet(0);

                sheet.options.isProtected = true;
                sheet.options.gridline = { showHorizontalGridline: false, showVerticalGridline: false };
                sheet.getRange(-1, 0, -1, sheet.getColumnCount(GC.Spread.Sheets.SheetArea.rowHeader), GC.Spread.Sheets.SheetArea.rowHeader).visible(false);
                sheet.getRange(0, -1, sheet.getRowCount(GC.Spread.Sheets.SheetArea.colHeader), -1, GC.Spread.Sheets.SheetArea.colHeader).visible(false);

                var style = sheet.getStyle(1, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(1, 1, style);
                }

                style = sheet.getStyle(3, 3, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(3, 3, style);
                }

                style = sheet.getStyle(7, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(7, 1, style);
                }

                style = sheet.getStyle(5, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(5, 1, style);
                }

                style = sheet.getStyle(9, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(9, 1, style);
                }

                style = sheet.getStyle(15, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(15, 1, style);
                    sheet.setStyle(21, 1, style);
                }

                style = sheet.getStyle(31, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(31, 1, style);
                }

                style = sheet.getStyle(37, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(37, 1, style);
                }

                style = sheet.getStyle(41, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(41, 1, style);
                }

                style = sheet.getStyle(46, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(46, 1, style);
                }

                style = sheet.getStyle(17, 22, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(17, 22, style);
                }

                style = sheet.getStyle(19, 12, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(19, 12, style);
                    sheet.setStyle(19, 16, style);
                    sheet.setStyle(19, 18, style);
                }

                style = sheet.getStyle(8, 21, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(8, 21, style);
                }

                style = sheet.getStyle(10, 21, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.wordWrap = true;
                    sheet.setStyle(10, 21, style);
                }

                style = sheet.getStyle(13, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.font = "normal bold 14px Calibri";
                    sheet.setStyle(13, 1, style);
                    sheet.setStyle(17, 1, style);
                    sheet.setStyle(28, 1, style);
                }

                style = sheet.getStyle(46, 1, GC.Spread.Sheets.SheetArea.viewport);
                if (style) {
                    style.font = "normal bold 14px Calibri";
                    style.wordWrap = true;
                    sheet.setStyle(46, 1, style);
                }

                spread.resumePaint();
            }
        }

index.html:

<!doctype html>
<html style="height:100%;font-size:14px;">

<head>
    <meta name="spreadjs culture" content="zh-cn" />
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css">
    <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script>
    <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js" type="text/javascript"></script>
    <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script>
    <script src="$DEMOROOT$/spread/source/data/taxform.js" type="text/javascript"></script>
    <script src="app.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="styles.css">
</head>
<body>

    <div class="sample-tutorial">
        <div id="ss" style="width:100%;height:100%"></div>
    </div>
</body>
</html>

style.css:

.sample-tutorial {
    position: relative;
    height: 100%;
    overflow: hidden;
}

body {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    right: 0;
}

本文转载自:

赶快下载体验吧!现推出限时活动,SpreadJS正版授权低至3490元!欢迎咨询慧都在线客服了解详情!


标签:

本站文章除注明转载外,均为本站原创或翻译。欢迎任何形式的转载,但请务必注明出处、不得修改原文相关链接,如果存在内容上的异议请邮件反馈至chenjj@pclwef.cn

文章转载自:

为你推荐

  • 推荐视频
  • 推荐活动
  • 推荐产品
  • 推荐文章
  • 慧都慧问
扫码咨询


添加微信 立即咨询

电话咨询

客服热线
023-68661681

TOP