⧉

Merge CSV Files

Combine multiple CSV files into one table

—
No file selected.

Merge CSV Files — what it does

Stack several CSV files into one table, with an option to add a column recording which file each row came from. Unlike a join, this appends rows rather than widening them, which is what you need when a report arrives split by month, by branch or by export batch.

Worked example

January and February sales exports stacked into one file with Add source file column ticked. The February file has an extra discount column.

Input — sales-jan.csv and sales-feb.csv

sales-jan.csv
order_id,region,amount
1001,East,42.00
1002,West,26.97
1003,East,17.50

sales-feb.csv
order_id,region,amount,discount
1004,North,42.00,5.00
1005,West,24.50,0.00

Output — merged.csv

Source file,order_id,region,amount,discount
sales-jan.csv,1001,East,42.00,
sales-jan.csv,1002,West,26.97,
sales-jan.csv,1003,East,17.50,
sales-feb.csv,1004,North,42.00,5.00
sales-feb.csv,1005,West,24.50,0.00

Headers are the union of both files in first-seen order, so the January rows get an empty discount cell. The page reports 5 rows · 4 columns (the Source file column is not counted) and merged.csv starts with a UTF-8 byte-order mark.

When this tool helps

  • Combining twelve monthly exports into a single file before analysing a full year.
  • Merging per-branch or per-region reports that share the same column layout.
  • Consolidating results collected by several people into one dataset for review.

How to use it

  1. Select all the CSV files to combine.
  2. Turn on the source filename column if you need provenance.
  3. Process the merge.
  4. Download the combined CSV.

Accuracy, limits, and good practice

  • Files should share the same headers. Mismatched column names produce a table with gaps where a file did not supply that field.
  • The source filename column is worth keeping — once rows are stacked, there is otherwise no way to tell where a given row came from.
  • Check for duplicate rows afterwards, especially if the exports overlapped in date range; the deduplicator will clean them by key.

Frequently asked questions

Is the header repeated for each file?

No. One header row is written and the data rows from every file follow beneath it.

Does file selection order matter?

It sets the row order in the output. Sort afterwards with the CSV sorter if you need a specific sequence.

What if one file uses semicolons?

Convert it first with the delimiter converter so all inputs parse consistently before merging.

Are columns matched by name or by position?

By name. Each row is placed under the combined header list using its own file's headers, so a column that exists in only one file is left empty for the others, and a header spelled differently (Amount versus amount) becomes a separate column.

Does the Source file column contain the full path?

No, only the file name as it was selected (sales-jan.csv), never the folder it came from. The column is always first and is only added when the checkbox is ticked.

Related tools on this site

Everything above runs inside this page. Merge CSV Files needs no account, no upload, and no server round trip — close the tab and nothing is left behind.

合併 CSV 檔案能做什麼

把多份 CSV 疊成同一張表,並可選擇加上一欄記錄每列來自哪個檔案。與關聯合併不同,這是往下追加資料列而非往右加寬欄位,正好用在報表依月份、依分店或依批次分開匯出的情況。

實際範例

一月與二月的銷售匯整檔疊成一份,並勾選加上來源檔名欄位。二月的檔案多了一個 discount 欄。

來源:sales-jan.csv 與 sales-feb.csv

sales-jan.csv
order_id,region,amount
1001,East,42.00
1002,West,26.97
1003,East,17.50

sales-feb.csv
order_id,region,amount,discount
1004,North,42.00,5.00
1005,West,24.50,0.00

得到:merged.csv

Source file,order_id,region,amount,discount
sales-jan.csv,1001,East,42.00,
sales-jan.csv,1002,West,26.97,
sales-jan.csv,1003,East,17.50,
sales-feb.csv,1004,North,42.00,5.00
sales-feb.csv,1005,West,24.50,0.00

欄名是兩檔的聯集,依首次見到的順序排列,所以一月的列 discount 留白。頁面顯示 5 rows · 4 columns(Source file 欄不計),merged.csv 開頭帶 UTF-8 BOM。

什麼時候用得上

  • 把十二份月報匯出檔合成一份,再進行全年分析。
  • 合併欄位結構相同的各分店或各地區報表。
  • 把多人各自收集的結果整合成單一資料集以供檢視。

使用步驟

  1. 選取所有要合併的 CSV 檔案。
  2. 如需追溯來源,開啟來源檔名欄位。
  3. 執行合併。
  4. 下載合併後的 CSV。

精確度、限制與實務建議

  • 各檔案應使用相同標題。欄位名稱不一致時,缺少該欄的檔案會在表中留下空格。
  • 來源檔名欄很值得保留,資料一旦疊在一起,否則就無從得知某一列出自哪份檔案。
  • 合併後請檢查重複列,尤其匯出區間有重疊時;可用去重工具依鍵值清理。

常見問題

每個檔案的標題都會重複出現嗎?

不會。只會寫入一列標題,所有檔案的資料列接在其下方。

選檔順序有差嗎?

會決定輸出的列順序。若需要特定順序,可事後用 CSV 排序工具處理。

如果其中一份用分號分隔呢?

請先用分隔符轉換工具統一格式,確保所有輸入都能一致解析後再合併。

欄位是依名稱還是依位置對齊?

依名稱。每一列都按它所屬檔案的欄名放到合併後的欄位清單底下,只在某一個檔案裡有的欄位,其他檔案的列就留空;拼法不同的欄名(Amount 與 amount)會變成兩個欄位。

Source file 欄會寫完整路徑嗎?

不會,只寫選取時的檔名(sales-jan.csv),不含資料夾。該欄永遠排第一,且只有勾選核取方塊時才會加上。

本站相關工具

以上步驟全部在這個頁面內完成,合併 CSV 檔案 不需要註冊、不上傳檔案、也不經過伺服器,關閉分頁後不會留下任何資料。