跳至頁尾內容
EXCEL 工具

如何在 Excel 中切換欄位

想要自動跟蹤您的資料並計算平均值嗎? Microsoft Excel是世界上使用最廣泛的電子表格應用程式,擁有數百萬使用者。 Excel和其他電子表格程式非常適合資料處理、分析和可視化,因為它們允許您在一個位置排序、篩選、格式化和製作圖表。 考慮為實地考察收集聯絡資訊。

表格是由Excel電子表格中的列和行集合建立的。 列通常分配字母,而行通常分配數字。 單元格是列和行的交集。 單元格的地址由表示列的字母和表示行的數字決定。

您是否想過如何在Excel表格中移動列?

本教程涵蓋如何切換或移動多個列。 更改相鄰列是大多數人經常做的事情。 本教程將向您展示如何:

  1. 使用Shift鍵方法切換兩列
  2. 使用剪切和粘貼方法交換整列的位置
  3. 在Excel中一次移動多列
  4. 使用鍵盤快捷鍵切換兩個Excel列

使用Shift鍵方法切換兩列

當您使用拖放方式切換Excel列時,它只會突出顯示單元格而不是移動它們。 如果要移動選定的列,請使用Shift鍵方法; 要做到這一點,有幾個步驟:

  1. 打開Excel應用程式。
  2. 右鍵點擊要移動的列的標題。 這將選擇整列。
  3. 將光標移至該列的右側。 光標將更改為四方向箭頭圖標。
  4. 在列的側面左鍵點擊並按下Shift鍵。
  5. 簡單地拖動列並按住Shift鍵。 您將看到一條線 "|" 顯示您的下個列將插入的位置。
  6. 放開左鍵和Shift鍵。
  7. 第一列將替換第二列,將列移至一側。
  8. 然後,選擇第二列,使用相同的方法將其移動到第一列的位置。
Microsoft Excel - First Positions

圖1 - Microsoft Excel - 第一位置

Microsoft Excel - Second Positions

圖2 - Microsoft Excel - 第二位置

Microsoft Excel - Final Position

圖3 - Microsoft Excel - 最終位置

注意:在不按住Shift鍵的情況下更改位置會重疊第二列的資料。

使用剪切和粘貼方法交換整列的位置

如果拖放方法對您不起作用,您也可以使用剪切和粘貼方法。 以下是步驟:

  1. 打開Microsoft Excel應用程式。
  2. 右鍵點擊您想移動的列的標題。 這將突出顯示整列。
  3. 突出顯示後,在列標題上右鍵單擊並選擇"剪切"選項。 您也可以按Ctrl + X來剪切列。
  4. 點擊要與另一列交換的列標題。
  5. 當突出顯示時,右鍵單擊列並從選單中點擊"插入剪切單元格"。
  6. 這將把該列插入到最初的位置。
  7. 使用相同的方法將第二列移動到另一列的位置。
Microsoft Excel - Cut option

圖4 - Microsoft Excel - 剪切選項

Microsoft Excel - Insert cut cells

圖5 - Microsoft Excel - 插入剪切單元格

Microsoft Excel - Last Position

圖6 - Microsoft Excel - 最後位置

注意:根據幾項條件規則,在複製/粘貼整列時,您將不允許在選擇的區域插入新列。

在Excel中一次移動多列

要在Excel中一次移動多列,請按照以下簡單步驟進行:

  1. 選擇第一行; 然後右鍵點擊該行並選擇插入選項。
  2. 使用第一行來安排新的列順序。
  3. 然後,根據您希望列顯示的模式,在新行中新增值。
How To Switch Columns In Excel 7 related to 在Excel中一次移動多列

圖7

  1. 接下來,通過左鍵點擊並拖動它到資料的最後單元格來選擇所有資料。
  2. 點擊工具欄上的"資料"選項卡。
  3. 在那裡,點擊"排序"在"排序和篩選"組中。
Data tab - Select sort

圖8 - 資料選項卡 - 選擇排序

  1. 將顯示"排序"對話框。

點擊"選項"。

Sort Dialog Box - Options

圖9 - 排序對話框 - 選項

選擇"從左到右排序"選項並點擊"OK"。

Sort Options - Sort left to right

圖10 - 排序選項 - 從左到右排序

然後,在"排序依據"選項中,選擇第1行並點擊"OK"。

Sort Dialog Box - Sort by

圖11 - 排序對話框 - 排序依據

刪除新插入的行。

結果:

Result

圖12 - 結果

使用鍵盤快捷鍵切換兩個Excel列

使用鍵盤快捷鍵可以輕鬆切換兩個列。 按照這些步驟更改選定的列:

  1. 在Excel中選擇列中的任何單元格。
  2. 按住Ctrl並按空格鍵選擇整個列。
  3. 接下來,再次按住Ctrl並按"X"鍵剪切它。
  4. 選擇要與第一個列交換的列。
  5. 再次按住Ctrl並按空格鍵突出該列。
  6. 按住Ctrl鍵並按(+)鍵將第一個插入到新位置。
  7. 移至第二列並按住Ctrl並按空格鍵選擇整列。
  8. 按Ctrl + 'X'剪切列。
  9. 選擇第一個的位置並按Ctrl +(+)。
  10. 這將切換兩列的位置。
