在使用方法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)’‘
发布于 2019-06-15 21:14:12
我已经运行了你的代码,没有看到任何错误
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)
{
}
}https://stackoverflow.com/questions/56610484
复制相似问题