Skip to content

A fast, versatile, and powerful XLSX to HTML converter. Support an extensive scope of cell stylings and additional elements. Empower the efficient transformation of spreadsheets into well-structured web documents. Provide the ability to easily customize every aspect of the conversion process with progress callbacks. Only depend on the Open XML SDK.

License

Notifications You must be signed in to change notification settings

Fei-Sheng-Wu/XlsxToHtmlConverter

Repository files navigation

XlsxToHtmlConverter v2.1.0

Language .NET .NET Standard NuGet Downloads Commits Since License

A fast, versatile, and powerful XLSX to HTML converter. Support an extensive scope of cell stylings and additional elements. Empower the efficient transformation of spreadsheets into well-structured web documents. Provide the ability to easily customize every aspect of the conversion process with progress callbacks. Only depend on the Open XML SDK.

Dependencies

Features

  • Cell structures, sizes, fonts, fills, borders, alignments, and visibilities
  • Content presentation with number formats and basic conditional formats
  • Elements of pictures and shapes with responsive positioning
  • HTML construction with configurable details and modernized organization
Original XLSX File
Original XLSX File
Converted HTML File
Converted HTML File

Versioning

For versions ≥ 2.0.0, the versioning of XlsxToHtmlConverter conforms to the following scheme:

Generation Major Minor
2 . 1 . 0
(backward-incompatible) (backward-incompatible) (backward-compatible)
Significant codebase refactors. Severe bug fixes and core improvements. Mild changes.

The changelogs are available at the Releases.

How to Use

Only one line to convert a local XLSX file to HTML:

XlsxToHtmlConverter.Converter.Convert(@"C:\path\to\input.xlsx", @"C:\path\to\output.html");

Similarly, the use of Stream is supported:

Stream input = ...;
Stream output = ...;
XlsxToHtmlConverter.Converter.Convert(input, output);

Alternatively, the input may also be a DocumentFormat.OpenXml.Packaging.SpreadsheetDocument instance:

using DocumentFormat.OpenXml.Packaging;
SpreadsheetDocument input = ...;
Stream output = ...;
XlsxToHtmlConverter.Converter.Convert(input, output);

Conversion Configuration

A third optional parameter can be set to configure the conversion process:

XlsxToHtmlConverter.ConverterConfiguration configuration = new()
{
    BufferSize = 65536,
    Encoding = Encoding.UTF8,
    NewlineCharacter = "\n",
    TabCharacter = new(' ', 2),
    RoundingDigits = 2,
    CurrentCulture = CultureInfo.CurrentCulture,
    HtmlTitle = null,
    HtmlPresetStylesheet = ...,
    XlsxSheetSelector = null,
    ConvertSheetTitles = true,
    ConvertSizes = true,
    ConvertVisibilities = true,
    ConvertStyles = true,
    ConvertNumberFormats = true,
    ConvertPictures = true,
    ConvertShapes = true,
    UseHtmlFragment = false,
    UseHtmlClasses = true,
    UseHtmlHexColors = true,
    UseHtmlProportionalWidths = true,
    UseHtmlDataElements = true,
    ...
};
XlsxToHtmlConverter.Converter.Convert(..., ..., configuration);

Progress Callback

A fourth optional parameter can be set to add a progress callback event handler:

XlsxToHtmlConverter.Converter.Convert(..., ..., ..., HandleProgressChanged);
private void HandleProgressChanged(DocumentFormat.OpenXml.Packaging.SpreadsheetDocument? sender, XlsxToHtmlConverter.ConverterProgressChangedEventArgs e)
{
    string summary = $"Sheet {e.CurrentSheet} of {e.SheetCount} | Row {e.CurrentRow} of {e.RowCount}";
    string progress = new string('█', (int)Math.Round(e.ProgressPercentage / 100.0 * 50)).PadRight(50, '░');
    Console.Write($"{e.ProgressPercentage:F2}% ({summary}) {progress}");
}

License

This project is under the MIT License.

About

A fast, versatile, and powerful XLSX to HTML converter. Support an extensive scope of cell stylings and additional elements. Empower the efficient transformation of spreadsheets into well-structured web documents. Provide the ability to easily customize every aspect of the conversion process with progress callbacks. Only depend on the Open XML SDK.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Contributors 3

  •  
  •  
  •  

Languages