简体   繁体   中英

Missing method exception when using Spreadsheetlight.SLFill.SetPattern

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)'.'

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)
        {

        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM