Browse Source

基本完成

yzh 4 years ago
parent
commit
ff5a57d1f3
100 changed files with 194 additions and 0 deletions
  1. 3 0
      .gitignore
  2. 29 0
      composer.json
  3. 8 0
      examples/download.php
  4. 75 0
      examples/export_demo.php
  5. 38 0
      examples/import_demo.php
  6. 1 0
      examples/static/layui/css/layui.css
  7. 1 0
      examples/static/layui/css/layui.mobile.css
  8. 2 0
      examples/static/layui/css/modules/code.css
  9. 1 0
      examples/static/layui/css/modules/laydate/default/laydate.css
  10. BIN
      examples/static/layui/css/modules/layer/default/icon-ext.png
  11. BIN
      examples/static/layui/css/modules/layer/default/icon.png
  12. 1 0
      examples/static/layui/css/modules/layer/default/layer.css
  13. BIN
      examples/static/layui/css/modules/layer/default/loading-0.gif
  14. BIN
      examples/static/layui/css/modules/layer/default/loading-1.gif
  15. BIN
      examples/static/layui/css/modules/layer/default/loading-2.gif
  16. BIN
      examples/static/layui/font/iconfont.eot
  17. 25 0
      examples/static/layui/font/iconfont.svg
  18. BIN
      examples/static/layui/font/iconfont.ttf
  19. BIN
      examples/static/layui/font/iconfont.woff
  20. BIN
      examples/static/layui/font/iconfont.woff2
  21. BIN
      examples/static/layui/images/face/0.gif
  22. BIN
      examples/static/layui/images/face/1.gif
  23. BIN
      examples/static/layui/images/face/10.gif
  24. BIN
      examples/static/layui/images/face/11.gif
  25. BIN
      examples/static/layui/images/face/12.gif
  26. BIN
      examples/static/layui/images/face/13.gif
  27. BIN
      examples/static/layui/images/face/14.gif
  28. BIN
      examples/static/layui/images/face/15.gif
  29. BIN
      examples/static/layui/images/face/16.gif
  30. BIN
      examples/static/layui/images/face/17.gif
  31. BIN
      examples/static/layui/images/face/18.gif
  32. BIN
      examples/static/layui/images/face/19.gif
  33. BIN
      examples/static/layui/images/face/2.gif
  34. BIN
      examples/static/layui/images/face/20.gif
  35. BIN
      examples/static/layui/images/face/21.gif
  36. BIN
      examples/static/layui/images/face/22.gif
  37. BIN
      examples/static/layui/images/face/23.gif
  38. BIN
      examples/static/layui/images/face/24.gif
  39. BIN
      examples/static/layui/images/face/25.gif
  40. BIN
      examples/static/layui/images/face/26.gif
  41. BIN
      examples/static/layui/images/face/27.gif
  42. BIN
      examples/static/layui/images/face/28.gif
  43. BIN
      examples/static/layui/images/face/29.gif
  44. BIN
      examples/static/layui/images/face/3.gif
  45. BIN
      examples/static/layui/images/face/30.gif
  46. BIN
      examples/static/layui/images/face/31.gif
  47. BIN
      examples/static/layui/images/face/32.gif
  48. BIN
      examples/static/layui/images/face/33.gif
  49. BIN
      examples/static/layui/images/face/34.gif
  50. BIN
      examples/static/layui/images/face/35.gif
  51. BIN
      examples/static/layui/images/face/36.gif
  52. BIN
      examples/static/layui/images/face/37.gif
  53. BIN
      examples/static/layui/images/face/38.gif
  54. BIN
      examples/static/layui/images/face/39.gif
  55. BIN
      examples/static/layui/images/face/4.gif
  56. BIN
      examples/static/layui/images/face/40.gif
  57. BIN
      examples/static/layui/images/face/41.gif
  58. BIN
      examples/static/layui/images/face/42.gif
  59. BIN
      examples/static/layui/images/face/43.gif
  60. BIN
      examples/static/layui/images/face/44.gif
  61. BIN
      examples/static/layui/images/face/45.gif
  62. BIN
      examples/static/layui/images/face/46.gif
  63. BIN
      examples/static/layui/images/face/47.gif
  64. BIN
      examples/static/layui/images/face/48.gif
  65. BIN
      examples/static/layui/images/face/49.gif
  66. BIN
      examples/static/layui/images/face/5.gif
  67. BIN
      examples/static/layui/images/face/50.gif
  68. BIN
      examples/static/layui/images/face/51.gif
  69. BIN
      examples/static/layui/images/face/52.gif
  70. BIN
      examples/static/layui/images/face/53.gif
  71. BIN
      examples/static/layui/images/face/54.gif
  72. BIN
      examples/static/layui/images/face/55.gif
  73. BIN
      examples/static/layui/images/face/56.gif
  74. BIN
      examples/static/layui/images/face/57.gif
  75. BIN
      examples/static/layui/images/face/58.gif
  76. BIN
      examples/static/layui/images/face/59.gif
  77. BIN
      examples/static/layui/images/face/6.gif
  78. BIN
      examples/static/layui/images/face/60.gif
  79. BIN
      examples/static/layui/images/face/61.gif
  80. BIN
      examples/static/layui/images/face/62.gif
  81. BIN
      examples/static/layui/images/face/63.gif
  82. BIN
      examples/static/layui/images/face/64.gif
  83. BIN
      examples/static/layui/images/face/65.gif
  84. BIN
      examples/static/layui/images/face/66.gif
  85. BIN
      examples/static/layui/images/face/67.gif
  86. BIN
      examples/static/layui/images/face/68.gif
  87. BIN
      examples/static/layui/images/face/69.gif
  88. BIN
      examples/static/layui/images/face/7.gif
  89. BIN
      examples/static/layui/images/face/70.gif
  90. BIN
      examples/static/layui/images/face/71.gif
  91. BIN
      examples/static/layui/images/face/8.gif
  92. BIN
      examples/static/layui/images/face/9.gif
  93. 1 0
      examples/static/layui/lay/modules/carousel.js
  94. 2 0
      examples/static/layui/lay/modules/code.js
  95. 1 0
      examples/static/layui/lay/modules/colorpicker.js
  96. 1 0
      examples/static/layui/lay/modules/element.js
  97. 2 0
      examples/static/layui/lay/modules/flow.js
  98. 1 0
      examples/static/layui/lay/modules/form.js
  99. 1 0
      examples/static/layui/lay/modules/jquery.js
  100. 1 0
      examples/static/layui/lay/modules/laydate.js

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+/.idea
+/vendor
+composer.lock

