[英]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.