toror33

연락처 download

...@@ -417,6 +417,11 @@ ...@@ -417,6 +417,11 @@
417 "ms": "2.0.0" 417 "ms": "2.0.0"
418 } 418 }
419 }, 419 },
420 + "deepmerge": {
421 + "version": "3.2.0",
422 + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-3.2.0.tgz",
423 + "integrity": "sha512-6+LuZGU7QCNUnAJyX8cIrlzoEgggTM6B7mm+znKOX4t5ltluT9KLjN6g61ECMS0LTsLW7yDpNoxhix5FZcrIow=="
424 + },
420 "delayed-stream": { 425 "delayed-stream": {
421 "version": "1.0.0", 426 "version": "1.0.0",
422 "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", 427 "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
...@@ -516,6 +521,36 @@ ...@@ -516,6 +521,36 @@
516 "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz", 521 "resolved": "https://registry.npmjs.org/events/-/events-1.1.1.tgz",
517 "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ=" 522 "integrity": "sha1-nr23Y1rQmccNzEwqH1AEKI6L2SQ="
518 }, 523 },
524 + "excel4node": {
525 + "version": "1.7.2",
526 + "resolved": "https://registry.npmjs.org/excel4node/-/excel4node-1.7.2.tgz",
527 + "integrity": "sha512-3XSsPSSbUeGloTRQMTmgf4aA1WDGa9fWQitOCGN/URG8NvwPjgVdbyG7FWKukqTdl5XBz9jv0vVBz3BBIo52tg==",
528 + "requires": {
529 + "deepmerge": "3.2.0",
530 + "image-size": "0.7.2",
531 + "jszip": "3.2.1",
532 + "lodash.get": "4.4.2",
533 + "lodash.isequal": "4.5.0",
534 + "lodash.isundefined": "3.0.1",
535 + "lodash.reduce": "4.6.0",
536 + "lodash.uniqueid": "4.0.1",
537 + "mime": "2.4.0",
538 + "uuid": "3.3.2",
539 + "xmlbuilder": "11.0.1"
540 + },
541 + "dependencies": {
542 + "mime": {
543 + "version": "2.4.0",
544 + "resolved": "https://registry.npmjs.org/mime/-/mime-2.4.0.tgz",
545 + "integrity": "sha512-ikBcWwyqXQSHKtciCcctu9YfPbFYZ4+gbHEmE0Q8jzcTYQg5dHCr3g2wwAZjPoJfQVXZq6KXAjpXOTf5/cjT7w=="
546 + },
547 + "xmlbuilder": {
548 + "version": "11.0.1",
549 + "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-11.0.1.tgz",
550 + "integrity": "sha512-fDlsI/kFEx7gLvbecc0/ohLG50fugQp8ryHzMTuW9vSa1GJ0XYWKnhsUx7oie3G98+r56aTQIUB4kht42R3JvA=="
551 + }
552 + }
553 + },
519 "exit-on-epipe": { 554 "exit-on-epipe": {
520 "version": "1.0.1", 555 "version": "1.0.1",
521 "resolved": "https://registry.npmjs.org/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz", 556 "resolved": "https://registry.npmjs.org/exit-on-epipe/-/exit-on-epipe-1.0.1.tgz",
...@@ -743,6 +778,16 @@ ...@@ -743,6 +778,16 @@
743 "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz", 778 "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.1.13.tgz",
744 "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg==" 779 "integrity": "sha512-4vf7I2LYV/HaWerSo3XmlMkp5eZ83i+/CDluXi/IGTs/O1sejBNhTtnxzmRZfvOUqj7lZjqHkeTvpgSFDlWZTg=="
745 }, 780 },
781 + "image-size": {
782 + "version": "0.7.2",
783 + "resolved": "https://registry.npmjs.org/image-size/-/image-size-0.7.2.tgz",
784 + "integrity": "sha512-CBmVIFHyDyiWi1U24eNHl8SH0Iir2IgmEv1RwdRVZxWsEbSCvV5b/eXaYP8epOFv2dbw5uNBOrn1Nc5P5KvsUA=="
785 + },
786 + "immediate": {
787 + "version": "3.0.6",
788 + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.0.6.tgz",
789 + "integrity": "sha1-nbHb0Pr43m++D13V5Wu2BigN5ps="
790 + },
746 "inherits": { 791 "inherits": {
747 "version": "2.0.3", 792 "version": "2.0.3",
748 "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz", 793 "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
...@@ -851,11 +896,55 @@ ...@@ -851,11 +896,55 @@
851 "promise": "^7.0.1" 896 "promise": "^7.0.1"
852 } 897 }
853 }, 898 },
899 + "jszip": {
900 + "version": "3.2.1",
901 + "resolved": "https://registry.npmjs.org/jszip/-/jszip-3.2.1.tgz",
902 + "integrity": "sha512-iCMBbo4eE5rb1VCpm5qXOAaUiRKRUKiItn8ah2YQQx9qymmSAY98eyQfioChEYcVQLh0zxJ3wS4A0mh90AVPvw==",
903 + "requires": {
904 + "lie": "~3.3.0",
905 + "pako": "~1.0.2",
906 + "readable-stream": "~2.3.6",
907 + "set-immediate-shim": "~1.0.1"
908 + }
909 + },
910 + "lie": {
911 + "version": "3.3.0",
912 + "resolved": "https://registry.npmjs.org/lie/-/lie-3.3.0.tgz",
913 + "integrity": "sha512-UaiMJzeWRlEujzAuw5LokY1L5ecNQYZKfmyZ9L7wDHb/p5etKaxXhohBcrw0EYby+G/NA52vRSN4N39dxHAIwQ==",
914 + "requires": {
915 + "immediate": "~3.0.5"
916 + }
917 + },
854 "lodash": { 918 "lodash": {
855 "version": "4.17.15", 919 "version": "4.17.15",
856 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", 920 "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz",
857 "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" 921 "integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A=="
858 }, 922 },
923 + "lodash.get": {
924 + "version": "4.4.2",
925 + "resolved": "https://registry.npmjs.org/lodash.get/-/lodash.get-4.4.2.tgz",
926 + "integrity": "sha1-LRd/ZS+jHpObRDjVNBSZ36OCXpk="
927 + },
928 + "lodash.isequal": {
929 + "version": "4.5.0",
930 + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz",
931 + "integrity": "sha1-QVxEePK8wwEgwizhDtMib30+GOA="
932 + },
933 + "lodash.isundefined": {
934 + "version": "3.0.1",
935 + "resolved": "https://registry.npmjs.org/lodash.isundefined/-/lodash.isundefined-3.0.1.tgz",
936 + "integrity": "sha1-I+89lTVWUgOmbO/VuDD4SJEa+0g="
937 + },
938 + "lodash.reduce": {
939 + "version": "4.6.0",
940 + "resolved": "https://registry.npmjs.org/lodash.reduce/-/lodash.reduce-4.6.0.tgz",
941 + "integrity": "sha1-8atrg5KZrUj3hKu/R2WW8DuRTTs="
942 + },
943 + "lodash.uniqueid": {
944 + "version": "4.0.1",
945 + "resolved": "https://registry.npmjs.org/lodash.uniqueid/-/lodash.uniqueid-4.0.1.tgz",
946 + "integrity": "sha1-MmjyanyI5PSxdY1nknGBTjH6WyY="
947 + },
859 "media-typer": { 948 "media-typer": {
860 "version": "0.3.0", 949 "version": "0.3.0",
861 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz", 950 "resolved": "https://registry.npmjs.org/media-typer/-/media-typer-0.3.0.tgz",
...@@ -986,6 +1075,11 @@ ...@@ -986,6 +1075,11 @@
986 "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz", 1075 "resolved": "https://registry.npmjs.org/on-headers/-/on-headers-1.0.2.tgz",
987 "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA==" 1076 "integrity": "sha512-pZAE+FJLoyITytdqK0U5s+FIpjN0JP3OzFi/u8Rx+EV5/W+JTWGXG8xFzevE7AjBfDqHv/8vL8qQsIhHnqRkrA=="
988 }, 1077 },
1078 + "pako": {
1079 + "version": "1.0.11",
1080 + "resolved": "https://registry.npmjs.org/pako/-/pako-1.0.11.tgz",
1081 + "integrity": "sha512-4hLB8Py4zZce5s4yd9XzopqwVv/yGNhV1Bl8NTmCq1763HeK2+EwVTv+leGeL13Dnh2wfbqowVPXCIO0z4taYw=="
1082 + },
989 "parseurl": { 1083 "parseurl": {
990 "version": "1.3.3", 1084 "version": "1.3.3",
991 "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz", 1085 "resolved": "https://registry.npmjs.org/parseurl/-/parseurl-1.3.3.tgz",
...@@ -1300,6 +1394,11 @@ ...@@ -1300,6 +1394,11 @@
1300 "send": "0.16.2" 1394 "send": "0.16.2"
1301 } 1395 }
1302 }, 1396 },
1397 + "set-immediate-shim": {
1398 + "version": "1.0.1",
1399 + "resolved": "https://registry.npmjs.org/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz",
1400 + "integrity": "sha1-SysbJ+uAip+NzEgaWOXlb1mfP2E="
1401 + },
1303 "setprototypeof": { 1402 "setprototypeof": {
1304 "version": "1.1.0", 1403 "version": "1.1.0",
1305 "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz", 1404 "resolved": "https://registry.npmjs.org/setprototypeof/-/setprototypeof-1.1.0.tgz",
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
11 "crypto-js": "^4.0.0", 11 "crypto-js": "^4.0.0",
12 "debug": "~2.6.9", 12 "debug": "~2.6.9",
13 "ejs": "^3.1.3", 13 "ejs": "^3.1.3",
14 + "excel4node": "^1.7.2",
14 "express": "~4.16.1", 15 "express": "~4.16.1",
15 "express-session": "^1.17.1", 16 "express-session": "^1.17.1",
16 "formidable": "^1.2.2", 17 "formidable": "^1.2.2",
......
...@@ -3,6 +3,7 @@ var router = express.Router(); ...@@ -3,6 +3,7 @@ var router = express.Router();
3 const XLSX = require('xlsx'); 3 const XLSX = require('xlsx');
4 var multer = require('multer'); 4 var multer = require('multer');
5 var fs = require('fs'); 5 var fs = require('fs');
6 +var xl = require('excel4node');
6 // var pool = require('./../routes/modules/database'); 7 // var pool = require('./../routes/modules/database');
7 8
8 //파일 저장위치와 파일이름 설정 9 //파일 저장위치와 파일이름 설정
...@@ -88,7 +89,59 @@ contact_download : 연락처 파일 다운로드 모듈 ...@@ -88,7 +89,59 @@ contact_download : 연락처 파일 다운로드 모듈
88 input : 사용자의 연락처 다운로드 요청 89 input : 사용자의 연락처 다운로드 요청
89 output : 연락처 다운로드 성공 여부 및 csv, xlsx 파일 90 output : 연락처 다운로드 성공 여부 및 csv, xlsx 파일
90 */ 91 */
91 -router.get('/contact_download', function(req, res, next) { 92 +router.post('/contact_download', function(req, res, next) {
93 +
94 + var filename = 'public/upload/contactdownload.xlsx';
95 + fs.exists(filename, function (exists) {
96 + console.log(exists);
97 + if(exists == true)
98 + {
99 + fs.unlink(filename, function (err) {
100 + if (err) throw err;
101 + console.log('file deleted');
102 + });
103 + }
104 + });
105 +
106 + // Create a new instance of a Workbook class
107 + var wb = new xl.Workbook();
108 +
109 + // Add Worksheets to the workbook
110 + var ws = wb.addWorksheet('Sheet 1');
111 +
112 + ws.cell(1, 1)
113 + .string('name');
114 + ws.cell(1, 2)
115 + .string('phone');
116 + ws.cell(1, 3)
117 + .string('email');
118 + ws.cell(1, 4)
119 + .string('added_date');
120 +
121 + var user_id = req.query.id;
122 + var sqlquery = "SELECT * FROM contact WHERE user_id = ?";
123 + connection.query(sqlquery, [user_id], function (err, rows) {
124 + if (err) {
125 + console.log("download contact failed");
126 + throw err;
127 + } else {
128 + if(rows.length != 0)
129 + {
130 + for(var i=0;i<rows.length;i++)
131 + {
132 + ws.cell(i+2, 1).string(rows[i].name);
133 + ws.cell(i+2, 2).string(rows[i].phone);
134 + ws.cell(i+2, 3).string(rows[i].email);
135 + ws.cell(i+2, 4).string(rows[i].added_date);
136 + }
137 + }
138 + wb.write('public/upload/contactdownload.xlsx');
139 + var file = __dirname + '/public/upload/contactdownload.xlsx';
140 + // console.log(file);
141 + res.download(file);
142 + }
143 +
144 + });
92 }); 145 });
93 146
94 /* 147 /*
......