HTML table 앨리먼트 내용을 CSV 파일로 다운로드 함수

// table 엘리먼트 내용을 file_name 이름의 파일로 다운로드
export const get_csv_from_table = (table_el, file_name) => go(
table_el.querySelectorAll('tr'),
map(row => map(sell => `"${sell.innerText.replace(/^\s*|\s*$/gi, '')}"`, row.querySelectorAll('td, th'))),
arr => '\uFEFF' + arr.join('\n'),
csv_arr => $.el(`
<a download = "${file_name}" href="${window.URL.createObjectURL(new Blob([csv_arr], { type: 'text/csv' }))}"></a>`).click());

예시)

get_csv_from_table(document.querySelector(‘table’),’XXXX년정산.csv’);

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
모든 댓글 보기
0
생각을 나눠주시면 감사해요!x
()
x
Please enter Google Username or ID to start!
Example: clip360net or 116819034451508671546
Title
Caption
File name
Size
Alignment
Link to
  Open new windows
  Rel nofollow