![how to use merge and center in excel horizontally how to use merge and center in excel horizontally](https://www.techonthenet.com/excel/cells/images/center_across2011_001.gif)
- #How to use merge and center in excel horizontally .dll
- #How to use merge and center in excel horizontally code
- #How to use merge and center in excel horizontally windows
You’ll find this in the top portion of your Excel window. You can do this by dragging your mouse to make a box around your print area.
![how to use merge and center in excel horizontally how to use merge and center in excel horizontally](https://www.exceltip.com/wp-content/uploads/2014/08/22.png)
#How to use merge and center in excel horizontally .dll
One more thing we need to do is add a reference to .dll and import the same DLL to be able to use the Excel Interop API. So there you have it, we can put these 3 steps into a method and use it whenever we want to merge and center cells.
![how to use merge and center in excel horizontally how to use merge and center in excel horizontally](https://support.content.office.net/en-us/media/0fa97ae4-5dcf-4632-863c-c579a80e0b67.png)
Range.HorizontalAlignment = .XlHAlign.xlHAlignCenter This can be done again with a single statement as shown below Center the cells – Finally, we need to set the alignment of the data in the merged cells so that data appears centered horizontally.( Warning – there might be data loss if multiple cells within the range have different values) Merge the cells – Once we have the handle to the range, we can call the Merge() on the range to do just that – merge the cells that form the range into a single cell.The parameters that we need to pass to the get_Range() specify where we want the range to start and where it should end. Here, excelApp refers to an instance of .Application class. Range range = excelApp.get_Range(sheet.Cells, sheet.Cells) Get an Excel range – For folks familiar with Excel interop, they would be aware that for most operations we would need to get our hands on an Excel Range object and then perform the intended operation on the range.So let’s take a look at the steps involved:
#How to use merge and center in excel horizontally code
To accomplish this, we need to perform 3 steps, and they are as easy as they come – each step requires a single line of code in C#. Specifically, let’s look at how we can merge a collection of cells and center them through. However, there are still many systems that rely heavily on Interop for this so in this post, I will be talking using the Interop approach to work with Excel. To be clear, Open XML is the recommended approach for working with Office applications using.
#How to use merge and center in excel horizontally windows
Many a times, we need to generate Excel reports as output from Windows applications.