Markdown 表格產生器:Excel、Google 試算表貼上就轉好

從 Excel 或 Google 試算表複製儲存格貼上(也可以貼 CSV),工具會自動判斷 Tab、逗號或分號,即時產生 Markdown 表格。可設定標題列與每欄對齊,按「複製 Markdown」貼到 README、筆記或 AI 對話。

所屬專區:AI 與效率。版本 1.0.0,最後測試於。

適合誰:員工識別證小編記者證

Markdown 表格

在左側貼上資料,這裡會即時產生 Markdown 表格。

內容只在你的瀏覽器處理,不會送出。

適合什麼時候用

  • 把試算表裡的資料放進 README、技術文件或 Markdown 筆記
  • 在 AI 對話中用表格提供資料,或給 AI 一個要照著輸出的表格範例
  • 會議紀錄、比較表需要在純文字編輯器裡也看得懂(對齊欄寬)

怎麼使用

  1. 在 Excel 或 Google 試算表選取要的儲存格(包含標題列)並複製,貼到左側欄位;也可以直接貼 CSV 文字。按「填入範例」可以先看效果。
  2. 分隔符號預設「自動偵測」,下拉選單會顯示目前判斷的結果;不對時改選 Tab、逗號或分號。
  3. 確認「第一列是標題」,在「每欄對齊方式」設定靠左、置中或靠右;需要原始碼整齊時勾選「對齊欄寬」。
  4. 右側即時顯示 Markdown 與預覽,按「複製 Markdown」貼到要用的地方。

範例:三欄、含換行與直線符號

從試算表複製這三列(「備註」第一筆儲存格裡有換行,第二筆含有 |),把「數量」設為靠右:

品項 數量 備註
咖啡豆 2 中焙(換行)下週到貨
手沖壺 1 型號 A|B

沒有勾選「對齊欄寬」時,輸出是:

| 品項 | 數量 | 備註 |
| :-- | --: | :-- |
| 咖啡豆 | 2 | 中焙<br>下週到貨 |
| 手沖壺 | 1 | 型號 A\|B |

勾選「對齊欄寬」後,中文字以 2 格計算補上空白,原始文字裡的 | 會上下對齊:

| 品項   | 數量 | 備註             |
| :----- | ---: | :--------------- |
| 咖啡豆 |    2 | 中焙<br>下週到貨 |
| 手沖壺 |    1 | 型號 A\|B        |

對齊符號怎麼看

第二列(分隔列)用冒號的位置決定對齊方式,這是 GitHub Flavored Markdown 規格中的寫法:

分隔列寫法 對齊
:--- 靠左
:---: 置中
---: 靠右
--- 不指定,由平台的樣式決定

本工具選「靠左」時會明確輸出 :--- 這類寫法;冒號旁的連字號數量不影響結果,勾選「對齊欄寬」時只是變長。

規格也說明,資料列的格數比標題少時會補上空白格;本工具會先把每一列補齊到同樣欄數,輸出的表格各列格數一致。

要請 AI 依固定欄位輸出表格時,可以把產生的表格當成「輸出格式」範例放進 Prompt,寫法見寫好 AI Prompt 的六個欄位。資料要給程式使用時,改用 CSV ⇄ JSON 轉換器。

限制與注意事項

  • 只處理複製出來的純文字:儲存格顏色、粗體、超連結與合併儲存格都不會保留。
  • Markdown 表格的儲存格只能放行內內容,不能放清單或段落;儲存格內換行會轉成 <br>,若貼到的平台不接受表格內的 HTML,<br> 會以文字顯示。
  • 貼到的編輯器或平台若不支援 Markdown 表格語法,會顯示成原始文字;請先在目標平台預覽。
  • 「對齊欄寬」以等寬字型中全形字佔 2 格估算,部分字型、罕用字或符號可能仍有些微偏差;不影響表格轉成網頁後的樣子。
  • 自動偵測只看第一個非空白行;偵測錯誤時請手動選擇分隔符號。空白行會被略過。

隱私與無障礙

貼上的資料只在你的瀏覽器轉換,不會上傳到任何伺服器;關閉分頁後不保留。

