nissl-lab / npoi

a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop.
Apache License 2.0
5.65k stars 1.42k forks source link

ExcelToHtmlConverter dont assign class to tr tag #1381

Closed batyadmx closed 1 day ago

batyadmx commented 1 month ago

NPOI Version

2.7.1

File Type

xlsx

Upload the Excel File

XLSX file: pepa.xlsx

Html result: pepa.txt

Reproduce Steps

Here's the code

System.Globalization.CultureInfo customCulture = (System.Globalization.CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
customCulture.NumberFormat.NumberDecimalSeparator = ".";

Thread.CurrentThread.CurrentCulture = customCulture;

(typeof(IndexedColors).GetField("mappingIndex", BindingFlags.Static | BindingFlags.NonPublic)
   .GetValue(null) as Dictionary<int, IndexedColors>)[0] = IndexedColors.Black;
var workbook = new XSSFWorkbook("pepa.xlsx");

var converter = new ExcelToHtmlConverter();
converter.OutputColumnHeaders = false;
converter.OutputRowNumbers = false;

converter.ProcessWorkbook(workbook);

converter.Document.Save("pepa.html");

Issue Description

After convertion html code contains styles for table rows, but tr tags dont have assigned classes.

wuzxc1230123 commented 1 day ago

@batyadmx HtmlDocumentFacade is erro public void AddStyleClass(XmlElement element, string classNamePrefix, string style) { string exising = element.GetAttribute("class"); string addition = GetOrCreateCssClass(element.Name, classNamePrefix, style); string newClassValue = string.IsNullOrEmpty(exising) ? addition : (exising + " " + addition); element.SetAttribute("class", newClassValue); }

update ` public void AddStyleClass(XmlElement element, string classNamePrefix, string style) { string exising = element.GetAttribute("class"); string addition = GetOrCreateCssClass(element.Name, classNamePrefix, style); string newClassValue = string.IsNullOrEmpty(exising) ? addition : (exising + " " + addition);

    element.SetAttribute("class", newClassValue);
}

`