html to excel

Convert HTML to Excel workbook using C# .NET.

The HTML tables are commonly used to present structured data on web pages, but when it comes to deeper analysis, Excel’s robust features and functionalities shine. Therefore, by converting HTML to Excel with C# .NET, you gain access to Excel’s powerful tools for data manipulation, visualization, and collaboration. With this conversion, you unlock deeper insights, make informed decisions, and streamline document workflows.

In this article, we are going to explore the details on empowering users to leverage the full potential of HTML to Excel conversion using .NET REST API.

REST API for HTML to Excel Conversion

The conversion of HTML to Excel seamlessly is made possible with the robust capabilities of GroupDocs.Conversion Cloud SDK for .NET. The SDK supports a wide range of HTML formats and enables precise customization options, such as specifying column widths, adjusting cell formatting, and handling complex table structures with ease. Also, the SDK ensures high-fidelity conversions, delivering accurate and reliable results every time.

Firstly, we need to install the SDK by searching GroupDocs.Conversion-Cloud in NuGet package manager and click the Install button. Another option is to execute the following command in package manager console.

NuGet\Install-Package GroupDocs.Conversion-Cloud -Version 24.2.0

After the installation, please make sure you have obtained your personalized API credentials(i.e. Client ID and Client Secret). You may visit this short tutorial explaining the details on how to get the API credentials.

Convert HTML to Excel in C# .NET

Let’s explore the details on how this SDK simplifies the HTML to Excel conversion workflows, while maintaining data integrity and quality.

  1. Create an instance of Configuration class where we pass client credentials as arguments.
var configurations = new Configuration(clientId, clientSecret1);
  1. Initialize the ConvertApi where we pass Configuration object as an input argument.
var apiInstance = new ConvertApi(configurations);
  1. Upload the input HTML file to the cloud storage.
fileUpload.UploadFile(new UploadFileRequest("sourceFile.html", stream));
  1. Create an instance ConvertSettings where we specify the name for input HTML, resultant format as xls and the name for resultant Excel workbook as arguments.
var settings = new ConvertSettings{...}
  1. Call the ConvertDocumentRequest API to export HTML to Excel and save the resultant XLS to the cloud storage.
var response = apiInstance.ConvertDocument(new ConvertDocumentRequest(settings));
html to excel

Image:- Preview of HTML to Excel conversion.

The resultant Excel workbook generated in above example can be downloaded from resultant.xls.

Convert Web to Excel using cURL commands

Achieving the conversion of a web page to Excel format becomes straightforward with the integration of GroupDocs.Conversion Cloud and cURL commands. This efficient approach empowers you to seamlessly transform web page content into Excel spreadsheets with minimal effort. So, by utilizing cURL commands in conjunction with GroupDocs.Conversion Cloud, you can initiate the conversion process directly from the command line interface and streamline the entire workflow.

Once we have generated the JWT token based on personalized credentials, please execute the following cURL command to download the webpage as Excel format and save the resultant Excel worksheet in cloud storage.

curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-X POST \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"internal\",  \"FilePath\": \"{sourceFile}\",  \"Format\": \"xlsx\",  \"LoadOptions\": {    \"Format\": \"html\"  },  \"OutputPath\": \"{convertedFile}\"}"

Please replace sourceFile with the name of input HTML page, convertedFile with the name of resultant Excel workbook and accessToken with personalized JWT access token.

  • If you want to save the resultant file on local drive, please try using the following cURL command.
curl -v "https://api.groupdocs.cloud/v2.0/conversion" \
-H "accept: application/json" \
-H "authorization: Bearer {accessToken}" \
-H "Content-Type: application/json" \
-d "{  \"StorageName\": \"internal\",  \"FilePath\": \"{sourceFile}\",  \"Format\": \"xls\",  \"LoadOptions\": {    \"Format\": \"html\"  }}" \
-o "Converted.xls"

Download Webpage as Excel

You may also consider downloading the web page as Excel format using our free HTML to Excel Converter. This lightweight and super-efficient App is developed on top of GroupDocs.Conversion Cloud REST APIs and enables you to witness the amazing capabilities of our REST API.

html to excel app

Conclusion

In conclusion, whether you opt for GroupDocs.Conversion Cloud SDK for .NET or leverage cURL commands with GroupDocs.Conversion Cloud, both approaches offer efficient and reliable solutions for converting HTML to Excel format. Therefore, we encourage you to leverage the capabilities of GroupDocs.Conversion Cloud for HTML to Excel conversion, to streamline workflows and unlock the full potential of your data.

We highly recommend visiting the following links to learn more about: