What is objData
? Generally speaking, you shouldn't need to add columns to a sheet - EPPlus will do this automatically when your reference the cell for the first time. My VB is a little rusty but this works fine for me:
<TestMethod> _
Public Sub PhoneNumberFormatTest()
Dim file = New FileInfo("c:\temp\temp.xlsx")
If file.Exists Then
file.Delete()
End If
Dim pck = New ExcelPackage(file)
Dim workbook = pck.Workbook
Dim worksheet = workbook.Worksheets.Add("newsheet")
Const number As String = "6028035615"
Const format As String = "(###) ###-####"
Dim startcell = worksheet.Cells(1, 1)
startcell.Value = Int64.Parse(number)
startcell.Offset(1, 0).Value = Int64.Parse(number) + 1
worksheet.Column(1).Width = 15
worksheet.Column(1).Style.Numberformat.Format = format
pck.Save()
End Sub
I downloaded the source code solution of EPPlus 3 (stable) and ran this as a unit test...
EDIT: Added string manipulation:
<TestMethod> _
Public Sub PhoneNumberFormatTest()
Dim file = New FileInfo("c:\temp\temp.xlsx")
If file.Exists Then
file.Delete()
End If
Dim pck = New ExcelPackage(file)
Dim workbook = pck.Workbook
Dim worksheet = workbook.Worksheets.Add("newsheet")
Const number As String = "6028035615"
Const format As String = "(###) ###-####"
Dim startcell = worksheet.Cells(1, 1)
'Directly to numbers with parse
startcell.Value = Int64.Parse(number)
startcell.Offset(1, 0).Value = Int64.Parse(number) + 1
'OR as a string back to a number.
Dim stringcell = startcell.Offset(2, 0)
stringcell.Value = number
stringcell.Value = Int64.Parse(DirectCast(stringcell.Value, String))
stringcell.Style.Numberformat.Format = "(###) ###-####"
'As string - does not work as number
stringcell.Offset(0, 1).Value = number
stringcell.Offset(0, 1).Style.Numberformat.Format = "(###) ###-####"
worksheet.Column(1).Width = 15
worksheet.Column(1).Style.Numberformat.Format = format
pck.Save()
End Sub