Solved

Creating a XLS in Classic ASP or VB6

Posted on 2009-04-08
10
1,533 Views
Last Modified: 2013-11-25
Hello,

Does anyone know how to create a .xls file in VB6 or Classic ASP without having Excel installed on the machine?

In addition, as these .xls files must be readable by Excel Viewer, which doesrn't read read HTML / MIME type files, so it must be true .xls files.

Thank you.
0
Comment
Question by:APD_Toronto
  • 4
  • 4
  • 2
10 Comments
 
LVL 4

Expert Comment

by:rentonc
Comment Utility
You can use filesystemobject to create a text file and name it with the extension .xls.
Fill the file with HTML tables and content, these will be viewable within Excel.
0
 
LVL 23

Assisted Solution

by:apresto
apresto earned 200 total points
Comment Utility
This is also known as a CSV. If you want an actual XLS file see here:
http://www.15seconds.com/Issue/970515.htm
Unless i have been away so long that i have missed something :) You will need an external COM component to achieve this,
0
 
LVL 4

Expert Comment

by:rentonc
Comment Utility
Yes Apresto, but this method outputs directly to page as an Excel file opened within the browser, not to an Excel file saved on the server. I use both methods in many systems.
0
 

Author Comment

by:APD_Toronto
Comment Utility
I need to deliver to the user a formatted xls sheet readable also by Excel Viewer.  So csv won't work, and Viewer doesnt read HTML.

How could I use OWC in ASP or VB6?  I have tried the code below in VB6 but I can't find the reference?

In HTML I placed it within <script> tage, it gives me ActiveX can't create object: 'owc.spreadshee'
Dim objS As Object

Set objS = CreateObject("owc.spreadsheet")
 

'Build Header

objS.cells(1, 1).Value = "Project"

objS.cells(1, 2).Value = "Tasks Completed"

objS.cells(1, 2).Value = "Last Status Date"
 

'Add a row of data

objS.cells(2, 1).Value = "MyProject"

objS.cells(2, 2).Value = "5/6" 'Want this to appear in the spreadsheet as a fraction.

objS.cells(2, 2).Value = "2006-05-11 10:21 am" 'Want this to appear as a date and time
 

'Save

objS.activesheet.Export "c:\temp.xls", 0

End Sub

Open in new window

0
 
LVL 23

Expert Comment

by:apresto
Comment Utility
Ah, i think it could be that owc isnt installed on this server. you can download it from here:
http://www.microsoft.com/downloads/details.aspx?FamilyID=982B0359-0A86-4FB2-A7EE-5F3A499515DD&displaylang=EN
 
 

Reference:

http://www.experts-exchange.com/Web_Development/Miscellaneous/Q_21683358.html?qid=21683358

Open in new window

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 4

Accepted Solution

by:
rentonc earned 300 total points
Comment Utility
Incorrect, the viewer will read the .xls file perfectly as I am using the very same system here.

Filesystemobject saves the .xls file (which is built up with tables) and the viewer reads it perfectly. This way you don't need to install OWC on the server.
0
 

Author Comment

by:APD_Toronto
Comment Utility
rentonc:

Are you sure, I have the code below.  The full Excel reads it, but Excel Viewer givse me "Microsoft Excel Viewer cannot open files of this  type".  I'm using Excel Viewer 2003 (11.8237.8221) SP3.

Please help?
<%@ Language=VBScript %>

   <%

      'Change HTML header to specify Excel's MIME content type

      Response.Buffer = TRUE

      Response.ContentType = "application/vnd.ms-excel"

      FPath = "c:\" & fn 

      Response.AddHeader "Content-Disposition", "attachment; filename=123.xls" 

 
 

   %>

   <html xmlns:o="urn:schemas-microsoft-com:office:office"

xmlns:x="urn:schemas-microsoft-com:office:excel"

xmlns="http://www.w3.org/TR/REC-html40">

   <head>

    <style>

 

  <!--table

 

  @page

     {mso-header-data:"&XX Day Absence Report\000ADate\: &D\000APage &P";

	  mso-number-format:"\#\,\#\#0\.00"; 

	  mso-page-orientation:landscape; }

 

  .style0

     {font-size:10.0pt;

	  font-style:normal;

	  font-family:Arial;}

 

  td

     {mso-style-parent:style0;

	  font-size:10.0pt;

	  font-style:normal;

	  font-family:Arial;}

 

  -->

 

	</style>

	

	<!--[if gte mso 9]><xml>

		 <x:ExcelWorkbook>

		  <x:ExcelWorksheets>

		   <x:ExcelWorksheet>

		    <x:Name>Book1</x:Name>

		    <x:WorksheetOptions>

		     <x:Print>

		      <x:ValidPrinterInfo/>

		      <x:HorizontalResolution>1200</x:HorizontalResolution>

		      <x:VerticalResolution>1200</x:VerticalResolution>

		     </x:Print>

		     <x:Selected/>

		     <x:DoNotDisplayGridlines/>

		     <x:ProtectContents>False</x:ProtectContents>

		     <x:ProtectObjects>False</x:ProtectObjects>

		     <x:ProtectScenarios>False</x:ProtectScenarios>

		    </x:WorksheetOptions>

		   </x:ExcelWorksheet>

		  </x:ExcelWorksheets>

		  <x:WindowHeight>15840</x:WindowHeight>

		  <x:WindowWidth>23835</x:WindowWidth>

		  <x:WindowTopX>0</x:WindowTopX>

		  <x:WindowTopY>15</x:WindowTopY>

		  <x:ProtectStructure>False</x:ProtectStructure>

		  <x:ProtectWindows>False</x:ProtectWindows>

		 </x:ExcelWorkbook>

		 <x:ExcelName>

		  <x:Name>Print_Titles</x:Name>

		  <x:SheetIndex>1</x:SheetIndex>

		  <x:Formula>=Book1!$A:$A,Book1!$1:$1</x:Formula>

		 </x:ExcelName>

		</xml><![endif]-->
 

	

   </head>

   <BODY>

   <!-- Our table which will be translated into an Excel spreadsheet -->

   <TABLE BORDER=1 CELLSPACING=1 CELLPADDING=1 border=1

			style="border-right-style: solid; border-right-width: 2;

        		   border-left-style: solid; border-left-width: 2;

        		   border-top-style: solid; border-left-width: 2;

        		   border-bottom-style: solid; border-left-width: 2">

 

  <tr><td WIDTH="145"> <b> # </b> </td> </tr>

 

 <% For i = 1 To 500 %>

 

	<tr><td> <%=i%> </td> </tr>
 

<% Next %>

   </TABLE>

   </BODY>

   </HTML>

	

Open in new window

0
 
LVL 4

Expert Comment

by:rentonc
Comment Utility
You have to save the file to disk first, currently you are streaming the content you create as a excel document type.

In its simplest for, if you saved a file called example.xls with the code below in it, it would open within the viewer.

Try it and let me know, because this works for me on our excel viewers
<Table>

<tr>

<th>Heeading 1</th>

<td>Result 1</td>

</tr>

</table>

Open in new window

0
 

Author Comment

by:APD_Toronto
Comment Utility
I copied your code in Notepad and saved as both as .htm and as .xls... Excel reads it, Viewer does not.  Same error.
Can you give me the link where you got your viewer?  Mine may be corrupt, but i did get it from microsoft.com?
0
 

Author Comment

by:APD_Toronto
Comment Utility
rentoc:
Which Version of Excel Viewer are you using?
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now