How to convert Excel file to HTML

Hi,

I have an excel which needs to be saved as HTML file. I tried in general way to send hotkeys and save it as HTML, but after automating everything correctly, in the end Bot is still saving the file as Excel only. Because in Save as Window, Bot is giving the file name and selecting the Type as html but after clicking the the save button, the type is automatically getting changed to Excel again. is there any other alternatives to change the excel file to html file? I tried invoke code using the following code, but it didn’t work

using Spire.Xls;

namespace XLSToHTML

{
class Program
{
static void Main(string args)
{
//Create a Workbook instance
Workbook workbook = new Workbook();

        //Load an Excel sample document
        workbook.LoadFromFile(@"sample.xlsx");

        //Get the first worksheet of the document 
        Worksheet sheet = workbook.Worksheets[0];
       
        //Save the worksheet to HTML
        sheet.SaveToHtml("ExcelToHTML.html");
    }
}

}

it is showing the error as closing } is needed although everything seems to be working in VB Studio. Can anyone please resolve this issue?

TIA

If you are sure that the contents of your excel would be readable as html, I guess you can try just letting the bot save it as an excel and then just add a sequence to rename the file from ExcelFile.xlsx to ExcelFile.html
Have not tried if, but I think it might work.

I have tried it, but when Bot is saving it with HTML extension, it’s still saving it as Sample.html.xlsx

Hi,

Try this workflow below
DataTableToHtmlText.xaml (14.5 KB)

1 Like

Hi, Thanks for the code but there is a small thing missing, I am not getting Colomn Names from the excel file. can you update the code with adding colomn names as well when converting to HTML file?

Hi,

No need to update the code un-mark has headers property in read range

1 Like

Thanks for solving this, can you tell me why this code is not working?

I used invoke Code activity: C#( this worked fine in VB studio)

// Create an instance of the class used to import/export Excel files
ExcelDocument workbook = new ExcelDocument();

// Import Excel file
workbook.easy_LoadXLSXFile(“C:\Samples\file.xlsx”);

// Export HTML file
workbook.easy_WriteHTMLFile(“C:\Samples\Excel to HTML.html”);

or VB.Net

// Create an instance of the class used to import/export Excel files
ExcelDocument workbook = new ExcelDocument();

// Import Excel file
workbook.easy_LoadXLSXFile("C:\\Samples\\file.xlsx");

// Export HTML file
workbook.easy_WriteHTMLFile("C:\\Samples\\Excel to HTML.html");

Well,
I’m not sure why this is not working may try saving this as text file then convert to html. and invoke code might have some limitations

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.