Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Exporting Excel to HTML

Posted on 2005-04-12
9
Medium Priority
?
377 Views
Last Modified: 2010-04-05
How can I export Excel file (all worksheets) to an HTML file from Delphi using Excel's COM? I want them to be saved in the same way as the "Save As" menu option does. It makes DHTML tabs for all worksheets in the output HTML file. Plz give me some working sample.

Thanks.
0
Comment
Question by:m_adil
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 17

Assisted Solution

by:geobul
geobul earned 90 total points
ID: 13764521
Hi,

Try this:

  YourExcelApplication.ActiveWorkbook.SaveAs(FileName:= 'c:\ExcelExport.html', FileFormat := 44);

Replace:
  - YourExcelApplication with the name of your variable
  - 'c:\ExcelExport.html' with the filename you want.

Regards, Geo
0
 
LVL 1

Author Comment

by:m_adil
ID: 13764679
but this will export only active worksheet. plz read the question again. I wrote, I want to export "all worksheets". So all worksheets that contain any data should be exported.

0
 
LVL 3

Accepted Solution

by:
Octabun earned 285 total points
ID: 13765271
Try to record what you want to do as a macro and then do the same in Delphi. To get the value of constants, just assign them to a cell in a macro.

With Office 2003 the result is

{
    Workbooks.Open Filename:= _
        "D:\Documents\Borland Studio Projects\UseExcel\Book1.xls"
    ActiveWorkbook.SaveAs Filename:= _
        "D:\Documents\Borland Studio Projects\UseExcel\Book1.htm", FileFormat:=xlHtml _
        , ReadOnlyRecommended:=False, CreateBackup:=False
}

procedure TForm1.FormClick(Sender: TObject);
var
  ex: olevariant;
begin
  ex := CreateOleObject('Excel.Application');
  ex.Workbooks.Open('D:\Documents\Borland Studio Projects\UseExcel\Book1.xls');
  ex.ActiveWorkbook.SaveAs(Filename := 'D:\Documents\Borland Studio Projects\UseExcel\test.htm',
      FileFormat := 44, ReadOnlyRecommended := False, CreateBackup := False);
  ex.ActiveWorkbook.Close;
end;

It works for me exactly as you want. So, the only way it can fail for you is that your office is not 2003 so that your recorded macro would be different.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 17

Expert Comment

by:geobul
ID: 13765286
Just try it. It will export the workbook not the current sheet only.

Regards, Geo
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13765290
"but this will export only active worksheet"

You have to loop through the worksheets of the workbook and save each one as
HTML using code provided above.
0
 
LVL 17

Expert Comment

by:geobul
ID: 13765315
Open the exported html file with InternetExplorer and you'll see the tabs at the bottom-left side of the page. If your current workbook contains one worksheet only then there won't be any tab there.
0
 
LVL 1

Author Comment

by:m_adil
ID: 13766373
yes it works perfect in office 2003. but what about office 2000? will it work with office 2000 in the same way?
0
 
LVL 3

Expert Comment

by:Octabun
ID: 13769446
You need to get to Office 2000 and record the macro there. I do not have Office 2000, so I cannot help. Most likely, it will work exactly as Save As invoked interactively, that is, if Office 2000 saves all worksheets, it will save them all too.

The  "ReadOnlyRecommended:=False, CreateBackup:=False" part recorder by Office 2003 looks optional, so if Office 2000 does not record that, you may drop it.
0
 
LVL 1

Author Comment

by:m_adil
ID: 13770036
it is working in office 2000 as well - thanks!

now how to grade points? I think both Geo and Octabun comeup with the same solution. how abt if i split and give 75% to Octabun and 25% to Geo as Octabun's code looks more comprehensive.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…
Suggested Courses

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question