﻿# 如何在 Microsoft Office Excel 搜尋與取代斷行符號

原本我們可以很容易的從 Excel 複製/貼上儲存格的資料進資料庫，只要透過 Management Studio 就可以辦到。但是只要遇到客戶提供 Excel 文件的儲存格(Cell)中有「斷行符號」時就會破功，資料將會無法完整匯入，所以你就需要如何在 Excel 中快速取代「斷行符號」了。

![Excel - Search and Replace](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/7b2d9ea398df7c3ec58b-201603436-1d378283-7032-49f9-9b8a-0f0541a69e3e.png)

### 先說 Excel 如何搜尋取代斷行符號

老實說這個功能設計的不是太顯眼，直接從 Excel 中是很難發現的，一定要 Google 才能搜尋到答案，以下是操作步驟：

1.  按下 `Ctrl+H` 進入「尋找及取代」的對話框
    
    ![image](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/6ebc1add3e90d626903a-201529442-decf54b0-4be1-4a55-9b59-b048377d3384.png)
    
2.  在「尋找目標」欄位按下 `Ctrl+J` 插入斷行字元
    
    因為「斷行符號」是不可見字元，所以這個步驟非常不顯眼，一定要看仔細，輸入框中會出現一個第二行的鍵盤游標，非常非常小喔！
    
    ![image](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/bcef64307508cf9dbe82-201529544-d88bfe6f-ca7c-412e-a31e-aaf801f610b3.png)
    
3.  在「取代成」欄位輸入一個你希望替代的字元
    
    例如我的目的是快速匯入資料到資料庫中，所以我會選擇一個一定不會出現的字元，例如 `$$` 符號，等匯入後再一次取代掉！
    
    ![image](https://stwillblogassets.blob.core.windows.net/files/images/external/user-images.githubusercontent.com/a371e294f5c1c0fe650a-201529639-331e869d-d608-4b44-8898-14052309089f.png)
    
4.  最後按下「全部取代」就可以完成所有斷行符號的置換！ 👍
    

### 透過 Management Studio 快速匯入 Excel 資料的方法

這部分我直接透過錄製影片的方式來解說比較清楚：

> [如何快速從 Excel 匯入資料到 SQL Server 資料庫中](https://youtu.be/ZBB1VuWt2sU)

<iframe title="YouTube video player" src="https://www.youtube.com/embed/ZBB1VuWt2sU" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen"></iframe>

### 相關連結

-   [Quick Tip: Find and Replace Line Breaks in Cells - Contextures Blog](https://contexturesblog.com/archives/2021/02/18/find-and-replace-line-breaks-in-excel-2/)