Microsoft Excel - First Position

圖13 - Microsoft Excel - 第一位置

Microsoft Excel - Second Position

圖14 - Microsoft Excel - 第二位置

Microsoft Excel - Final Position

圖15 - Microsoft Excel - 最終位置

IronXL C#程式庫

要在.NET中打開、閱讀、編輯、切換列和保存Excel文件,IronXL提供了一個多功能而強大的框架。 它與所有.NET專案型別相容,包括Windows應用程式、ASP.NET MVC和.NET Core應用程式。

對於.NET開發人員,IronXL提供了一個簡單的API來讀寫Excel文件。

為了存取Excel處理腳本,IronXL不需要在您的伺服器上安裝Microsoft Office Excel,也不需要使用Excel Interop。這使得在.NET中處理Excel文件變得非常快速和簡單。

使用IronXL,開發人員可以通過編寫幾行程式碼執行所有與Excel相關的計算,包括新增兩個單元格、整列選項、在Excel表格中新增整個列、在Excel表格中新增整行、使用求和功能以及處理多個列和多個行的許多其他有用功能。

以下是一些C#程式碼範例。

using IronXL;

// Load an existing Excel workbook from a file.
WorkBook workbook = WorkBook.Load("test.xlsx");

// Access the default worksheet in the workbook.
WorkSheet worksheet = workbook.DefaultWorkSheet;

// Set formulas in specific cells.
// A1 will calculate the sum of the range B8 to C12.
worksheet["A1"].Formula = "Sum(B8:C12)";

// B8 will calculate the division of C9 by C11.
worksheet["B8"].Formula = "=C9/C11";

// G30 will find the maximum value in the range C3 to C7.
worksheet["G30"].Formula = "Max(C3:C7)";

// Force recalculation of all formula values in all sheets.
workbook.EvaluateAll();

// Get the calculated value from a formula, e.g., the calculated value in G30.
string formulaValue = worksheet["G30"].Value;

// Get the formula as a string representation, e.g., "Max(C3:C7)" for G30.
string formulaString = worksheet["G30"].Formula;

// Save the workbook with updated formulas and values.
workbook.Save();
using IronXL;

// Load an existing Excel workbook from a file.
WorkBook workbook = WorkBook.Load("test.xlsx");

// Access the default worksheet in the workbook.
WorkSheet worksheet = workbook.DefaultWorkSheet;

// Set formulas in specific cells.
// A1 will calculate the sum of the range B8 to C12.
worksheet["A1"].Formula = "Sum(B8:C12)";

// B8 will calculate the division of C9 by C11.
worksheet["B8"].Formula = "=C9/C11";

// G30 will find the maximum value in the range C3 to C7.
worksheet["G30"].Formula = "Max(C3:C7)";

// Force recalculation of all formula values in all sheets.
workbook.EvaluateAll();

// Get the calculated value from a formula, e.g., the calculated value in G30.
string formulaValue = worksheet["G30"].Value;

// Get the formula as a string representation, e.g., "Max(C3:C7)" for G30.
string formulaString = worksheet["G30"].Formula;

// Save the workbook with updated formulas and values.
workbook.Save();
Imports IronXL

' Load an existing Excel workbook from a file.
Private workbook As WorkBook = WorkBook.Load("test.xlsx")

' Access the default worksheet in the workbook.
Private worksheet As WorkSheet = workbook.DefaultWorkSheet

' Set formulas in specific cells.
' A1 will calculate the sum of the range B8 to C12.
Private worksheet("A1").Formula = "Sum(B8:C12)"

' B8 will calculate the division of C9 by C11.
Private worksheet("B8").Formula = "=C9/C11"

' G30 will find the maximum value in the range C3 to C7.
Private worksheet("G30").Formula = "Max(C3:C7)"

' Force recalculation of all formula values in all sheets.
workbook.EvaluateAll()

' Get the calculated value from a formula, e.g., the calculated value in G30.
Dim formulaValue As String = worksheet("G30").Value

' Get the formula as a string representation, e.g., "Max(C3:C7)" for G30.
Dim formulaString As String = worksheet("G30").Formula

' Save the workbook with updated formulas and values.
workbook.Save()
$vbLabelText   $csharpLabel

開發者在C#中修改和編輯Excel文件時必須謹慎,因為一個小錯誤可能會改變整個文件。 能夠依賴高效和簡單的程式碼行有助於減少錯誤風險,並使我們更容易以程式方式編輯或刪除Excel文件。 今天,我們將演練快速和準確編輯C#中的Excel文件所需的步驟,使用已經過充分測試的功能。 如需更多資訊,請存取以下連結

Curtis Chau
技術作家

Curtis Chau擁有Carleton大學的電腦科學學士學位,專精於前端開發,擁有Node.js、TypeScript、JavaScript和React的專業知識。Curtis熱衷於建立直觀且美觀的使用者介面,喜愛使用現代框架並建立結構良好、視覺吸引力的手冊。

除了開發,Curtis對物聯網(IoT)有濃厚的興趣,探索創新的方法來整合硬體和軟體。在空閒時間,他喜歡玩遊戲和建立Discord機器人,結合他對技術的熱愛與創造力。

Iron 支援團隊

我們線上24小時,每週5天。
聊天
電子郵件
給我打電話