每個選項都有標籤;每欄對齊方式用下拉選單設定,不需要拖曳;產生的列數與欄數會通知螢幕閱讀器,預覽表格有欄位標題;可只用鍵盤完成貼上、設定與複製。

搭配 AI 使用的 Prompt 範本

把【】裡的內容換成你的情況再貼到 AI 工具。送出前請確認沒有個資或機密資料,並自行核對 AI 的回答。

(貼上前請刪除姓名、電話、Email 等個人資料;需要區分人時用代號,例如 成員A。)
請把下面的內容整理成一個 Markdown 表格。

用途:【例:放進 README 的方案比較、會議紀錄的待辦事項】
原始內容:【貼上筆記、條列或從試算表複製的資料】
欄位:【例:項目、負責人、期限、狀態;不確定就請你建議】
排序方式:【例:依期限由近到遠】

請輸出:
1. Markdown 表格:第一列是標題列,數字欄靠右對齊(用 ---:),儲存格內不放清單或段落。
2. 表格下方列出原始內容中放不進表格或意思不明的部分。
3. 列數核對:原始內容共幾項、表格共幾列,不一致時說明原因。

規則:只整理我提供的內容,不要補上新的事實、數字、日期或價格;你自行歸類或改寫的地方標成【假設】,原文有矛盾或需要我確認的標成【需查證】。表格中如有合計或百分比,在表格下方寫出算式。
(資料已經在試算表裡時,直接複製儲存格貼到本站 /tools/markdown-table/ 轉換,比請 AI 重打更不容易出錯。)

計算邏輯原始碼

工具的計算部分是以下 TypeScript 函式,沒有呼叫任何外部服務。你可以複製到自己的專案使用,授權為 MIT License(Copyright © 2026 Explore Hub;保留此著作權聲明即可自由使用、修改、商用)。

csv-json.ts
export type Delimiter = ',' | '\t' | ';';
export type Cell = string | number;

/** Above this many characters (about 5 MB of ASCII) the UI warns that converting may be slow. */
export const LARGE_INPUT = 5_000_000;

const stripBom = (s: string) => (s.charCodeAt(0) === 0xfeff ? s.slice(1) : s);

/**
 * Guess the delimiter from the first non-blank line, ignoring quoted text.
 * A tab wins outright (Excel / Google 試算表 copy cells as tab-separated); otherwise the more frequent of ; and , (tie → ,).
 */
export function detectDelimiter(text: string): Delimiter {
  const first = stripBom(text).split(/\r\n|\r|\n/).find((l) => l.trim() !== '') ?? '';
  const line = first.replace(/"(?:[^"]|"")*"/g, '');
  const count = (d: string) => line.split(d).length - 1;
  if (count('\t') > 0) return '\t';
  return count(';') > count(',') ? ';' : ',';
}

/**
 * RFC 4180 parser: fields wrapped in "…" may contain the delimiter, line breaks and "" (an escaped quote).
 * Accepts CRLF, LF or CR line endings and strips a leading UTF-8 BOM. Blank lines are skipped.
 * A quote only opens a quoted field at the start of a field; elsewhere it is ordinary text (5" 螢幕).
 * Throws with the line and character position of a quote that is never closed.
 */
export function parseCsv(text: string, delimiter: Delimiter = ','): string[][] {
  const s = stripBom(text);
  const rows: string[][] = [];
  let row: string[] = [];
  let field = '';
  let atFieldStart = true;
  let line = 1;
  let lineStart = 0;

  const endRow = () => {
    row.push(field);
    if (!(row.length === 1 && row[0] === '')) rows.push(row);
    row = [];
    field = '';
    atFieldStart = true;
  };

  for (let i = 0; i < s.length; i++) {
    const c = s[i];
    if (atFieldStart && c === '"') {
      const openLine = line;
      const openCol = i - lineStart + 1;
      for (i++; ; i++) {
        if (i >= s.length) {
          throw new Error(`第 ${openLine} 行第 ${openCol} 個字元的引號 " 沒有結束:請補上結尾的 ",或把欄位內的 " 寫成 ""。`);
        }
        if (s[i] === '"') {
          if (s[i + 1] !== '"') break; // closing quote; the loop's i++ moves past it
          field += '"';
          i++;
        } else {
          if (s[i] === '\n') {
            line++;
            lineStart = i + 1;
          }
          field += s[i];
        }
      }
      atFieldStart = false;
    } else if (c === delimiter) {
      row.push(field);
      field = '';
      atFieldStart = true;
    } else if (c === '\n' || c === '\r') {
      if (c === '\r' && s[i + 1] === '\n') i++;
      endRow();
      line++;
      lineStart = i + 1;
    } else {
      field += c;
      atFieldStart = false;
    }
  }
  if (field !== '' || row.length > 0 || !atFieldStart) endRow();
  return rows;
}

/** Empty headers become 欄位_<column number>; repeats get _2, _3 … so every key is unique and the result is deterministic. */
export function uniqueHeaders(raw: readonly string[]): string[] {
  const used = new Set<string>();
  return raw.map((h, i) => {
    const base = h.trim() || `欄位_${i + 1}`;
    let name = base;
    for (let n = 2; used.has(name); n++) name = `${base}_${n}`;
    used.add(name);
    return name;
  });
}

/**
 * Optional type conversion: "" → null, true/false (any case) → boolean, plain decimal numbers → number.
 * A number is converted only if writing it back gives the exact same text, so 0912 (leading zero),
 * 12345678901234567890 (beyond double precision), 1.50, +5 and 1e3 all stay strings.
 */
export function convertValue(s: string): string | number | boolean | null {
  if (s === '') return null;
  if (/^true$/i.test(s)) return true;
  if (/^false$/i.test(s)) return false;
  if (/^-?\d+(\.\d+)?$/.test(s) && String(Number(s)) === s) return Number(s);
  return s;
}

export interface CsvToJsonOptions {
  delimiter: Delimiter;
  /** false: every value stays a string. */
  convertTypes: boolean;
  pretty: boolean;
}

/** First row = keys. Rows shorter than the header get "" (or null); extra cells get their own 欄位_N key. */
export function csvToJson(text: string, { delimiter, convertTypes, pretty }: CsvToJsonOptions) {
  const rows = parseCsv(text, delimiter);
  if (rows.length === 0) throw new Error('沒有資料:請貼上 CSV,第一列放欄位名稱。');
  const width = rows.reduce((w, r) => Math.max(w, r.length), 0);
  const keys = uniqueHeaders(Array.from({ length: width }, (_, i) => rows[0][i] ?? ''));
  // Object.fromEntries defines own properties, so a header named "__proto__" is kept as data.
  const data = rows.slice(1).map((r) => Object.fromEntries(keys.map((k, i) => [k, convertTypes ? convertValue(r[i] ?? '') : (r[i] ?? '')])));
  return { json: JSON.stringify(data, null, pretty ? 2 : undefined), records: data.length, keys };
}

/** JSON.parse with a Chinese message and an approximate line/column taken from the engine's error text when it has one. */
export function parseJson(text: string): unknown {
  const s = stripBom(text);
  if (s.trim() === '') throw new Error('沒有資料:請貼上 JSON 陣列,例如 [{"名稱":"A"}]。');
  try {
    return JSON.parse(s);
  } catch (e) {
    const msg = (e as Error).message;
    const at = (index: number) => {
      const before = s.slice(0, index).split('\n');
      return `(約第 ${before.length} 行第 ${before[before.length - 1].length + 1} 個字元)`;
    };
    // Engines differ: "line 3 column 5" (Firefox, newer V8), "position 12" (V8), or nothing (Safari).
    const lc = /line (\d+) column (\d+)/.exec(msg);
    const pos = /position (\d+)/.exec(msg);
    // V8 gives no position for a trailing comma in an array ("[1,]"), so look for one ourselves.
    const comma = /Unexpected token '[\]}]'/.test(msg) ? /,\s*[\]}]/.exec(s) : null;
    const where = lc ? `(約第 ${lc[1]} 行第 ${lc[2]} 個字元)` : pos ? at(Number(pos[1])) : comma ? at(comma.index) : '';
    throw new Error(`JSON 格式錯誤${where}:${msg}。常見原因:最後一項後多了逗號、用了單引號、鍵名沒加雙引號。`);
  }
}

