Wordpad opening an .xls file in html format? - excel

I got an .xls file from my friend. When I try to open that in excel it is opening fine. But when I try to open the same file in Wordpad it was showing the file contents using table tags like following:
<table border=1 cellspacing="0" cellpadding="0" width="580">
<style>
<!--table
.xl31
{mso-style-parent:style0;
mso-number-format:"\#";
text-align:left;
border-top:none;
border-right:.5pt solid black;
border-bottom:.5pt solid black;
border-left:none;
white-space:normal;}
-->
<tr><td> By _______________ </td><td colspan=2 > By ____________ </td></tr>
<tr><td>(Authorized Signature) </td><td colspan=2 > (Authorized Signature)</td></tr>
</table></th></tr>
</table>
But when I created an excel file using microsoft office-2003 and open it in Wordpad it is showing some junk data.
Could someone help me to find what could be the difference between these files?

It's common practice in many web apps out there to "cheat" a little and create Excel downloads by formatting data as an HTML table and sending it with a header describing the content as an Excel file. Excel will still render the data OK, thought it might complain that what was in the download didn't look like a real Excel file.
That's likely how your friend got that file. If you try it with an Excel file you created from Excel its either going to be binary (xls) or a zipped up set of XML files (2007+) so its not going to have any content you can read directly using Wordpad.

Related

ASP Classic - Excel file generate empty file

I have the file testeexcel.asp used to generate excel file in classic asp:
<%# Language=VBScript %>
<%
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
Response.ContentType = "application/vnd.ms-excel"
%>
<table>
<tr>
<td>Test</td>
</tr>
</table>
but when open in excel, the file is blank. If opened in notepad++, saved and reopened in excel the file works. See the link to test 104.41.63.35/testeexcel.asp
How to configure the file or IIS to resolve this problem?
Environment: Windows server 2012 - IIS 8.5
Marco - I have had success for the last several years with exporting from my Classic ASP to Excel using the setup you show -- but this week my clients have started reporting the same issue you describe although nothing about our application has changed. I have also been looking for an answer and I believe another poster may be correct pointing out that a recent Microsoft update is the culprit.
Opening excel files from the internet opens a blank excel window
I do not have the option to uninstall the update and have found that if I select to "save and open" instead of just "open" (and select "yes" to the prompt to 'open anyway?') my spreadsheet was displayed. Hope that helps!

Creating small image file png's showing tabular data from Excel or other spreadsheet

On: Creating small image file png's showing tabular data
We sometimes need to show data online. There are a couple of popular ways of doing this:
HTML table
JSON/Xml or other and using some method to display
Creating an image
In this case we need to (or prefer to) create PNG images. The method we use now is to create it in Excel and export it to PNG.
The problem is that we have seen is that these images are not really optimized. And don't look nice when zoomed in. Or on different displays.
Question: now what would be the best way of exporting table/tabular data from program X where we can store it (like Excel) to a clean and neat image format lik epNG that is safe for the web?
Advice and ideas appreciated
There is a quick and good solution for your need. It is wkhtmltopdf
It renders any web page or local html file and converts it image or pdf. Result is satisfactory. It has windows, linux, bsd, os x ports.
What is it?
wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line tools to render HTML into PDF and various image formats using the Qt WebKit rendering engine. These run entirely "headless" and do not require a display or display service.
There is also a C library, if you're into that kind of thing.
Usage is as easy as like this:
wkhtmltoimage.exe http://www.google.com output.png
Note: You can set the quality of the image from command line and have very small sized images with additional command line options.
For example this code becomes
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
</style>
</head>
<body>
<table style="width:100%">
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
</body>
</html>
this image (size 5.16 KB with --quality 80)
And this becomes
wkhtmltoimage.exe --quality 80 https://www.google.co.uk/webhp?hl=en output.png
this (size 32.7 KB)

Embedding Excel as an Image Object into Word Document. Coldfusion

