简体   繁体   English

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

[英]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当使用方法 object.Fill.SetPattern(...) 尝试将一些背景颜色应用于使用 Spreadsheetlight 创建的 excel 文件时,抛出 MissingMethodException,我无法理解原因

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.我希望 Excel 文件中的第一行范围 A1:Z1 具有一些背景颜色。

Below is the exception:以下是例外:

System.MissingMethodException: 'Method not found: 'Void SpreadsheetLight.SLFill.SetPattern(DocumentFormat.OpenXml.Spreadsheet.PatternValues, SpreadsheetLight.SLThemeColorIndexValues, SpreadsheetLight.SLThemeColorIndexValues)'.' System.MissingMethodException: '找不到方法:'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)
        {

        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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