How to get actual value when copy from excel to web page
I have a simple JavaScript code in HTML page which gets pasted content from excel, splits it by "t"
and puts it in a HTML table.
Somethin like this - http://jsfiddle.net/duwood/sTX7y/
When in Excel I have cell with value 1.2562 and this cell is number formatted with 2 decimal places, Excel displays 1.26. When I copy/paste this cell to the HTML page, only 1.26 is copied. When I paste to another Excel document the actual value is pasted, but only if the source Excel file is still open.
Is there any way to get the actual cell value from the clipboard using JavaScript?
javascript excel
|
show 3 more comments
I have a simple JavaScript code in HTML page which gets pasted content from excel, splits it by "t"
and puts it in a HTML table.
Somethin like this - http://jsfiddle.net/duwood/sTX7y/
When in Excel I have cell with value 1.2562 and this cell is number formatted with 2 decimal places, Excel displays 1.26. When I copy/paste this cell to the HTML page, only 1.26 is copied. When I paste to another Excel document the actual value is pasted, but only if the source Excel file is still open.
Is there any way to get the actual cell value from the clipboard using JavaScript?
javascript excel
please read stackoverflow.com/help/how-to-ask You will find people would be more receptive to help if you edited your post to be more inline with the guidelines
– alowflyingpig
Nov 11 at 23:31
This: but only if the source Excel file is still open -- and if it is not open? what happens?
– Randy Casburn
Nov 11 at 23:31
I'd be using.value
Would be nice to see the code though...
– alowflyingpig
Nov 11 at 23:38
I added jsfiddle link, not mine, but the code is similar.
– Todor
Nov 11 at 23:45
2
Last paragraph on this page is relevant - mschaef.com/what_is_in_your_clipboard
– Tim Williams
Nov 11 at 23:46
|
show 3 more comments
I have a simple JavaScript code in HTML page which gets pasted content from excel, splits it by "t"
and puts it in a HTML table.
Somethin like this - http://jsfiddle.net/duwood/sTX7y/
When in Excel I have cell with value 1.2562 and this cell is number formatted with 2 decimal places, Excel displays 1.26. When I copy/paste this cell to the HTML page, only 1.26 is copied. When I paste to another Excel document the actual value is pasted, but only if the source Excel file is still open.
Is there any way to get the actual cell value from the clipboard using JavaScript?
javascript excel
I have a simple JavaScript code in HTML page which gets pasted content from excel, splits it by "t"
and puts it in a HTML table.
Somethin like this - http://jsfiddle.net/duwood/sTX7y/
When in Excel I have cell with value 1.2562 and this cell is number formatted with 2 decimal places, Excel displays 1.26. When I copy/paste this cell to the HTML page, only 1.26 is copied. When I paste to another Excel document the actual value is pasted, but only if the source Excel file is still open.
Is there any way to get the actual cell value from the clipboard using JavaScript?
javascript excel
javascript excel
edited Nov 11 at 23:43
asked Nov 11 at 23:27
Todor
206
206
please read stackoverflow.com/help/how-to-ask You will find people would be more receptive to help if you edited your post to be more inline with the guidelines
– alowflyingpig
Nov 11 at 23:31
This: but only if the source Excel file is still open -- and if it is not open? what happens?
– Randy Casburn
Nov 11 at 23:31
I'd be using.value
Would be nice to see the code though...
– alowflyingpig
Nov 11 at 23:38
I added jsfiddle link, not mine, but the code is similar.
– Todor
Nov 11 at 23:45
2
Last paragraph on this page is relevant - mschaef.com/what_is_in_your_clipboard
– Tim Williams
Nov 11 at 23:46
|
show 3 more comments
please read stackoverflow.com/help/how-to-ask You will find people would be more receptive to help if you edited your post to be more inline with the guidelines
– alowflyingpig
Nov 11 at 23:31
This: but only if the source Excel file is still open -- and if it is not open? what happens?
– Randy Casburn
Nov 11 at 23:31
I'd be using.value
Would be nice to see the code though...
– alowflyingpig
Nov 11 at 23:38
I added jsfiddle link, not mine, but the code is similar.
– Todor
Nov 11 at 23:45
2
Last paragraph on this page is relevant - mschaef.com/what_is_in_your_clipboard
– Tim Williams
Nov 11 at 23:46
please read stackoverflow.com/help/how-to-ask You will find people would be more receptive to help if you edited your post to be more inline with the guidelines
– alowflyingpig
Nov 11 at 23:31
please read stackoverflow.com/help/how-to-ask You will find people would be more receptive to help if you edited your post to be more inline with the guidelines
– alowflyingpig
Nov 11 at 23:31
This: but only if the source Excel file is still open -- and if it is not open? what happens?
– Randy Casburn
Nov 11 at 23:31
This: but only if the source Excel file is still open -- and if it is not open? what happens?
– Randy Casburn
Nov 11 at 23:31
I'd be using
.value
Would be nice to see the code though...– alowflyingpig
Nov 11 at 23:38
I'd be using
.value
Would be nice to see the code though...– alowflyingpig
Nov 11 at 23:38
I added jsfiddle link, not mine, but the code is similar.
– Todor
Nov 11 at 23:45
I added jsfiddle link, not mine, but the code is similar.
– Todor
Nov 11 at 23:45
2
2
Last paragraph on this page is relevant - mschaef.com/what_is_in_your_clipboard
– Tim Williams
Nov 11 at 23:46
Last paragraph on this page is relevant - mschaef.com/what_is_in_your_clipboard
– Tim Williams
Nov 11 at 23:46
|
show 3 more comments
1 Answer
1
active
oldest
votes
Clipboard formats
When you copy data from an application, it sends different pieces of data, on different formats, to the clipboard. As a result, you can do things as copying a file and then paste the actual file on a directory or just its path on a text document.
Likewise, an application is ready to understand a certain set of formats.
Some of these formats are standard. Others, are custom formats unique to an application. Maybe you want to read about clipboard formats on Windows and, mainly, the article provided by @Tim Williams.
You need to find a format that both Excel and your supported browsers can understand.
This other answer list some formats used by Excel. The Clipboard API and events W3C Working Draft enforces some mandatory data types.
In a slightly different scenario, I copied a range of cells from LibreOffice Calc to Firefox on my Linux machine. I can get a list of valid data formats for the current selection by using xclip
:
xclip -selection clipboard -o -t TARGETS
As per @Tim Williams' link you can use a tool called . It seems that it is not available any longer; the OP found a similar one called clipview.cbdump
on Windows
It returns around 20 formats, half of them exclusive to OpenOffice (application/x-openoffice-...
). Just two were supported by my browser (the rest return an empty string): text/plain
and text/html
.
Under text/plain
format, the browser pastes the text inside the cells as you see it (1.26, not the real value 1.2562) and that makes sense. Under text/html
it returns a very verbose output, including the cell value:
<!-- more html -->
<td height="34" align="right" sdval="1.2562">1.26</td>
<!-- more html -->
Set clipboard format in JavaScript
Once you know which is your target format, you can use ClipboardEvent.clipboardData
:
- to obtain the data to be pasted from the
paste
event handler, typically with agetData(format)
call.
format
is a DOMString representing the type of data to retrieve.
var textArea = document.querySelector('textarea');
textArea.addEventListener('paste', function(e) {
var format = document.querySelector('input[name="format"]:checked').value;
e.preventDefault();
var excel_data = (e.originalEvent || e).clipboardData.getData(format);
textArea.value = excel_data;
});
<input id="plainText" type="radio" name="format" value="text/plain" checked>
<label for="plainText">plain text</label>
<input id="HTML" type="radio" name="format" value="text/html">
<label for="html">HTML</label>
<p>Paste excel data here:</p>
<textarea></textarea>
I couldn't findcbdump
anywhere on the web, but I found a similar toolclipview
that gets the job done. peterbuettner.de/develop/tools/clipview
– Todor
Nov 22 at 0:14
@Todor - Thanks for sharing. I've updated my answer.
– David
Nov 22 at 9:43
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254286%2fhow-to-get-actual-value-when-copy-from-excel-to-web-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Clipboard formats
When you copy data from an application, it sends different pieces of data, on different formats, to the clipboard. As a result, you can do things as copying a file and then paste the actual file on a directory or just its path on a text document.
Likewise, an application is ready to understand a certain set of formats.
Some of these formats are standard. Others, are custom formats unique to an application. Maybe you want to read about clipboard formats on Windows and, mainly, the article provided by @Tim Williams.
You need to find a format that both Excel and your supported browsers can understand.
This other answer list some formats used by Excel. The Clipboard API and events W3C Working Draft enforces some mandatory data types.
In a slightly different scenario, I copied a range of cells from LibreOffice Calc to Firefox on my Linux machine. I can get a list of valid data formats for the current selection by using xclip
:
xclip -selection clipboard -o -t TARGETS
As per @Tim Williams' link you can use a tool called . It seems that it is not available any longer; the OP found a similar one called clipview.cbdump
on Windows
It returns around 20 formats, half of them exclusive to OpenOffice (application/x-openoffice-...
). Just two were supported by my browser (the rest return an empty string): text/plain
and text/html
.
Under text/plain
format, the browser pastes the text inside the cells as you see it (1.26, not the real value 1.2562) and that makes sense. Under text/html
it returns a very verbose output, including the cell value:
<!-- more html -->
<td height="34" align="right" sdval="1.2562">1.26</td>
<!-- more html -->
Set clipboard format in JavaScript
Once you know which is your target format, you can use ClipboardEvent.clipboardData
:
- to obtain the data to be pasted from the
paste
event handler, typically with agetData(format)
call.
format
is a DOMString representing the type of data to retrieve.
var textArea = document.querySelector('textarea');
textArea.addEventListener('paste', function(e) {
var format = document.querySelector('input[name="format"]:checked').value;
e.preventDefault();
var excel_data = (e.originalEvent || e).clipboardData.getData(format);
textArea.value = excel_data;
});
<input id="plainText" type="radio" name="format" value="text/plain" checked>
<label for="plainText">plain text</label>
<input id="HTML" type="radio" name="format" value="text/html">
<label for="html">HTML</label>
<p>Paste excel data here:</p>
<textarea></textarea>
I couldn't findcbdump
anywhere on the web, but I found a similar toolclipview
that gets the job done. peterbuettner.de/develop/tools/clipview
– Todor
Nov 22 at 0:14
@Todor - Thanks for sharing. I've updated my answer.
– David
Nov 22 at 9:43
add a comment |
Clipboard formats
When you copy data from an application, it sends different pieces of data, on different formats, to the clipboard. As a result, you can do things as copying a file and then paste the actual file on a directory or just its path on a text document.
Likewise, an application is ready to understand a certain set of formats.
Some of these formats are standard. Others, are custom formats unique to an application. Maybe you want to read about clipboard formats on Windows and, mainly, the article provided by @Tim Williams.
You need to find a format that both Excel and your supported browsers can understand.
This other answer list some formats used by Excel. The Clipboard API and events W3C Working Draft enforces some mandatory data types.
In a slightly different scenario, I copied a range of cells from LibreOffice Calc to Firefox on my Linux machine. I can get a list of valid data formats for the current selection by using xclip
:
xclip -selection clipboard -o -t TARGETS
As per @Tim Williams' link you can use a tool called . It seems that it is not available any longer; the OP found a similar one called clipview.cbdump
on Windows
It returns around 20 formats, half of them exclusive to OpenOffice (application/x-openoffice-...
). Just two were supported by my browser (the rest return an empty string): text/plain
and text/html
.
Under text/plain
format, the browser pastes the text inside the cells as you see it (1.26, not the real value 1.2562) and that makes sense. Under text/html
it returns a very verbose output, including the cell value:
<!-- more html -->
<td height="34" align="right" sdval="1.2562">1.26</td>
<!-- more html -->
Set clipboard format in JavaScript
Once you know which is your target format, you can use ClipboardEvent.clipboardData
:
- to obtain the data to be pasted from the
paste
event handler, typically with agetData(format)
call.
format
is a DOMString representing the type of data to retrieve.
var textArea = document.querySelector('textarea');
textArea.addEventListener('paste', function(e) {
var format = document.querySelector('input[name="format"]:checked').value;
e.preventDefault();
var excel_data = (e.originalEvent || e).clipboardData.getData(format);
textArea.value = excel_data;
});
<input id="plainText" type="radio" name="format" value="text/plain" checked>
<label for="plainText">plain text</label>
<input id="HTML" type="radio" name="format" value="text/html">
<label for="html">HTML</label>
<p>Paste excel data here:</p>
<textarea></textarea>
I couldn't findcbdump
anywhere on the web, but I found a similar toolclipview
that gets the job done. peterbuettner.de/develop/tools/clipview
– Todor
Nov 22 at 0:14
@Todor - Thanks for sharing. I've updated my answer.
– David
Nov 22 at 9:43
add a comment |
Clipboard formats
When you copy data from an application, it sends different pieces of data, on different formats, to the clipboard. As a result, you can do things as copying a file and then paste the actual file on a directory or just its path on a text document.
Likewise, an application is ready to understand a certain set of formats.
Some of these formats are standard. Others, are custom formats unique to an application. Maybe you want to read about clipboard formats on Windows and, mainly, the article provided by @Tim Williams.
You need to find a format that both Excel and your supported browsers can understand.
This other answer list some formats used by Excel. The Clipboard API and events W3C Working Draft enforces some mandatory data types.
In a slightly different scenario, I copied a range of cells from LibreOffice Calc to Firefox on my Linux machine. I can get a list of valid data formats for the current selection by using xclip
:
xclip -selection clipboard -o -t TARGETS
As per @Tim Williams' link you can use a tool called . It seems that it is not available any longer; the OP found a similar one called clipview.cbdump
on Windows
It returns around 20 formats, half of them exclusive to OpenOffice (application/x-openoffice-...
). Just two were supported by my browser (the rest return an empty string): text/plain
and text/html
.
Under text/plain
format, the browser pastes the text inside the cells as you see it (1.26, not the real value 1.2562) and that makes sense. Under text/html
it returns a very verbose output, including the cell value:
<!-- more html -->
<td height="34" align="right" sdval="1.2562">1.26</td>
<!-- more html -->
Set clipboard format in JavaScript
Once you know which is your target format, you can use ClipboardEvent.clipboardData
:
- to obtain the data to be pasted from the
paste
event handler, typically with agetData(format)
call.
format
is a DOMString representing the type of data to retrieve.
var textArea = document.querySelector('textarea');
textArea.addEventListener('paste', function(e) {
var format = document.querySelector('input[name="format"]:checked').value;
e.preventDefault();
var excel_data = (e.originalEvent || e).clipboardData.getData(format);
textArea.value = excel_data;
});
<input id="plainText" type="radio" name="format" value="text/plain" checked>
<label for="plainText">plain text</label>
<input id="HTML" type="radio" name="format" value="text/html">
<label for="html">HTML</label>
<p>Paste excel data here:</p>
<textarea></textarea>
Clipboard formats
When you copy data from an application, it sends different pieces of data, on different formats, to the clipboard. As a result, you can do things as copying a file and then paste the actual file on a directory or just its path on a text document.
Likewise, an application is ready to understand a certain set of formats.
Some of these formats are standard. Others, are custom formats unique to an application. Maybe you want to read about clipboard formats on Windows and, mainly, the article provided by @Tim Williams.
You need to find a format that both Excel and your supported browsers can understand.
This other answer list some formats used by Excel. The Clipboard API and events W3C Working Draft enforces some mandatory data types.
In a slightly different scenario, I copied a range of cells from LibreOffice Calc to Firefox on my Linux machine. I can get a list of valid data formats for the current selection by using xclip
:
xclip -selection clipboard -o -t TARGETS
As per @Tim Williams' link you can use a tool called . It seems that it is not available any longer; the OP found a similar one called clipview.cbdump
on Windows
It returns around 20 formats, half of them exclusive to OpenOffice (application/x-openoffice-...
). Just two were supported by my browser (the rest return an empty string): text/plain
and text/html
.
Under text/plain
format, the browser pastes the text inside the cells as you see it (1.26, not the real value 1.2562) and that makes sense. Under text/html
it returns a very verbose output, including the cell value:
<!-- more html -->
<td height="34" align="right" sdval="1.2562">1.26</td>
<!-- more html -->
Set clipboard format in JavaScript
Once you know which is your target format, you can use ClipboardEvent.clipboardData
:
- to obtain the data to be pasted from the
paste
event handler, typically with agetData(format)
call.
format
is a DOMString representing the type of data to retrieve.
var textArea = document.querySelector('textarea');
textArea.addEventListener('paste', function(e) {
var format = document.querySelector('input[name="format"]:checked').value;
e.preventDefault();
var excel_data = (e.originalEvent || e).clipboardData.getData(format);
textArea.value = excel_data;
});
<input id="plainText" type="radio" name="format" value="text/plain" checked>
<label for="plainText">plain text</label>
<input id="HTML" type="radio" name="format" value="text/html">
<label for="html">HTML</label>
<p>Paste excel data here:</p>
<textarea></textarea>
var textArea = document.querySelector('textarea');
textArea.addEventListener('paste', function(e) {
var format = document.querySelector('input[name="format"]:checked').value;
e.preventDefault();
var excel_data = (e.originalEvent || e).clipboardData.getData(format);
textArea.value = excel_data;
});
<input id="plainText" type="radio" name="format" value="text/plain" checked>
<label for="plainText">plain text</label>
<input id="HTML" type="radio" name="format" value="text/html">
<label for="html">HTML</label>
<p>Paste excel data here:</p>
<textarea></textarea>
var textArea = document.querySelector('textarea');
textArea.addEventListener('paste', function(e) {
var format = document.querySelector('input[name="format"]:checked').value;
e.preventDefault();
var excel_data = (e.originalEvent || e).clipboardData.getData(format);
textArea.value = excel_data;
});
<input id="plainText" type="radio" name="format" value="text/plain" checked>
<label for="plainText">plain text</label>
<input id="HTML" type="radio" name="format" value="text/html">
<label for="html">HTML</label>
<p>Paste excel data here:</p>
<textarea></textarea>
edited Nov 22 at 9:43
answered Nov 12 at 4:05
David
2,95011234
2,95011234
I couldn't findcbdump
anywhere on the web, but I found a similar toolclipview
that gets the job done. peterbuettner.de/develop/tools/clipview
– Todor
Nov 22 at 0:14
@Todor - Thanks for sharing. I've updated my answer.
– David
Nov 22 at 9:43
add a comment |
I couldn't findcbdump
anywhere on the web, but I found a similar toolclipview
that gets the job done. peterbuettner.de/develop/tools/clipview
– Todor
Nov 22 at 0:14
@Todor - Thanks for sharing. I've updated my answer.
– David
Nov 22 at 9:43
I couldn't find
cbdump
anywhere on the web, but I found a similar tool clipview
that gets the job done. peterbuettner.de/develop/tools/clipview– Todor
Nov 22 at 0:14
I couldn't find
cbdump
anywhere on the web, but I found a similar tool clipview
that gets the job done. peterbuettner.de/develop/tools/clipview– Todor
Nov 22 at 0:14
@Todor - Thanks for sharing. I've updated my answer.
– David
Nov 22 at 9:43
@Todor - Thanks for sharing. I've updated my answer.
– David
Nov 22 at 9:43
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53254286%2fhow-to-get-actual-value-when-copy-from-excel-to-web-page%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
please read stackoverflow.com/help/how-to-ask You will find people would be more receptive to help if you edited your post to be more inline with the guidelines
– alowflyingpig
Nov 11 at 23:31
This: but only if the source Excel file is still open -- and if it is not open? what happens?
– Randy Casburn
Nov 11 at 23:31
I'd be using
.value
Would be nice to see the code though...– alowflyingpig
Nov 11 at 23:38
I added jsfiddle link, not mine, but the code is similar.
– Todor
Nov 11 at 23:45
2
Last paragraph on this page is relevant - mschaef.com/what_is_in_your_clipboard
– Tim Williams
Nov 11 at 23:46