Missing method exception when using Spreadsheetlight.SLFill.SetPattern

634 Views Asked by At

When using the method object.Fill.SetPattern(...) to tried to apply some background colour to an excel file that is being created with Spreadsheetlight, an MissingMethodException is thrown, which I can't understand the reason

I tried to look up in the developer documentation for possible problems but I couldn't find the solution

using (SLDocument sl = new SLDocument())
        {
            sl.ImportDataTable("A1", dataTable, true);

            var style = sl.CreateStyle();
            style.Fill.SetPattern(PatternValues.Solid, SLThemeColorIndexValues.Accent2Color, SLThemeColorIndexValues.Accent4Color);

            sl.SetCellStyle("A1:Z1", style);

            sl.SaveAs(fileName);
        }

I expect the first row in the excel file, range A1:Z1, to be have some background colour.

Below is the exception:

System.MissingMethodException: 'Method not found: 'Void SpreadsheetLight.SLFill.SetPattern(DocumentFormat.OpenXml.Spreadsheet.PatternValues, SpreadsheetLight.SLThemeColorIndexValues, SpreadsheetLight.SLThemeColorIndexValues)'.'

1

There are 1 best solutions below

2
Jake Steffen On

I have ran your code and don't see any errors here is what I have

public void CreateDocument(DataTable dataTable )
{
   try
        {
            dataTable.Clear();
            dataTable.Columns.Add("Name");
            dataTable.Columns.Add("Marks");
            DataRow _ravi = dataTable.NewRow();
            _ravi["Name"] = "ravi";
            _ravi["Marks"] = "500";
            dataTable.Rows.Add(_ravi);

            using (SLDocument sl = new SLDocument())
            {                  
                sl.ImportDataTable("A1", dataTable, true);

                var style = sl.CreateStyle();
                //PatternValues.Solid, 
                style.Fill.SetPattern(PatternValues.Solid, SLThemeColorIndexValues.Accent2Color, SLThemeColorIndexValues.Accent4Color);


                sl.SetCellStyle("A1:Z1", style);



                sl.SaveAs("Test.xlsx");
            }
        }
        catch (MissingMethodException ex)
        {

        }
}