+ 29 - 0
composer.json

@@ -0,0 +1,29 @@
+{
+    "name": "yzh/xlswrite",
+    "description": "xlswrite excle export and import ,WebSocket client and server",
+    "license": "NPN",
+    "type": "library",
+    "authors": [
+        {
+            "name": "zhihao Yan",
+            "email": "zhihaoyan@npn.sg"
+        }
+    ],
+    "autoload": {
+        "psr-4": {
+            "Pxlswrite\\": "src"
+        }
+    },
+    "autoload-dev": {
+        "psr-4": {
+
+        }
+    },
+    "require": {
+        "php": "^7.2",
+        "textalk/websocket": "^1.3"
+    },
+    "require-dev": {
+
+    }
+}

+ 8 - 0
examples/download.php

@@ -0,0 +1,8 @@
+<?php
+require_once(__DIR__.'/../vendor/autoload.php');
+
+$dir = __DIR__.'/uploads';
+$filePath = $_GET['file'];
+//$fileName = end(explode('/',$filePath));
+$fileObj = new \Pxlswrite\Pxlswrite(['path'=>$dir]);
+$fileObj->download($filePath);

+ 75 - 0
examples/export_demo.php

@@ -0,0 +1,75 @@
+<?php
+require_once(__DIR__.'/../vendor/autoload.php');
+
+use Pxlswrite\DB\DB;
+use Pxlswrite\Pxlswrite;
+use Pxlswrite\WebSocket\WebSocketClient;
+
+$time = time();
+
+
+//实例化pxlswrite
+$fileObj = new Pxlswrite(['path' => __DIR__ . '/uploads']);
+//实例化WebSocketClient--需要推送进度才实例化
+$pushHandle = new WebSocketClient('ws://192.168.18.192:9502',$_GET['fd']);
+//创建excel文件
+$fileObj->fileName('123.xlsx');
+
+//定义样式
+$leftStyle = $fileObj->styleFormat()
+    ->bold()
+    ->align(Pxlswrite::FORMAT_ALIGN_LEFT, Pxlswrite::FORMAT_ALIGN_VERTICAL_CENTER)
+    ->toResource();
+$borderStyle = $fileObj->styleFormat()
+    ->align(Pxlswrite::FORMAT_ALIGN_RIGHT, Pxlswrite::FORMAT_ALIGN_VERTICAL_CENTER)
+    ->border(Pxlswrite::BORDER_SLANT_DASH_DOT)
+    ->toResource();
+$colorStyle = $fileObj->styleFormat()
+    ->fontColor(Pxlswrite::COLOR_BLUE)
+    ->toResource();
+$backgroundStyle  = $fileObj->styleFormat()
+    ->background(Pxlswrite::COLOR_RED)
+    ->toResource();
+$numberStyle = $fileObj->styleFormat()
+    ->number('#,##0')
+    ->toResource();
+$defaultStyle = $fileObj->styleFormat()
+    ->fontColor(Pxlswrite::COLOR_ORANGE)
+    ->border(Pxlswrite::BORDER_DASH_DOT)
+    ->align(Pxlswrite::FORMAT_ALIGN_CENTER,Pxlswrite::FORMAT_ALIGN_VERTICAL_CENTER)
+    ->toResource();
+
+$filePath = $fileObj->header(array('id', 'c1', 'c2', 'c3', 'c4','c5'))//设置表格头
+    ->defaultFormat($defaultStyle)//全局默认样式
+    ->setDataByGenerator('generateData',$pushHandle)//设置数据,$pushHandle 用于推送,可不传
+    ->setRow('A1:A3', 80, $leftStyle)//设置范围行样式
+    ->setRow('A2',50,$borderStyle)//设置指定某一行样式
+    ->setRow('A3',50,$colorStyle)//设置文字颜色
+    ->setRow('A4',40,$backgroundStyle)//设置背景色
+    ->setColumn('B:B',50,$numberStyle)//设置列样式
+    ->mergeCells('A1:C1', 'Merge cells',$fileObj->styleFormat()->align(Pxlswrite::FORMAT_ALIGN_CENTER,Pxlswrite::FORMAT_ALIGN_VERTICAL_CENTER)->toResource())//合并单元格
+    ->output();//输出excel文件到磁盘
+
+//单元格插入文本
+//for ($index = 0; $index < 10; $index++) {
+//    $fileObj->insertText($index, 0, 'viest');
+//    $fileObj->insertText($index, 1, 10000, '#,##0');
+//}
+//$filePath = $fileObj->output();
+
+$memory = floor((memory_get_peak_usage()) / 1024 / 1024) . "MB";#10M 22S
+$execute_time = time() - $time . 's';
+
+//同步下载
+//$fileObj->download($filePath);
+//ajax请求返回下载地址
+echo json_encode(['code' => 1, 'msg' => '导出完毕', 'url' => '/download.php?file=' . $filePath, 'data' => ['memory' => $memory, 'excute_time' => $execute_time]]);
+
+//数据生成器--封装数据获取的方法
+function generateData(){
+    $db = DB::getInstance();
+    $step = 10000;
+    for ($i = 0; $i < 100000; $i = $i + $step) {
+        yield $db->get_records_sql("select * from sheet1 limit {$i},{$step}", null, PDO::FETCH_ASSOC);
+    }
+}

+ 38 - 0
examples/import_demo.php

@@ -0,0 +1,38 @@
+<?php
+/**
+ * 游标读取Excel
+ * 分段插入数据库
+ */
+require_once(__DIR__.'/../vendor/autoload.php');
+
+use Pxlswrite\DB\DB;
+use Pxlswrite\Pxlswrite;
+use Pxlswrite\WebSocket\WebSocketClient;
+
+$time = time();
+
+$fileObj = new Pxlswrite(['path' => dirname($_GET['file'])]);
+$fileInfo = explode('/', $_GET['file']);
+$fileName = end($fileInfo);
+//实例化WebSocketClient
+$pushHandle = new WebSocketClient('ws://192.168.18.192:9502',$_GET['fd']);
+//打开excel文件  setSkipRows(1)跳过一行数据
+$fileObj->openFile($fileName)->openSheet()->setSkipRows(1)->importData('insert_data',$pushHandle);
+
+//数据插入逻辑
+function insert_data($data)
+{
+    $db = DB::getInstance();
+    $sql = '';
+    foreach ($data as $v) {
+        $sql .= "(" . implode(",", $v) . "),";
+    }
+    $sql = trim($sql, ',');
+    $db->execute("insert into sheet2 (id,c1,c2,c3,c4) values " . $sql);
+}
+
+
+$memory = floor((memory_get_peak_usage()) / 1024 / 1024) . "MB";#10M 12S
+$execute_time = time() - $time . 's';
+echo json_encode(['code' => 1, 'data' => ['memory' => $memory, 'execute_time' => $execute_time], 'msg' => '导入完毕']);
+#5MB 57s

File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/css/layui.css


File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/css/layui.mobile.css


+ 2 - 0
examples/static/layui/css/modules/code.css

@@ -0,0 +1,2 @@
+/** layui-v2.5.6 MIT License By https://www.layui.com */
+ html #layuicss-skincodecss{display:none;position:absolute;width:1989px}.layui-code-h3,.layui-code-view{position:relative;font-size:12px}.layui-code-view{display:block;margin:10px 0;padding:0;border:1px solid #e2e2e2;border-left-width:6px;background-color:#F2F2F2;color:#333;font-family:Courier New}.layui-code-h3{padding:0 10px;height:32px;line-height:32px;border-bottom:1px solid #e2e2e2}.layui-code-h3 a{position:absolute;right:10px;top:0;color:#999}.layui-code-view .layui-code-ol{position:relative;overflow:auto}.layui-code-view .layui-code-ol li{position:relative;margin-left:45px;line-height:20px;padding:0 5px;border-left:1px solid #e2e2e2;list-style-type:decimal-leading-zero;*list-style-type:decimal;background-color:#fff}.layui-code-view pre{margin:0}.layui-code-notepad{border:1px solid #0C0C0C;border-left-color:#3F3F3F;background-color:#0C0C0C;color:#C2BE9E}.layui-code-notepad .layui-code-h3{border-bottom:none}.layui-code-notepad .layui-code-ol li{background-color:#3F3F3F;border-left:none}

File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/css/modules/laydate/default/laydate.css


BIN
examples/static/layui/css/modules/layer/default/icon-ext.png


BIN
examples/static/layui/css/modules/layer/default/icon.png


File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/css/modules/layer/default/layer.css


BIN
examples/static/layui/css/modules/layer/default/loading-0.gif


BIN
examples/static/layui/css/modules/layer/default/loading-1.gif


BIN
examples/static/layui/css/modules/layer/default/loading-2.gif


BIN
examples/static/layui/font/iconfont.eot


File diff suppressed because it is too large
+ 25 - 0
examples/static/layui/font/iconfont.svg


BIN
examples/static/layui/font/iconfont.ttf


BIN
examples/static/layui/font/iconfont.woff


BIN
examples/static/layui/font/iconfont.woff2


BIN
examples/static/layui/images/face/0.gif


BIN
examples/static/layui/images/face/1.gif


BIN
examples/static/layui/images/face/10.gif


BIN
examples/static/layui/images/face/11.gif


BIN
examples/static/layui/images/face/12.gif


BIN
examples/static/layui/images/face/13.gif


BIN
examples/static/layui/images/face/14.gif


BIN
examples/static/layui/images/face/15.gif


BIN
examples/static/layui/images/face/16.gif


BIN
examples/static/layui/images/face/17.gif


BIN
examples/static/layui/images/face/18.gif


BIN
examples/static/layui/images/face/19.gif


BIN
examples/static/layui/images/face/2.gif


BIN
examples/static/layui/images/face/20.gif


BIN
examples/static/layui/images/face/21.gif


BIN
examples/static/layui/images/face/22.gif


BIN
examples/static/layui/images/face/23.gif


BIN
examples/static/layui/images/face/24.gif


BIN
examples/static/layui/images/face/25.gif


BIN
examples/static/layui/images/face/26.gif


BIN
examples/static/layui/images/face/27.gif


BIN
examples/static/layui/images/face/28.gif


BIN
examples/static/layui/images/face/29.gif


BIN
examples/static/layui/images/face/3.gif


BIN
examples/static/layui/images/face/30.gif


BIN
examples/static/layui/images/face/31.gif


BIN
examples/static/layui/images/face/32.gif


BIN
examples/static/layui/images/face/33.gif


BIN
examples/static/layui/images/face/34.gif


BIN
examples/static/layui/images/face/35.gif


BIN
examples/static/layui/images/face/36.gif


BIN
examples/static/layui/images/face/37.gif


BIN
examples/static/layui/images/face/38.gif


BIN
examples/static/layui/images/face/39.gif


BIN
examples/static/layui/images/face/4.gif


BIN
examples/static/layui/images/face/40.gif


BIN
examples/static/layui/images/face/41.gif


BIN
examples/static/layui/images/face/42.gif


BIN
examples/static/layui/images/face/43.gif


BIN
examples/static/layui/images/face/44.gif


BIN
examples/static/layui/images/face/45.gif


BIN
examples/static/layui/images/face/46.gif


BIN
examples/static/layui/images/face/47.gif


BIN
examples/static/layui/images/face/48.gif


BIN
examples/static/layui/images/face/49.gif


BIN
examples/static/layui/images/face/5.gif


BIN
examples/static/layui/images/face/50.gif


BIN
examples/static/layui/images/face/51.gif


BIN
examples/static/layui/images/face/52.gif


BIN
examples/static/layui/images/face/53.gif


BIN
examples/static/layui/images/face/54.gif


BIN
examples/static/layui/images/face/55.gif


BIN
examples/static/layui/images/face/56.gif


BIN
examples/static/layui/images/face/57.gif


BIN
examples/static/layui/images/face/58.gif


BIN
examples/static/layui/images/face/59.gif


BIN
examples/static/layui/images/face/6.gif


BIN
examples/static/layui/images/face/60.gif


BIN
examples/static/layui/images/face/61.gif


BIN
examples/static/layui/images/face/62.gif


BIN
examples/static/layui/images/face/63.gif


BIN
examples/static/layui/images/face/64.gif


BIN
examples/static/layui/images/face/65.gif


BIN
examples/static/layui/images/face/66.gif


BIN
examples/static/layui/images/face/67.gif


BIN
examples/static/layui/images/face/68.gif


BIN
examples/static/layui/images/face/69.gif


BIN
examples/static/layui/images/face/7.gif


BIN
examples/static/layui/images/face/70.gif


BIN
examples/static/layui/images/face/71.gif


BIN
examples/static/layui/images/face/8.gif


BIN
examples/static/layui/images/face/9.gif


File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/lay/modules/carousel.js


+ 2 - 0
examples/static/layui/lay/modules/code.js

