views:

118

answers:

4

I have generated a html table from my web application and save the table into .xls format(in a single word i am generating a .xls sheet from my web application ). But when i open that file in open office it shows the following thing (see the url)

http://yfrog.com/jy390pj

What other setting i have to show it in table form.

+2  A: 

It's not really saving as a .xls file -- it appears to be saving as the HTML, but with a .xls extension. How are you generating the .xls? On the server-side, you can provide a button to generate .xls directly (different methods depending on your server platform -- using perl there is the Spreadsheet::WriteExcel module that writes .xls directly, using Java there is JExcel (http://jexcelapi.sourceforge.net/ and POI (http://poi.apache.org/)), other platforms will have their methods.

jsegal
Actually you don't got my point what i am asking.I have generated a .Xls file my web application it is opening fine in open office on my machine.But on other machine a prompt is coming (whose snapshot i have shared).So basically i want to know about the what other setting i will have to do to open up that file on another machine.
subodh
+1  A: 

Okay Subodh, If you want to generate .xls or .csv files, You can't just change the extension of the file and have it open up correctly in that program.

2 Options you have at this point, both involve creating the file with the data on the server and then sending it to the user to download it.

.csv
CSV files are easier to generate from the server side. In a very basic way you can think of them as regular text files with commas(not necessarily only commas) separating individual cells that can be read by spreadsheet programs. For PHP there is an article Here that explains how to generate CSV files.

.xls
xls files are not as simple as simple to generate as CSV files. On the server-side you will need a solution to generate these. For PHP there is a resource Here.

Using xls over CSV has obvious advantage that you can specify formatting and can control visual representation of your data.


Edit : Upon closely looking at the image you posted, I can see what you are trying to do. If you just want to get that file to open correctly in a spreadsheet program, then don't save it either as CSV or xls

hello.html

<table>
<tr><td>Hi</td><td>Hi</td><td>Hi</td><td>Hi</td></tr>
<tr><td>2</td><td>2</td><td>131</td><td>11312</td></tr>
</table>

Saved as an HTML file will open up correctly(as a proper table) in any spreadsheet program.

DMin
Actually you don't got my point what i am asking.I have generated a .Xls file my web application it is opening fine in open office on my machine.But on other machine a prompt is coming (whose snapshot i have shared).So basically i want to know about the what other setting i will have to do to open up that file on another machine.
subodh
I am pretty sure that file that you were trying to import in that screenshot is not an excel file. I am sure, if you open that file in notepad, it will open up as well. It seems like a regular HTML file. An excel file will never have <table><strong><td> tags. try saving an excel file on your pc and open that in notepad, then try opening this in notepad you will see the difference. As far as I can see your server is not generating an xls file.
DMin
One thing I would try is this. The file that you have on your PC that got generated from the server. Change the extension of that file from xls to html and then open that file from open office or excel. tell me if you are able to see a proper table.
DMin
+8  A: 

You are not producing an XLS file, you are producing a mal-formed HTML file with a name that ends in .xls.

Indeed, you aren't even doing that since there aren't files on the web (there are streams that may or may not end up in files).

Different versions of Open Office, with different settings, will differ in terms of how they deal with stuff that is wrong. The version on one of the machines you are doing is saying "eh, this isn't XLS, oh! it's HTML with a table, I know what to do", while the other is getting as far as "eh, this isn't XLS, it's a bunch of text with strange less-than and greater-than characters all over the place, what do I do".

What you want to do is to produce an actual stream that Open Office and other spreadsheets can deal with. XLS is possible, but pretty hard. Go for CSV instead.

If your table was going to be:

<table>
 <tr>
  <th>1 heading</th><th>2 &amp; last heading</th>
 </tr>
 <tr>
  <td>1st cell</td><td>This is the "ultimate" cell</td>
 </tr>
</table>

Then it sould become:

"1 heading","2 & last heading"
"1st cell","This is the ""ultimate"" cell"

In otherwords newlines to indicate rows, commas to indicate cells, no HTML encoding, quotes around everything and quotes in your actual content doubled-up. (You don't need to always have quotes on your content, but it's never wrong so that's simpler than working out when you do need them).

Now, make your content type "text/csv".

You are now outputting a CSV stream that can be saved as a CSV file. Your spreadsheet software will have a much better idea about what to do with this (it may still ask about character ecodings on opening, but the preview will show you a spreadsheet of data, not a bunch of HTML source all over the place.

Jon Hanna
the problem is that if the file is not named XLS, than Open Office or Excel will not be started automatickly to load it.
Ian Ringrose
@Ian there's nothing to say it shouldn't be a file named something.xls, though with the above use of the simpler text/csv format something.csv would be more common, and will open Calc or Excel by default (i.e. unless something else was set to open it).
Jon Hanna
A: 

To narrow down the problem:

1) Are you opening the same .xls file on both machines? - what version of OpenOffice is on Machine 1? - what version of OpenOffice is on Machine 2?

2) How are you creating your .xls file? - are you just using the response object to change the content-type, or some proprietary software? - can you include a code sample?

3) Have you tried a pure HTML format?

dave
1.Yes i am opening same .xls in both machine2.I am creating the xls file by changing its content type in my web application 3.no i am converting it from the datagrid
subodh