This project has moved and is read-only. For the latest updates, please go here.

[Solved] Cell SetColor System.ArgumentException

Apr 13, 2012 at 12:20 PM
Edited Apr 13, 2012 at 12:35 PM


i getting te follwing error if i try to add color to a cell:
Eine Ausnahme (erste Chance) des Typs "System.ArgumentException" ist in EPPlus.dll aufgetreten.

Here is my code:

Dim newFile As FileInfo = New FileInfo("C:\temp\created.xlsx")
	If newFile.Exists Then
	newFile = New FileInfo("C:\temp\created.xlsx")
End If
Using Package As New ExcelPackage(newFile)
	Dim Worksheet As ExcelWorksheet = Package.Workbook.Worksheets.Add("Export")

	Worksheet.Cells("A1").Value = "Test"
	Worksheet.Cells("A1").Style.Font.Bold = True
End Using
If i comment Worksheet.Cells("A1").Style.Fill.BackgroundColor.SetColor(Color.Brown) out, all worked fine.
Any ideas ?
L0L... i've found the answer after a little more testing.
Before you can call SetColor(), you must set the PatternType:
Worksheet.Cells("A1").Style.Fill.PatternType = ExcelFillStyle.Solid
Apr 13, 2012 at 1:33 PM
Edited Apr 13, 2012 at 1:34 PM


set patterntype before setcolor...

            using (ExcelPackage p = new ExcelPackage(tmpl1))
                var ws = p.Workbook.Worksheets.Add("teste");
                ws.Cells["A1"].Value = "Test";
	        ws.Cells["A1"].Style.Font.Bold = true;
                ws.Cells["A1"].Style.Fill.PatternType = ExcelFillStyle.Solid;




Ops, I didnt see you´ve already solved your issue hehehe =)