I have a document xls
and another xlsx
already saved in bytes[]
my code and I need to pass it to html+css
so I can display it on a page.
It is important to note that I also need the css
and that means that reading each row individually from the excel is not an option since it would lose the style.
I am using Visual Studio with .NET to develop it in C# .
Currently it works for me from pdf that is easy to transform to html but this is not the case with xls
, xlsx
nor any Microsoft product since I cannot use the native library interop
since it is not a guarantee that the server has it installed.
The result would be something similar to this:
strFinalXls = strFinalXls.Replace("<body>", "<body>" + documentInfoHtml + "<BR /><BR />");
Where documentInfoHtml
is the result of transforming them bytes[]
to html and strFinalXls
is simply the content that replaces that body
of a page.
I have found a solution but practically all interop
of them use either paid libraries.
Do you know any way to do it with free software or open projects?
It is also important to keep the existing CSS styles as much as possible, so answers that simply extract the content to generate it myself HTML
is not enough in the sense that it would lose all the formatting.
From the NPOI library for C# (downloaded from github, NOT from the Nuget, since the Nuget is missing some DLLs):
Main Code - Important to note that an XLS is different from an XLSX (it is marked in the code)
The functions
ReadFully
,ConvertDocumentToHtmlMemoryStream
andBytesToStringConverted
:ReadFully - Transform a
Stream
tobyte[]
:ConvertDocumentToHtmlMemoryStream - Add information for your generation to HTML
BytesToStringConverted - Convert from
byte[]
tostring