Have anyone tried to embed excel as an image object to a word document using coldfusion? I have found no reference or tutorial to the question above so far on the internet. My code as of now does nothing to embed and would like someone who can share a link related to the question. Quick reference:
<!-- strPath is cffile.serverFile of cffile action="upload" -->
<cfset strpa = session.yo.path />
<cfif not structKeyExists(session, "yo")>
<cflocation url="form.cfm" addToken="false">
</cfif>
<head>
</head>
<body>
<CFOUTPUT>
Excel Table: </br>
<cfspreadsheet action="read" src="#GetTempDirectory()##strpa#" query="Result"> <cfdump var="#Result#"></br>
TextLabel: #session.yo.text# </br>
<!-- Embed Excel as Image Object to Word Document here?-->
</CFOUTPUT>
<a class="word-export" href="javascript:void(0)">Save As doc for the web page with wordexport.js lib </a>
</div>
<script src="js/FileSaver.js"></script>
<script src="js/jquery.wordexport.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
$("a.word-export").click(function(event) {
$("#page-content").wordExport();
});
});
</script>
</body>
Any help is much appreciated.
but the excel embedded in word document is not an image. It's a image
object to open the stored excel file
So your real goal is to embed an Excel file, not just an image of it, correct? If so, it is not possible with the plugin you are using. The reason is the plugin simply generates HTML code, which MS Word can interpret. You cannot embed Excel files within an HTML page. To embed a file, you need to generate a real Word document instead, which is not a trivial task.
If you are limited to HTML only, probably the closest you can get is to create a hyperlink to an Excel file. The link could point to a remote file on the server OR to a local file. For example, if you were to use <a href="ExcelFile.xls">, MS Word would attempt to open a file named "ExcelFile.xls", located in the same directory as your faux Word document.
Obviously that approach requires exporting both files. Since HTTP requests can only return a single mime type, you would need to create a zip file (containing both the HTML and Excel documents) and return the .zip file instead of .doc.

How can I download to Excel?

I'd like to go about offering a "download to excel" functionality for several different sets of data available on different parts of my coldfusion website. I'm using coldfusion and would love to use freely available custom tags / libraries that can help me accomplish this instead of coding it all myself from scratch. I've been pointed to cflib.org but am not sure how to get started. Anyone have any ideas, comments, or resources about downloading coldfusion website data to excel?
An approach that I have used in the past for an intranet with a load of tabular statistical data is to take advantage of the fact that Excel can read HTML.
On pages that I intend to provide Excel links for, I write out the core table as HTML to a file and include a link to that file in the rendered page. You can then serve this page with an .xls extension, use meta headers or even use an intermediary page with CFCONTENT in order to have your browser fire up Excel to display the content.
This approach can be extended for an arbitrary number of tables per page. You would have to write a tag to contain the table which will then take care of writing the file and supplying the download link for all HTML content contained within.
Sorry for the lack of example code. If my description of the process has left you scratching your head then I'll provide some examples for you.
You can also use an html table, as in:
<cfquery name="data" datasource="whatever">
...
</cfquery>
<cfheader name="Content-Disposition" value="inline; filename=fileName.xls">
<cfcontent type="application/x-msexcel" reset="true">
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td>Col1</td>
<td>Col2</td>
</tr>
</thead>
<tbody>
<cfoutput query="data">
<tr>
<td>#data.Col1#</td>
<td>#data.Col2#</td>
</tr>
</cfoutput>
</tbody>
</table>
hth,
larry
If you are on ColdFusion 9, you can always use cfspreadsheet:
http://www.cfquickdocs.com/cf9/#cfspreadsheet
http://help.adobe.com/en_US/ColdFusion/9.0/Developing/WS434C35B0-279B-4051-A61B-D84B5D76189C.html
Building on #Ciaran Archer's answer, I usually use CSV to accomplish this, which Excel will open up from the web if installed on a client's PC. Assuming the data you're working with is coming out of a database, use the QueryToCSV() from Ben Nadel's site as such:
<cfquery name="data" datasource="">
...
</cfquery>
<cfinclude template="fun_queryToCSV.cfm">
<cfheader name="Content-Disposition" value="filename=my-file-name.xls">
<cfcontent type="test/csv" reset="true">
<cfoutput>#querytoCSV(data)#</cfoutput>
The "reset" on cfcontent clears the response buffer so that the only thing inside of it is what comes after. Alternately, if you already have the data as file, cfcontent has a "file" attribute that will serve its contents up directly.
In the end, we used the Query2Excel function from cflib.org, and modified it slightly to suit our specific needs.
For those on Coldfusion 9+ and able to use cfspreadsheet, you can leverage SpreadsheetReadBinary() to make the spreadsheet downloadable without having to write the spreadsheet to a file first.

How to output an Excel *.xls file from classic ASP

I have a number of generated html tables that I need to output as an Excel file. The site is codded in classic ASP. Is this possible? Could it be done by somehow using the Open Office libraries?
EDIT: Thus far, I have tried some of the suggestions, but it seems to fail. Ideally, I want the user to be able to click a link that will begin the download of a .xls file. This code:
<%# Language=VBScript %>
<% option explicit
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader "content-disposition", " filename=excelTest.xls"
%>
<table>
<tr>
<th>Test Col 1</th>
<th>Test Col 2</th>
<th>Test Col 3</th>
<th colspan="2">Test Col 4</th>
<th>Test Col 6</th>
<th>Test Col 7</th>
</tr>
<tr>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
<td>Data</td>
</tr>
</table>
seems to fail when IE7 is used to get the page. IE says that it "cannot download excelTest.asp" and that "The requested site is either unavailable or cannot be found."
It's AddHeader, not AppendHeader.
<%# Language=VBScript %>
<% Option Explicit
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
%>
<table>
<tr>
<td>Test</td>
</tr>
</table>
Update:
I've written a blog post about how to generate Excel files in ASP Classic. It contains a rather useful piece of code to generate both xls and csv files.
MS made a COM library called Office Web Components to do this. MSOWC.dll needs to be registered on the server. It can create and manipulate office document files.
How To Use the Spreadsheet Web Component with Visual Basic
Working with the Office Web Components
There's a 'cheap and dirty' trick that I have used... shhhh don't tell anyone. If you output tab delimited text and make the file name *.xls then Excel opens it without objection, question or warning. So just crank the data out into a text file with tab delimitation and you can open it with Excel or Open Office.
You must specify the file to be downloaded (attachment) by the client in the http header:
Response.ContentType = "application/vnd.ms-excel"
Response.AppendHeader "content-disposition", "attachment: filename=excelTest.xls"
http://classicasp.aspfaq.com/general/how-do-i-prompt-a-save-as-dialog-for-an-accepted-mime-type.html
You can always just export the HTML table to an XLS document. Excel does a pretty good job understanding HTML tables.
Another possiblitly is to export the HTML tables as a CSV or TSV file, but you would need to setup the formatting in your code. This isn't too difficult to accomplish.
There's some classes in the Microsoft.Office.Interop that allow you to create an Excel file programatically, but I have always found them to be a little clumsy. You can find a .NET version of creating a spreadsheet here, which should be pretty easy to modify for classic ASP.
As for .NET, I've always liked CarlosAG's Excel XML Writer Library. It has a nice generator so you can setup your Excel file, save it as an XML spreadsheet and it generates the code to do all the formatting and everything. I know it's not classic ASP, but I thought that I would throw it out there.
With what you're trying above, try adding the header:
"Content-Disposition", "attachment; filename=excelTest.xls"
See if that works. Also, I always use this for the content type:
Response.ContentType = "application/octet-stream"
Response.ContentType = "application/vnd.ms-excel"
I had the same issue until I added Response.Buffer = False. Try changing the code to the following.
Response.Buffer = False
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader "Content-Disposition", "attachment; filename=excelTest.xls"
The only problem I have now is that when Excel opens the file I get the following message.
The file you are trying to open, 'FileName[1].xls', is in a different format than specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now?
When you open the file the data all appears in separate columns, but the spreadsheet is all white, no borders between the cells.
Hope that helps.
the XLS file is not a real Excel file. The code create an HTML file with .an xls extension. When you try open the XLS file with Notepad, you can see the HTML code.

Resources