|
本帖最后由 52yaoer 于 2021-10-25 17:41 编辑
exportExcel封装了生成Excel文件的接口逻辑。
点击进入模块详情
- <!DOCTYPE html>
- <html>
- <head>
- <title>Module Develop</title>
- <meta charset="utf-8">
- <meta name="viewport"
- content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
- <style type="text/css">
- html,
- body {
- height: 100%
- }
- body {
- background-color: #fff;
- margin: 0;
- }
- #wrap {
- height: 100%;
- position: relative;
- }
- #header {
- padding-top: 20px;
- background-color: #5082c2;
- height: 44px;
- position: relative;
- }
- #header h1 {
- font-size: 20px;
- height: 44px;
- line-height: 44px;
- margin: 0em;
- color: #fff;
- margin-left: 100px;
- margin-right: 100px;
- text-align: center;
- }
- #main {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- }
- a.button {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- -webkit-box-align: center;
- height: 32px;
- margin: 8px;
- background-color: rgba(240, 240, 240, 1.0);
- border-color: rgba(220, 220, 220, 1.0);
- border-width: 2px;
- border-style: solid;
- }
- a.active {
- background-color: rgba(240, 240, 240, 0.7);
- }
- </style>
- </head>
- <body>
- <div id="wrap">
- <div id="main">
- <br />
- <a class="button" tapmode="active" onclick="createWorkbook()">创建Workbook</a>
- <a class="button" tapmode="active" onclick="createSheet()">创建Sheet</a>
- <a class="button" tapmode="active" onclick="writeString1()">设置合并标题</a>
- <a class="button" tapmode="active" onclick="setColumnSize()">设置列宽</a>
- <a class="button" tapmode="active" onclick="writeString2()">设置Excel内容</a>
- <a class="button" tapmode="active" onclick="closeWorkbook()">关闭Workbook</a>
- <br />
- </div>
- </div>
- </body>
- <script type="text/javascript">
- var demo = null;
- var fileName;
- apiready = function () {
- demo = api.require('exportExcel');
- if (!demo) {
- alert("请添加模块后编译");
- return;
- }
- }
- function createWorkbook() {
- fileName = 'fs://' + new Date().getTime() + '.xlsx';
- var ret = demo.createWorkbook({ fileName: fileName });
- alert(JSON.stringify(ret));
- }
- function createSheet() {
- var ret = demo.createSheet({ sheetName: 'Sheet1' });
- alert(JSON.stringify(ret));
- }
- function writeString1() {
- demo.writeString({
- row: 0,
- col: 0,
- data: '合并标题测试',
- style: {
- textColor: 1,
- fontSize: 20,
- alignHorizontal: 1,
- alignVertical: 2,
- background: 9
- },
- merge: {
- row: 0,
- col: 9,
- }
- });
- alert('执行完成');
- }
- function setColumnSize() {
- for (var i = 0; i < 10; i++) {//列
- demo.setColumnSize({
- col: i,
- width: 20
- });
- }
- alert('执行完成');
- }
- function writeString2() {
- var row = 0;
- for (var i = 1; i < 100; i++) {//行
- row = i;
- for (var j = 0; j < 10; j++) {//列
- demo.writeString({
- row: row,
- col: j,
- data: '内容' + i,
- style: {
- textColor: 9,
- fontSize: 20,
- alignHorizontal: 1,
- alignVertical: 2,
- borderArray: [{
- pointer: 4,//0:left 1:right 2:top 3:bottom 4:all
- lineStyle: 2
- }]
- }
- });
- }
- }
- alert('执行完成');
- }
- function closeWorkbook() {
- var ret = demo.closeWorkbook();
- alert(JSON.stringify(ret));
- }
- </script>
- </html>
复制代码
|
|