使用 IRONXL 如何在 Excel 中合并单元格:逐步教程 Curtis Chau 已更新:六月 22, 2025 Download IronXL NuGet 下载 DLL 下载 Start Free Trial Copy for LLMs Copy for LLMs Copy page as Markdown for LLMs Open in ChatGPT Ask ChatGPT about this page Open in Gemini Ask Gemini about this page Open in Grok Ask Grok about this page Open in Perplexity Ask Perplexity about this page Share Share on Facebook Share on X (Twitter) Share on LinkedIn Copy URL Email article Many people find it challenging to understand how to merge cells in Excel. At first, this may seem like a daunting task, but we've got your back! This blog will walk you through how to quickly merge cells in Excel. IronXL: The C# Excel Library IronXL is a C# Excel library with many advanced features for Excel operations. One main benefit of the IronXL C# library is that you don't need to install Excel software locally on your system. It processes the Excel document without using Excel software. You can create a new Excel file and format data according to your needs using the IronXL C# library. It is a complete go-to package for all Excel operations. If you are building any software and have to create or edit an Excel file in your software, you can quickly perform such tasks with the help of the IronXL library. To use this library in your software build, you must download its DLL file or install it with NuGet Package Manager. You can use the free trial version to test all the features. The trial version is free, and it is very straightforward to use the license key with your project. You can also use this tutorial to better understand it. Once you are satisfied with IronXL, you can buy it at a very reasonable price. Next, we will talk about how to merge cells in Excel using the IronXL C# library. IronXL provides elementary and easy-to-use functions to read and merge cells in an Excel file. Let's examine how to join cells in C# language using the IronXL library: Create a C# .NET or VB .NET project in Visual Studio. Download the DLL file of the IronXL library or install it via NuGet Package Manager in Visual Studio. Apply your License key using this tutorial. Use IronXL in your project. using IronXL; using IronXL; Imports IronXL $vbLabelText $csharpLabel Load an Excel book using the WorkBook.Load() static function. // Load an existing Excel file WorkBook wb = WorkBook.Load("fileaddress.xlsx"); // Load an existing Excel file WorkBook wb = WorkBook.Load("fileaddress.xlsx"); ' Load an existing Excel file Dim wb As WorkBook = WorkBook.Load("fileaddress.xlsx") $vbLabelText $csharpLabel When the Excel file loads, select the sheet where we merge cells using the GetWorkSheet() function. // Get a specific worksheet by name WorkSheet ws = wb.GetWorkSheet("SheetName"); // Get a specific worksheet by name WorkSheet ws = wb.GetWorkSheet("SheetName"); ' Get a specific worksheet by name Dim ws As WorkSheet = wb.GetWorkSheet("SheetName") $vbLabelText $csharpLabel We have selected the sheet where we have to merge cells. Let's choose the cell address to merge using the Merge() function. // Merge cells from the specified range ws.Merge("FromCell:ToCell"); // Merge cells from the specified range ws.Merge("FromCell:ToCell"); ' Merge cells from the specified range ws.Merge("FromCell:ToCell") $vbLabelText $csharpLabel Selected cells are merged, and now it's time to save the edited file using the SaveAs() function. // Save the workbook to a new file wb.SaveAs("Filename.xlsx"); // Save the workbook to a new file wb.SaveAs("Filename.xlsx"); ' Save the workbook to a new file wb.SaveAs("Filename.xlsx") $vbLabelText $csharpLabel You have now seen how easy it is to merge cells in Excel using the IronXL library, given a working knowledge of C#. You can also use the tutorials on Excel operations in the IronXL official documentation. Furthermore, IronXL also offers a wide range of features to interact with Excel WorkBook, WorkSheet and Cells level such as converting between popular formats, cell data formatting, merging cells, inserting math functions, and even adding images. You can download a zip file project that demonstrates how to merge cells. Merging Cells in Microsoft Excel Introduction to Microsoft Excel Microsoft Excel is a spreadsheet application that helps users organize, analyze, and share data. It is one of the most popular office software programs to date. The goal of Excel is to simplify analyzing and managing data so people to be more productive at work. This particular tutorial will discuss how to merge cells in Excel. Before proceeding to examine how to join cells in Excel, you need to have a basic working knowledge of the following terms: cells and ranges. What are Cells and Ranges in Excel Cells A cell is the smallest unit of data in a spreadsheet. This is where you enter data, formulas, and other information. Every spreadsheet has a grid made up of rows and columns, and every cell in the grid is assigned an address that uniquely identifies it on the grid. You can identify cells by their location in the grid, such as A1 or B3. Ranges A cell range is a group of cells with different addresses. For example, a cell range with two numbers must be formatted as A1:A5. In Excel, the default reference style is "Cells," which must be changed if you want to use a different one. There are two kinds of ranges: horizontal and vertical. Each type has its purpose and uses. Methods of Merging Cells in Excel Merging cells is essential because it saves time when working with large tables with many rows and columns. When merging cells, the software will automatically center on the merged cell so that there's no need to adjust it manually. When we merge cells, most upper-left cell values are retained. This will also make your table look nicer and easier to read. Let's look at how we can merge multiple cells in Excel. 1) Using the Merge & Center Button Navigate to Merge Button in Excel The Merge & Center button is the simplest method to merge cells in Excel. Let's examine how to merge cells using this method: Open your Excel file in Microsoft Excel. Excel File opened in Microsoft Excel Select the cells you want to merge. Select two cells Now click on the Merge & Center button to merge selected cells. Merge & Center button The cells will be merged. You will get this output: Merged cell displayed in Microsoft Excel This method automatically merges cells and makes content aligned as centered. It is important to note that the software always preserves the furthest upper-left cell value. Other values will be discarded. 2) Merge cells using the "Format Cells" dialogue box You can merge cells using the "Format Cells" dialogue box. This gives you multiple options. Let's examine how to merge cells using the "Format Cells" dialogue box: Open your file in the Excel Software. Excel File opened in Microsoft Excel Select the cells you want to merge. Selecting cells Open the "Format Cells" dialogue box. You can open it in various ways. Go to the Home tab and click on the arrow icon on the Format button in the Cells section, and from the dropdown, select the Format Cells option. Navigate to Format Cells button You can open the Format Cells dialogue box using the keyboard shortcut Ctrl + 1. The third way to open this dialogue box is to right-click on selected cells and select the Format Cells menu. Accessing Format Cells from right-click menu The Format Cells dialogue box will open. Go to the alignment tab, select merge cells, and click the OK button. Format Cells dialog Selected cells will be merged. You can identify merged cells by checking the borderlines of the cells. Merged cell Notice that data in cells is not centered using this technique. This needs to be done manually from the home tab using the formatting section. 3) Alt Hot Key You can perform this task quickly if you don't want to use your mouse, and instead use the keyboard to merge cells. You must select the cells you want to join and press Alt + H + M + C simultaneously. Your selected cells will be merged. 4) Quick Access Toolbar If you want to use the merge tool frequently, you can add this option to your quick-access toolbar. Let's look at how we can add the Merge and Center option to the Quick Access toolbar. Go to the title bar and click on the little arrow icon. It will show a dropdown. From the dropdown, select the More Commands option. Navigate to More Commands A new pop-up box will open. Scroll down and select the Merge and Center option. Excel Options UI After selecting Merge and Center, click the Add button, and this will add the command to the Quick Access toolbar options. Next, press OK to apply this change. Adding Merge & Center button into the toolbar Now, you can use the Merge and Center option using the Quick Access toolbar. Quick Access toolbar UI You can use this button using Alt with another key. You can see which key is related to the Quick Access toolbar option by clicking the Alt key. Quick Access toolbar UI with Shortcut key displayed You can use the Alt + 5 key combination to merge cells quickly. 5) Concatenate Function If you wish to combine data from two or more columns, then the Merge and Center option will not work because it retains only the first cell's data and discards that from other cells. If you try to merge two or more cells that contain data, it will give you a warning as shown below: Discard data dialog To combine the data from cells, you have to use an Excel function called the "Concatenate" function. Let's see how it works. Let's say we want to combine a first name and a second name. Data displayed before using concatenate Function We can't do it using the Merge and Center option. We will do it using the Concatenate function. Now move to the cell after the second name, where the data will be combined. Type =Concatenate() and in parameters, give the address of those cells whose data you want to merge, like this: =CONCATENATE(A1, " ", B1) Adding a new cell with concatenate function Press Enter, and you will see that the data from the two cells has been merged. The result using Excel function Next, select the cell where the data is combined and dragged from the user to apply a function on other cells in the column. Applying to multiple cells in the same column The final result You will see that the data from the two cells have been combined. You can now delete the columns if you don't want them. Unmerge Cells We can unmerge cells with a straightforward method: Select the merged cells in Excel. Go to the home tab and click on the Merge and Center button. It will unmerge cells. This is how you can unmerge cells very quickly. If you wish to unmerge all merged cells in Excel, you can do it easily as follows: Press Ctrl+A to select the whole sheet. Go to the Home tab and select the Merge and Center button. It will unmerge all merged cells in an Excel sheet with just one click. 常见问题解答 如何使用C#在Excel中合并单元格? 您可以使用IronXL通过先加载Excel工作簿(使用WorkBook.Load()),选择所需的工作表(使用GetWorkSheet()),然后使用Merge()方法指定您要合并的单元格范围,来合并Excel中的单元格。 使用C#库自动化Excel任务有哪些优势? 在C#中使用IronXL自动化Excel任务允许您执行复杂的操作而不需要安装Microsoft Excel。它通过提供诸如数据格式化、合并单元格等功能,直接通过C#来提高生产力和效率。 是否可以通过编程方式在Excel中合并和居中数据? 是的,使用IronXL,您可以通过C#程序代码在Excel文件中编程合并单元格和居中数据。合并单元格使用Merge()方法后,您可以使用适当的属性将文本对齐到中心位置。 如何使用C#在Excel中取消合并单元格? 要使用IronXL在Excel中取消合并单元格,请加载工作簿,访问工作表,然后对您要分开的合并单元格范围使用Unmerge()方法。 IronXL能够在不安装Excel的情况下处理Excel操作吗? 是的,IronXL允许您直接在C#中创建、编辑和操作Excel文件,而无需在您的计算机上安装Microsoft Excel。 如何使用C#自动化Excel中的Concatenate函数? IronXL使您能够通过编程将多个单元格中的文本合并到一个单元格中,实现Concatenate函数的自动化。 使用IronXL在Excel中合并单元格有哪些步骤? 要使用IronXL合并单元格,首先在Visual Studio中创建一个C#项目,引用IronXL库,加载您的Excel文件,选择工作表,然后使用Merge()方法合并您想要的单元格范围。 Curtis Chau 立即与工程团队聊天 技术作家 Curtis Chau 拥有卡尔顿大学的计算机科学学士学位,专注于前端开发,精通 Node.js、TypeScript、JavaScript 和 React。他热衷于打造直观且美观的用户界面,喜欢使用现代框架并创建结构良好、视觉吸引力强的手册。除了开发之外,Curtis 对物联网 (IoT) 有浓厚的兴趣,探索将硬件和软件集成的新方法。在空闲时间,他喜欢玩游戏和构建 Discord 机器人,将他对技术的热爱与创造力相结合。 相关文章 已发布十月 27, 2025 如何在 C# 中创建 Excel 数据透视表 学习通过这个清晰的分步指南使用C# Interop和IronXL在Excel中创建数据透视表。 阅读更多 已发布十月 27, 2025 如何在C#中将DataGridView导出到包含列头的Excel 学习如何在将DataGridView数据导出到Excel时保留列头。使用IronXL库的C#逐步教程。 阅读更多 已发布十月 27, 2025 如何在.NET Core中使用CSV Reader与IronXL 学习通过实际示例有效地使用IronXL作为.NET Core的CSV读取器。 阅读更多 如何在 Excel 中锁定单元格:逐步教程使用 C# 创建 CSV 文件
已发布十月 27, 2025 如何在C#中将DataGridView导出到包含列头的Excel 学习如何在将DataGridView数据导出到Excel时保留列头。使用IronXL库的C#逐步教程。 阅读更多