473,387 Members | 1,534 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Execcommand > What is happening? Anyone?

Hi!
I need help. I have a variable which is just a string containing the
output of a transform from XML to CSV format. I want the client to be
able to download this as a file (.csv), so I used this piece of code:

function SaveVarAsFile(someVar){
alert(someVar);
SaveFrame.document.open("text/plain","replace");
SaveFrame.document.write(someVar);
SaveFrame.document.close();
SaveFrame.document.charset="UTF-8";
SaveFrame.focus();
SaveFrame.document.execCommand('SaveAs','false','t est.csv');

SaveFrame is an iframe in the body of my page:
<iframe id="SaveFrame" style="display:none"></iframe>

Now I don't want the encoding to be UTF-8 but I need it to be ASCII,
in order to display the file properly in Excel instead of having all
the data in one column. But when I change charset into "ASCII", the
file that is saved is not the document in the iframe but the whole
html page the iframe is part of! How is this possible and what can I
do to fix it?
Secondly, the saved file begins and ends with html tags that I don't
want, I want it to be just plain text. How do I get rid of these tags?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=utf-8"></HEAD>
<BODY><PRE>

Hope someone can help 'cause I'm getting really frustrated! Thanks.
Jul 23 '05 #1
3 5510
Hello

I don't know if this helps.

I tested it for myself, and Microsoft seems to do something different
depending on the extension you give the file name.

If you use ".csv" then as you noted, it seems to save the HTML mark
up.

However if you use ".txt", then it will just save the plain text as
desired.

If you want to save with a file name ".csv" then you may need to use
the ActiveX object "Scripting.FileSystemObject" but obviously this is
only for browsers that support it, and it will depend on browser
security settings.

Julian
Jul 23 '05 #2
Thanks, but I had already gotten rid of the HTML tags differently, by
changing the MIME type of
SaveFrame.document.open("text/plain","replace"); to text/html. What
remains is the encoding problem, I get this neat file which looks like
this:

"id","datatype"
"0","Unknown"
"1","integer"
"2","float"
"3","string"
"4","memo"
"6","date-time"
"7","boolean"

but the encoding is unicode and Excel therefore does not separate the
columns but shows the data above all in one column. When I open it
with notepad, save it as ANSI and reopen it in Excel, it is displayed
correctly in two columns without showing the commas and apostrophes.
Who can help me? Thanks!
Jul 23 '05 #3
Hello

Sorry I could not help.

I wonder if it would make any difference to specify the encoding as well.

See the following page:-

http://www.w3.org/International/tuto...rial-char-enc/
Julian
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: dd | last post by:
Cannot figure it out. If somebody can help, I'd appreciate it. I am using DHTML Edit control from C# for editing HTML pages. I am trying to insert a table into an HTML page and I keep getting an...
1
by: E J | last post by:
Does anyone know of a way to wrap custom tags around selected text using execCommand or otherwise? I am developing a rich text editor for use in a web site and while there are a few decent ones...
3
by: Patrick S | last post by:
I am using IE 6.0. On a page, I have placed a contenteditable div which I want to use as a Rich Text Area. I am using the execCommand method of the document to control bold, italics,...
2
by: Rafal Konopka | last post by:
I've read MS documentation, I've searched the discussion threads, I cannot invoke the SaveAs command from a web page. I tried <a href="javascript:window.execCommand(\"SaveAs\");"><click here</a>...
4
by: am75 | last post by:
Hi everybody, I'm developing web pages for content management using iframes, through which users can edit html portions... I found execCommand to apply simple formats (bold, italic...) to text....
0
by: SAL | last post by:
Below is my javaScript function that I am having trouble with. When I set the bUserInterface parameter to FALSE in the follow statement, "document.execCommand("CreateLink","false", oSource)", the...
23
by: abdalimohd | last post by:
hi all, i m developing an html editor for my web page since i cannot trace out the enter key press for the available html editors for asp.net app. now i have done everything that i need with this...
1
by: appleseed | last post by:
I'm having some problems on IE with a small editor I'm building. The source of the problem is the following: Consider having an iFrame with designMode="on" in which you select some text. When...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.