CreateNamedStyle template issue

Oct 17, 2011 at 10:07 PM
Edited Oct 19, 2011 at 3:46 PM

I tried to use the « Template » parameter in the CreateNamedStyle function and I always get this error : « ArgumentOutOfRangeException was unhandled. »

Here is a code sample :


 

Dim fiFile As IO.FileInfo
Dim excelFile As ExcelPackage
Dim wsSheet As ExcelWorksheet

Try

	If IO.File.Exists("testExcel.xlsx") Then
		IO.File.Delete("testExcel.xlsx")
	End If
	fiFile = New IO.FileInfo("testExcel.xlsx")

	excelFile = New ExcelPackage(fiFile)
	wsSheet = excelFile.Workbook.Worksheets.Add("test1")

	Dim firstNamedStyle As Style.XmlAccess.ExcelNamedStyleXml = _
		excelFile.Workbook.Styles.CreateNamedStyle("tempFirst")
	With firstNamedStyle.Style
		.HorizontalAlignment = Style.ExcelHorizontalAlignment.CenterContinuous
		.VerticalAlignment = Style.ExcelVerticalAlignment.Center
	End With
	Console.WriteLine(firstNamedStyle.Name)

	With excelFile.Workbook.Styles.CreateNamedStyle("first", _
			firstNamedStyle.Style).Style
		.Font.Bold = True
		.Font.SetFromFont(New Font("Arial Black", 8))
		.Border.Bottom.Style = Style.ExcelBorderStyle.Medium
		.Border.Left.Style = Style.ExcelBorderStyle.Medium
	End With

	wsSheet.Cells("B2").Value = "Center"
	wsSheet.Cells("B2").StyleName = "first"

	excelFile.Save()

Catch ex As Exception
	Console.WriteLine(ex.Message)

	Console.Read()
Finally
End Try

 


 

What am I doing wrong ?

Coordinator
Oct 19, 2011 at 7:05 AM

I think this is a bug. Try the lates source and see if it works for you. Otherwise report it as an issue