LoginSignup
3
4

More than 5 years have passed since last update.

<table>タグのデータを配列に変換する

Last updated at Posted at 2017-04-04

スクリプト書いた。

table-tag-parser

Clipboard.jsと組わせると、ボタンクリックでテーブルのデータをクリップボードにコピー、Excelやスプレッドシートに貼り付けできる。サンプルはここ

import Clipboard from 'clipboard';
import parser from 'table-tag-parser';

const clipboard = new Clipboard('#button', {
  text: () => {
    const data = parser('#table', { ignoreHeader: true });

    return data.reduce((memo, row) => memo + row.reduce((memo, cell) => `${memo}${cell},`, '') + '\n', '');
  }
});

Railsとかでさくっと作った管理系の画面に、「CSVエクスポート機能欲しいんですよー」とか言われた時に便利。

3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4