0

I've researched for days but I can not find anything to resolve this issue that I am having.

I have an excel file in .xlsx format that is updated through out the day. What I need to do is call a batch that converts it to .html. I will be taking that HTML file and copying it to a folder that automatically publishes it for internal uses at my company.

If anyone out there can help it would be greatly appreciated.

2 Answers 2

5

Excel lets you save as a web page natively. It also has a "single file" web page that combines all images/etc into a single file. It uses the mht or mhtml extension.

Const xlHtml = 44
Const xlWebArchive = 45

' Create an instance of Excel and open the workbook...
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Open "C:\Folder\MyWorkbook.xlsx"

' Save the workbook as an HTML or MHTML page...
objExcel.ActiveWorkbook.SaveAs "C:\Folder\MyPage.html",  xlHtml
' -or-
objExcel.ActiveWorkbook.SaveAs "C:\Folder\MyPage.mhtml", xlWebArchive

' Close Excel...
objExcel.Quit
Sign up to request clarification or add additional context in comments.

2 Comments

So trying to implement this into something production related at work and we are seeing the folder that this also creates with the stylesheet.css file and everything else the HTML file calls. Is there a way for just a straight HTML file that doesn't need all of the other stuff?
Did you try using the xlWebArchive type with the mht or mhtml extension like I showed?
2

If Some one looking for C#

Add Reference -> COM -> Look for Microsoft Excel, Microsoft Office then

using Excel = Microsoft.Office.Interop.Excel;

namespace ExcelToSinglePageWeb
{
    class Program
    {
        static void Main(string[] args)
        {
            Excel.Application xlApp = new Excel.Application();
            Excel.Workbook xlWorkbook = xlApp.Workbooks.Open(@"C:\Users\name\Desktop\Work In Progress.xlsx");
            xlWorkbook.SaveAs(@"C:\Users\name\Desktop\SomePage.mhtml", 45);
            xlApp.Quit();
        }
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.