A fast Xlsx to Html file converter. Support cell fills, fonts, borders, alignments, and other styles. Support different cell sizes and merged cells. Support custom number formats and basic conditions. Support multiple sheets and hidden sheets. Support embedded pictures. Support progress callbacks. Only depend on the Microsoft Open Xml SDK.
DocumentFormat.OpenXml ≥ 3.0.0
- Cell fills, fonts, borders, alignments, and other styles
- Custom column widths and row heights
- Vertical and horizontal merged cells
- Number formats and basic conditional formats
- Sheet tab titles, colors, and hidden sheets
- Picture embeddings as Base64 images
- Conversion progress callback
Only one line to convert a Xlsx file to Html with the use of Stream
.
XlsxToHtmlConverter.Converter.ConvertXlsx(inputStream, outputStream);
Or to convert with specific ConverterConfig
and progress callback.
XlsxToHtmlConverter.Converter.ConvertXlsx(inputStream, outputStream, config, progressCallback);
Just use a string
of the path to the file instead of a Stream
to convert a local Xlsx file.
string filename = @"C:\path\to\file.xlsx";
XlsxToHtmlConverter.Converter.ConvertXlsx(filename, outputStream);
A third optional parameter can be set to decide whether to use a MemoryStream
or a FileStream
. When set to true
, a MemoryStream
is used to load the entire file at once instead of reading the file with a FileStream
.
Please note that using a
MemoryStream
will use up significantly more memory, especially for larger files.
XlsxToHtmlConverter.Converter.ConvertXlsx(filename, outputStream, true);
ConverterConfig
include flexible and customizable conversion configurations.
In rare cases where the converter is unable to produce the correct stylings, it is suggested to set
ConvertStyles
tofalse
, which will at least ensure the conversion of all the content with default stylings.
XlsxToHtmlConverter.ConverterConfig config = new XlsxToHtmlConverter.ConverterConfig()
{
PageTitle = "My Title",
PresetStyles = XlsxToHtmlConverter.ConverterConfig.DefaultPresetStyles + " body { background-color: skyblue; } table { width: 100%; }",
ErrorMessage = "An unhandled error occured during the conversion: {EXCEPTION}",
Encoding = System.Text.Encoding.UTF8,
BufferSize = 65536,
ConvertStyles = true,
ConvertSizes = true,
ConvertNumberFormats = true,
ConvertPictures = true,
ConvertShapes = true,
ConvertSheetTitles = true,
ConvertHiddenSheets = false,
ConvertFirstSheetOnly = false,
ConvertHtmlBodyOnly = false,
UseHtmlStyleClasses = true,
UseHexColors = true,
RoundingDigits = 2
};
A progress callback event can be set up with ConverterProgressCallbackEventArgs
, where things like ProgressPercent
can be used.
EventHandler<XlsxToHtmlConverter.ConverterProgressCallbackEventArgs> progressCallback = ConverterProgressCallback;
private static void ConverterProgressCallback(object sender, XlsxToHtmlConverter.ConverterProgressCallbackEventArgs e)
{
string info = string.Format("{0:##0.00}% (Sheet {1} of {2} | Row {3} of {4})", e.ProgressPercent, e.CurrentSheet, e.TotalSheets, e.CurrentRow, e.TotalRows);
string progress = new string('█', (int)(e.ProgressPercent / 2)) + new string('░', (int)((100 - e.ProgressPercent) / 2));
Console.WriteLine(info + new string(' ', 5) + progress);
}
This project is under the MIT License.