繁体   English   中英

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

[英]Missing method exception when using Spreadsheetlight.SLFill.SetPattern

当使用方法 object.Fill.SetPattern(...) 尝试将一些背景颜色应用于使用 Spreadsheetlight 创建的 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: '找不到方法:'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)
        {

        }
}

暂无
暂无

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

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