@@ -0,0 +1,2 @@
+/** layui-v2.5.6 MIT License By https://www.layui.com */
+ ;layui.define("jquery",function(e){"use strict";var a=layui.$,l="http://www.layui.com/doc/modules/code.html";e("code",function(e){var t=[];e=e||{},e.elem=a(e.elem||".layui-code"),e.about=!("about"in e)||e.about,e.elem.each(function(){t.push(this)}),layui.each(t.reverse(),function(t,i){var c=a(i),o=c.html();(c.attr("lay-encode")||e.encode)&&(o=o.replace(/&(?!#?[a-zA-Z0-9]+;)/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&#39;").replace(/"/g,"&quot;")),c.html('<ol class="layui-code-ol"><li>'+o.replace(/[\r\t\n]+/g,"</li><li>")+"</li></ol>"),c.find(">.layui-code-h3")[0]||c.prepend('<h3 class="layui-code-h3">'+(c.attr("lay-title")||e.title||"code")+(e.about?'<a href="'+l+'" target="_blank">layui.code</a>':"")+"</h3>");var d=c.find(">.layui-code-ol");c.addClass("layui-box layui-code-view"),(c.attr("lay-skin")||e.skin)&&c.addClass("layui-code-"+(c.attr("lay-skin")||e.skin)),(d.find("li").length/100|0)>0&&d.css("margin-left",(d.find("li").length/100|0)+"px"),(c.attr("lay-height")||e.height)&&d.css("max-height",c.attr("lay-height")||e.height)})})}).addcss("modules/code.css","skincodecss");

File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/lay/modules/colorpicker.js


File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/lay/modules/element.js


+ 2 - 0
examples/static/layui/lay/modules/flow.js

@@ -0,0 +1,2 @@
+/** layui-v2.5.6 MIT License By https://www.layui.com */
+ ;layui.define("jquery",function(e){"use strict";var l=layui.$,o=function(e){},t='<i class="layui-anim layui-anim-rotate layui-anim-loop layui-icon ">&#xe63e;</i>';o.prototype.load=function(e){var o,i,n,r,a=this,c=0;e=e||{};var f=l(e.elem);if(f[0]){var m=l(e.scrollElem||document),u=e.mb||50,s=!("isAuto"in e)||e.isAuto,v=e.end||"没有更多了",y=e.scrollElem&&e.scrollElem!==document,d="<cite>加载更多</cite>",h=l('<div class="layui-flow-more"><a href="javascript:;">'+d+"</a></div>");f.find(".layui-flow-more")[0]||f.append(h);var p=function(e,t){e=l(e),h.before(e),t=0==t||null,t?h.html(v):h.find("a").html(d),i=t,o=null,n&&n()},g=function(){o=!0,h.find("a").html(t),"function"==typeof e.done&&e.done(++c,p)};if(g(),h.find("a").on("click",function(){l(this);i||o||g()}),e.isLazyimg)var n=a.lazyimg({elem:e.elem+" img",scrollElem:e.scrollElem});return s?(m.on("scroll",function(){var e=l(this),t=e.scrollTop();r&&clearTimeout(r),!i&&f.width()&&(r=setTimeout(function(){var i=y?e.height():l(window).height(),n=y?e.prop("scrollHeight"):document.documentElement.scrollHeight;n-t-i<=u&&(o||g())},100))}),a):a}},o.prototype.lazyimg=function(e){var o,t=this,i=0;e=e||{};var n=l(e.scrollElem||document),r=e.elem||"img",a=e.scrollElem&&e.scrollElem!==document,c=function(e,l){var o=n.scrollTop(),r=o+l,c=a?function(){return e.offset().top-n.offset().top+o}():e.offset().top;if(c>=o&&c<=r&&!e.attr("src")){var m=e.attr("lay-src");layui.img(m,function(){var l=t.lazyimg.elem.eq(i);e.attr("src",m).removeAttr("lay-src"),l[0]&&f(l),i++})}},f=function(e,o){var f=a?(o||n).height():l(window).height(),m=n.scrollTop(),u=m+f;if(t.lazyimg.elem=l(r),e)c(e,f);else for(var s=0;s<t.lazyimg.elem.length;s++){var v=t.lazyimg.elem.eq(s),y=a?function(){return v.offset().top-n.offset().top+m}():v.offset().top;if(c(v,f),i=s,y>u)break}};if(f(),!o){var m;n.on("scroll",function(){var e=l(this);m&&clearTimeout(m),m=setTimeout(function(){f(null,e)},50)}),o=!0}return f},e("flow",new o)});

File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/lay/modules/form.js


File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/lay/modules/jquery.js


File diff suppressed because it is too large
+ 1 - 0
examples/static/layui/lay/modules/laydate.js


Some files were not shown because too many files changed in this diff