-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
142 lines (118 loc) · 5.38 KB
/
index.html
File metadata and controls
142 lines (118 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>js excel 읽기</title>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.14.3/xlsx.full.min.js"></script>
<script>
function excelExport(event) {
excelExportCommon(event, handleExcelDataAll);
}
function excelExportCommon(event, callback) {
var input = event.target;
var reader = new FileReader();
reader.onload = function () {
var fileData = reader.result;
var wb = XLSX.read(fileData, { type: 'binary' });
var sheetNameList = wb.SheetNames; // 시트 이름 목록 가져오기
var firstSheetName = sheetNameList[0]; // 첫번째 시트명
var firstSheet = wb.Sheets[firstSheetName]; // 첫번째 시트
callback(firstSheet);
};
reader.readAsBinaryString(input.files[0]);
}
function handleExcelDataAll(sheet) {
//handleExcelDataHeader(sheet); // header 정보
//handleExcelDataJson(sheet); // json 형태
//handleExcelDataCsv(sheet); // csv 형태
//handleExcelDataHtml(sheet); // html 형태
//console.log(XLSX.utils.sheet_to_json(sheet));
//console.log(XLSX.utils.sheet_to_csv(sheet));
let xlsxToJson = XLSX.utils.sheet_to_json(sheet);
//중복 제거
xlsxToJson = xlsxToJson.filter((item, i) => {
return (
xlsxToJson.findIndex((item2, j) => {
return item["__EMPTY_2"] === item2["__EMPTY_2"];
}) === i
);
});
console.log(xlsxToJson);
console.log(Object.keys(xlsxToJson).length);
let Json_addCoordinate = {};
for (let i = 1; i <= Object.keys(xlsxToJson).length; i++) {
let query = xlsxToJson[i]["__EMPTY"] + " " + xlsxToJson[i]["__EMPTY_1"] + " " + xlsxToJson[i]["__EMPTY_2"];
if (!xlsxToJson[i]["__EMPTY_1"]) {
query = xlsxToJson[i]["__EMPTY"] + " " + xlsxToJson[i]["__EMPTY_2"];
}
console.log(`${i}: ` + query);
let url = `https://dapi.kakao.com/v2/local/search/address.json?query=` + encodeURIComponent(query);
fetch(url, {
headers: {
'Authorization': 'KakaoAK 009723cdaa567cb7959564ab48403f45'
}
})
.then((res) => {
return res.json();
})
.then((json) => {
//console.log(JSON.stringify(json));
if (json["meta"]["total_count"] === 1) {
let div = document.createElement("div");
div.innerHTML = `<p>${query}</p> <p>${JSON.stringify(json["documents"])}</p>`;
document.getElementById("displayExcelJson").appendChild(div);
Json_addCoordinate[i] = json["documents"];
console.log("\n\n\n\n\n" + "dddd")
}
});
//break;
}
console.log("\n\n\n\n\n" + "dddd")
console.log(JSON.stringify(Json_addCoordinate));
console.log(Json_addCoordinate);
console.log(Object.keys(Json_addCoordinate).length);
//handleExcelDataJson(Json_addCoordinate)
}
function handleExcelDataHeader(sheet) {
var headers = get_header_row(sheet);
$("#displayHeaders").html(JSON.stringify(headers));
}
function handleExcelDataJson(sheet) {
//$("#displayExcelJson").html(JSON.stringify(XLSX.utils.sheet_to_json(sheet)));
//$("#displayExcelJson").html(JSON.stringify(sheet, '\t'));
}
function handleExcelDataCsv(sheet) {
$("#displayExcelCsv").html(XLSX.utils.sheet_to_csv(sheet));
}
function handleExcelDataHtml(sheet) {
$("#displayExcelHtml").html(XLSX.utils.sheet_to_html(sheet));
}
// https://github.com/SheetJS/js-xlsx/issues/214
function get_header_row(sheet) {
var headers = [];
var range = XLSX.utils.decode_range(sheet['!ref']);
var C, R = range.s.r; /* start in the first row */
/* walk every column in the range */
for (C = range.s.c; C <= range.e.c; ++C) {
var cell = sheet[XLSX.utils.encode_cell({ c: C, r: R })] /* find the cell in the first row */
var hdr = "UNKNOWN " + C; // <-- replace with your desired default
if (cell && cell.t) hdr = XLSX.utils.format_cell(cell);
headers.push(hdr);
}
return headers;
}
</script>
</head>
<body>
파일 선택 : <input type="file" id="excelFile" onchange="excelExport(event)" />
<h1>Header 정보 보기</h1>
<div id="displayHeaders"></div>
<h1>JSON 형태로 보기</h1>
<div id="displayExcelJson"></div>
<h1>CSV 형태로 보기</h1>
<div id="displayExcelCsv"></div>
<h1>HTML 형태로 보기</h1>
<div id="displayExcelHtml"></div>
</body>
</html>