Forum Moderators: open
Once they have configured the item, there is a link that says "copy to clipboard - excel format". This has been working fine except that now there is a request to put a line feed (alt + enter) after 1 bit of text and before the next to keep is all in the same excel cell but on different lines. The ultimate goal of all this is to paste from the clipboard into a formatted excel spreadsheet to create in order form.
I've tried to insert "\v" (vertical tab) but that does nothing.
I've tried to insert "\n" (line feed) but that moves to the next row to paste the rest of the data.
I've tried to insert "\10" but that inserts a square box instead of the line feed.
I've tried to insert String.fromCharCode(10) but that moves to the next row also.
How do I do this? See sample code below.
data = data + Qty;
data = data + "\t" + designation;
data = data + "\t" + description;
data = data + "\v" + NeedNewLine;
data = data + "\t" + Net;
data = data + "\r\n";
window.clipboardData.setData('Text', data);
What I need is for the text in "Description" to show first in the cell. Then in the same cell on a new line show the text called "NeedNewLine".
Any suggestions are appreciated.
Did I misunderstand your response?
Thanks.
eg
data = data + "\t" + '"' + description + '"';
you will probably also need to replace any quotes within desciption with ""
If all else fails try exporting example from excel to discover formatting required for new lines within a field.
Maybe I should try to automatically convert the that I get to the correct alt+enter once it is within the excel spreadsheet. I'm not sure how I can do that, but I'll give that a try.
Thanks again.
foo[TAB]"bar
baz"[TAB]foobar
...does not result in:
+-----+-----+--------+
¦ foo ¦ bar ¦ foobar ¦
¦ ... ¦ baz ¦ ...... ¦
+-----+-----+--------+
Right?
[edited by: DrDoc at 10:43 pm (utc) on Aug. 14, 2008]
+------+---------+-------+
¦ foo ¦ bar baz ¦ foobar¦
I can not do exactly what you suggest using Visual Web Developer 2005. It results in an error when I try to run the web page. I can not do:
data = data + " " + newline1;
data = data + "
" + newline2;
This creates an error on the web page.
var strOut = "foo\t\"bar\nbaz\"\tfoobar";
window.clipboardData.setData('Text', strOut);
Now paste in Excel. Voila!
var strOut = "foo\t\"bar\nbaz\"\t\"I can even \"\"quote\"\" strings in here!\"";
window.clipboardData.setData('Text', strOut);
That works too!
As long as you have tab characters (\t) separating the fields, and any fields which employ newlines surrounded by double quotes -- it should work.
Again, create what you want in Excel. Save the file in the "Text (Tab delimited)" format. Open the file in your favorite text editor. That is what you need to recreate in your JavaScript. And that is what we have given you instructions for above.
var strOut = "foo\t\"bar\nbaz\"\tfoobar";
window.clipboardData.setData('Text', strOut);
That works.
[edited by: DrDoc at 12:51 am (utc) on Aug. 15, 2008]
I can "save as" from excel to various formats but is does not show me anything useful.
Are you saying that when you "save as tab separated values" the file contains some odd character at the line break position ?
The odd character in you post appears to be "/010" octal 10, decimal 8 (backspace) perhaps that is it ?
Could I beg one more try? Please replace foo bar baz and foobar with variable names Qty Description Newline and Net.
Sorry to be so dense, but I have been looking at this so long, I'm not seeing the forest for the trees.
Thanks for sticking with me!