Infragistics (which provides a 3rd party paid control) has a pretty good library that comes with their web controls for creating Excel files. In fact, I’m not using their web controls anymore for work projects but I am using their Excel library still and love it. There are a few things I wish I could do with it like auto sizing cells (I may just not have figured that out yet) but for the most part it does everything I need. Anyway, I needed to merge some cells today in the header of a report.
Dim mergedRegion1 As Infragistics.Excel.WorksheetMergedCellsRegion = ws.MergedCellsRegions.Add(index, 0, index, 6)
The index, is the row that you want to start on (the first one is the row to start on, the second one is the row to end on. In my example, I’m starting and ending on the same row because I want to merge cells across. The 0 and the 6 are the cells that I want to merge, this is essentially saying merge cells 0 all the way through 6. The 4 values here create a rectangle of merged cells.
Here’s a link to the documentation on Infragistics site: http://help.infragistics.com/Help/NetAdvantage/ASPNET/2010.1/CLR3.5/html/ExcelEngine_Merge_Cells.html