const isRecord = (v: unknown): v is Record<string, unknown> => typeof v === 'object' && v !== null && !Array.isArray(v);

/** Numbers stay numbers; null → empty; nested objects/arrays are written as JSON text inside the cell. */
const toCell = (v: unknown): Cell =>
  v === null || v === undefined ? '' : typeof v === 'number' ? v : typeof v === 'string' ? v : typeof v === 'boolean' ? String(v) : JSON.stringify(v);

/**
 * Array of objects → header row (union of keys, in order of first appearance) + one row per object.
 * Array of arrays → rows as they are, no header. A single object is treated as a one-item array.
 * Pass the result to toCsv / downloadCsv (csv.ts), which quote cells and neutralise spreadsheet formulas.
 */
export function jsonToRows(data: unknown): Cell[][] {
  const list = Array.isArray(data) ? data : isRecord(data) ? [data] : null;
  if (!list) throw new Error('JSON 最外層需要是陣列 [ … ](或單一物件 { … })。');
  if (list.length === 0) throw new Error('陣列是空的,沒有資料可以轉換。');

  if (Array.isArray(list[0])) {
    return list.map((r, i) => {
      if (!Array.isArray(r)) throw new Error(`第 ${i + 1} 筆不是陣列:陣列裡要全部是陣列,或全部是物件。`);
      return r.map(toCell);
    });
  }
  const keys = new Set<string>();
  list.forEach((r, i) => {
    if (!isRecord(r)) throw new Error(`第 ${i + 1} 筆不是物件:陣列裡要全部是物件 { … },或全部是陣列 [ … ]。`);
    for (const k of Object.keys(r)) keys.add(k);
  });
  const header = [...keys];
  return [header, ...list.map((r) => header.map((k) => toCell(r[k])))];
}
markdown-table.ts
import { parseCsv, type Delimiter } from './csv-json.ts';

export type Align = 'left' | 'center' | 'right';

export interface Table {
  header: string[];
  body: string[][];
}

/**
 * Pasted text → rectangular table. Rows shorter than the widest row are padded with "".
 * Without a header row the columns are named 欄 1, 欄 2 …
 */
export function toTable(text: string, delimiter: Delimiter, firstRowIsHeader: boolean): Table {
  const rows = parseCsv(text, delimiter);
  const width = rows.reduce((w, r) => Math.max(w, r.length), 0);
  const grid = rows.map((r) => Array.from({ length: width }, (_, i) => r[i] ?? ''));
  if (firstRowIsHeader) return { header: grid[0] ?? [], body: grid.slice(1) };
  return { header: Array.from({ length: width }, (_, i) => `欄 ${i + 1}`), body: grid };
}

/** A Markdown cell cannot hold a line break or a bare |: escape | as \| and turn line breaks into <br>. */
export const escapeCell = (s: string) => s.trim().replace(/\|/g, '\\|').replace(/\r\n|\r|\n/g, '<br>');

// shortcut: covers CJK, kana, Hangul, full-width forms and common emoji, not the full Unicode East Asian Width table; extend if odd scripts misalign.
const WIDE = /[ᄀ-ᅟ⺀-꓏가-힣豈-﫿︰-﹏＀-⦆¢-₩\u{1F300}-\u{1FAFF}\u{20000}-\u{3FFFD}]/u;

/** Columns a string takes in a monospace font: full-width (East Asian Wide) characters count 2, others 1. */
export function displayWidth(s: string): number {
  let w = 0;
  for (const ch of s) w += WIDE.test(ch) ? 2 : 1;
  return w;
}

/**
 * Build a GFM table. Alignment row: :--- left, :---: center, ---: right.
 * pretty = pad every cell with spaces so the | line up in a monospace editor (full-width characters count as 2).
 */
export function toMarkdown(table: Table, aligns: readonly Align[], pretty: boolean): string {
  if (table.header.length === 0) return '';
  const head = table.header.map(escapeCell);
  const body = table.body.map((r) => r.map(escapeCell));
  const widths = head.map((h, i) => (pretty ? body.reduce((w, r) => Math.max(w, displayWidth(r[i])), Math.max(3, displayWidth(h))) : 3));
  const align = (i: number) => aligns[i] ?? 'left';

  const pad = (s: string, i: number) => {
    const gap = pretty ? widths[i] - displayWidth(s) : 0;
    const before = align(i) === 'right' ? gap : align(i) === 'center' ? Math.floor(gap / 2) : 0;
    return ' '.repeat(before) + s + ' '.repeat(gap - before);
  };
  const rule = widths.map((w, i) => (align(i) === 'center' ? `:${'-'.repeat(w - 2)}:` : align(i) === 'right' ? `${'-'.repeat(w - 1)}:` : `:${'-'.repeat(w - 1)}`));
  const line = (cells: string[]) => `| ${cells.join(' | ')} |`;

  return [line(head.map(pad)), line(rule), ...body.map((r) => line(r.map(pad)))].join('\n');
}

常見問題

自動偵測分隔符號是怎麼判斷的?

工具只看第一個非空白行(引號內的文字不算):只要出現 Tab 就當作 Tab 分隔;沒有 Tab 時,比較分號和逗號哪個多,一樣多時用逗號。判斷錯誤時在下拉選單手動選擇即可。

儲存格裡有換行或直線符號 | 怎麼辦?

工具會自動處理:換行轉成 <br>,| 改寫成 \|,避免表格被切斷。貼 CSV 時,含換行或分隔符號的儲存格要用雙引號包起來,欄位內的雙引號寫成兩個 ""。

資料沒有標題列怎麼辦?

取消勾選「第一列是標題」,工具會用「欄 1、欄 2……」當標題列,因為 Markdown 表格的第一列固定是標題。複製後可以再把欄名改成你要的文字。

「對齊欄寬」會改變表格顯示的樣子嗎?

不會。它只在每格補空白,讓原始文字裡的 | 上下對齊,在純文字編輯器裡比較好讀;轉成網頁後的表格和沒勾選時相同。

參考資料

  1. GitHub,〈GitHub Flavored Markdown Spec(Tables extension)〉,2019年4月6日。查閱於 2026年11月21日。

相關內容

  • CSV ⇄ JSON 轉換器工具

    免費 CSV 與 JSON 互轉工具。支援引號、欄位內換行,以及逗號、分號、Tab 分隔;可選擇保留文字或轉換數字,0 開頭的電話與長編號不會被改掉,轉出的 CSV 防公式注入,資料只在瀏覽器處理。

  • AI Prompt 產生器工具

    免費 AI Prompt 產生器。依角色、任務、背景、目標、限制、輸出格式六個欄位填空,即時組成結構清楚的 Prompt,可複製到 ChatGPT、Claude、Gemini,並提醒移除個資。

  • 提案架構產生器工具

    免費提案大綱工具。依提案名稱、對象、背景、問題、目標、做法、時程、預算、風險與成效指標填空,整理成 Markdown 大綱與里程碑表格,並產生請 AI 寫成提案初稿的 Prompt,缺的資訊標成【待補】。

  • 搜尋結果標題與描述預覽工具

    免費搜尋結果預覽工具。輸入頁面標題、meta description 與網址,查看桌機與手機的估計顯示、字數與可能被截斷的位置,並提醒重複關鍵字、描述過短等常見問題。

  • 自己做網頁小工具:從計算邏輯到可用、可及、不外洩資料

    用本站 MIT 授權的程式碼示範怎麼做網頁小工具:計算與畫面分開、用 node:test 測試、處理 type="number" 與 NaN、用 Intl.NumberFormat 格式化金額、無障礙檢查、資料不外洩,以及 CSV 公式注入的防法。

  • 用 AI 整理會議紀錄:可複製 Prompt 與資料保護檢查

    用 AI 把逐字稿整理成決議、待辦(負責人、期限)與待確認事項的可複製 Prompt,附貼上前的去識別化檢查清單、對照逐字稿核對輸出的步驟,以及行政院生成式 AI 參考指引的重點。

  • 寫好 AI Prompt 的六個欄位:角色、任務、背景、目標、限制、輸出格式

    把 Prompt 拆成角色、任務、背景、目標、限制、輸出格式六個欄位,附活動企劃、會議重點、家長通知的寫法對照、可複製範例,以及檢查 AI 輸出與保護資料的做法。