跳過到頁腳內容
EXCEL 工具

如何在 Excel 中切換欄位

想自動追蹤數據並計算平均值嗎? 微軟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 中交換多列

Figure 7

  1. 接下來,按一下滑鼠左鍵並拖曳滑鼠,選取所有數據,直到選取數據的最後一個儲存格。
  2. 點選工具列上的"資料"標籤。
  3. 在"排序與篩選"群組中,按一下"排序"。
Data tab - Select sort

圖 8 -資料標籤 - 選擇排序

  1. 將出現"排序"對話框。

點選"選項"。

Sort Dialog Box - Options

圖 9 -排序對話框 - 選項

選擇"從左到右排序"選項,然後按一下"確定"。

Sort Options - Sort left to right

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

然後,在"排序依據"選項中,選擇第 1 行,然後按一下"確定"。

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# 庫

IronXL 為在 .NET 中開啟、讀取、編輯、切換列和儲存 Excel 檔案提供了一個強大且用途廣泛的框架。 它與所有 .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 檔案。 For more information, please visit the following [link](link).

Jordi Bardia
軟體工程師
Jordi 在 Python、C# 和 C++ 上最得心應手,當他不在 Iron Software 展現技術時,便在做遊戲編程。在分担产品测测试,产品开发和研究的责任时,Jordi 为持续的产品改进增值。他说这种多样化的经验使他受到挑战并保持参与, 而这也是他与 Iron Software 中工作一大乐趣。Jordi 在佛罗里达州迈阿密长大,曾在佛罗里达大学学习计算机科学和统计学。