Imports NPOI.SS.UserModel
Imports NPOI.HSSF.Util
''----------------------------------
Public Sub MergeCells()
Dim srcWB As HSSFWorkbook = Nothing
Dim filePath = "C:\test.xls"
Using fs As New FileStream(filePath, FileMode.Open, FileAccess.Read)
srcWB = New HSSFWorkbook(fs)
End Using
Dim sheet As HSSFSheet = srcWB.GetSheetAt(0)
'Set row number
Dim startRow = 2
Dim endRow = 4
'Set column
number
Dim startColumn = 2
Dim endColumn = 2
sheet.AddMergedRegion(New CellRangeAddress(startRow, endRow, startColumn, endColumn))
Dim savePath As String = "C:\test1.xls"
Using fs As New FileStream(savePath, FileMode.Create, FileAccess.Write)
srcWB.Write(fs)
End Using
MsgBox("done")
End Sub