C# 使用Spreadsheetlight.SLFill.SetPattern时缺少方法异常

C# 使用Spreadsheetlight.SLFill.SetPattern时缺少方法异常,c#,spreadsheetlight,C#,Spreadsheetlight,当使用object.Fill.SetPattern(…)方法尝试将背景颜色应用于正在使用电子表格灯创建的excel文件时,会引发MissingMethodException,我无法理解其原因 我试图在开发人员文档中查找可能出现的问题,但找不到解决方案 using (SLDocument sl = new SLDocument()) { sl.ImportDataTable("A1", dataTable, true); var s

当使用object.Fill.SetPattern(…)方法尝试将背景颜色应用于正在使用电子表格灯创建的excel文件时,会引发MissingMethodException,我无法理解其原因

我试图在开发人员文档中查找可能出现的问题,但找不到解决方案

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);
        }
我希望excel文件中的第一行(范围A1:Z1)有一些背景色

以下是例外情况:


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

我已经运行了您的代码,在这里没有看到任何错误

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

        }
}

你能发布完整的异常详细信息吗?我现在把它添加到了帖子中。你能试着把代码放在一个方法里面吗,这个方法的参数是datatable?我现在尝试在这个类中使用另一个方法,叫做“SetGradient”,它确实有效。显然,程序无法找到“SetPattern”方法。我不知道为什么我更新了答案,将代码包含在方法中。