[Solved] Cell SetColor System.ArgumentException

Apr 13, 2012 at 11:20 AM
Edited Apr 13, 2012 at 11:35 AM

Hi,

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.Delete()
	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
	Worksheet.Cells("A1").Style.Fill.BackgroundColor.SetColor(Color.Brown)
	Package.Save()
End Using
If i comment Worksheet.Cells("A1").Style.Fill.BackgroundColor.SetColor(Color.Brown) out, all worked fine.
Any ideas ?
[SOLVED]
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
Editor
Apr 13, 2012 at 12:33 PM
Edited Apr 13, 2012 at 12: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;
	        ws.Cells["A1"].Style.Fill.BackgroundColor.SetColor(Color.Brown);
	        p.Save();
            }

 

PS:

 

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