-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ExcelToHtmlConverter.ProcessWorkbook throws Illegal IndexedColor index: 0 error on .NET Core 3.1 #621
Comments
Can you provide the Excel file? |
The sample has been uploaded. |
The exception thrown by IndexedColor.ValueOf() method. In some cases, the color value=0. But there is no pre-defined color whose index equals 0. |
Hi, Is there any way to avoid this exception? |
Here is a simple workaround :
But a real fix is still very welcome |
Thanks for the "fix", @PhenX. In my case I needed white instead of black, so it seems the color is not fixed, but you lead me on the right track. :) |
以下代码在.net framework中可顺利执行,但在core 3.1下2.5.4版本报错:Illegal IndexedColor index: 0;
` ///
/// (NPOI)Excel转HTML
///
/// HTML文件的的名称(不带后缀)
/// 需要转换Excel的绝对路径
///
public string ExcelToHtml(string Filename)
{
IWorkbook workbook;
//获取后缀名称
string fileExt = Path.GetExtension(Filename).ToLower();
//判断是否可以打开该文件,如果出错则文件已经打开或者有异常
try
{
System.IO.FileStream stream = System.IO.File.OpenWrite(Filename);
stream.Close();
}
catch
{
return null;
}
using (FileStream fs = new FileStream(Filename, FileMode.Open, FileAccess.Read))
{
//如果是XLSX格式选择XSSFWorkbook ,如果是XLS格式选择HSSFWorkbook
if (fileExt == ".xlsx") { workbook = new XSSFWorkbook(fs); } else if (fileExt == ".xls") { workbook = new HSSFWorkbook(fs); } else { workbook = null; }
if (workbook == null) { return null; }
}
以下是Excel样例。
simple.xlsx
The text was updated successfully, but these errors were encountered: