The other method is to use flash, which can avoid the security restrictions of the browser, but the system class only has the set method, and the clipboard class can access it, however, it seems that flash 10 is needed.
I found a circle on the Internet, but I didn't find it. Finally, I want to see how google sheet works.
It is found that google sheet implements multi-data format pasting of excel plain text without security restrictions and flash is not used. Many people may know this method. I was surprised at the beginning, but google's js files have been processed and seem too tired. Then I went to ZOHO sheet. Its js file was simply processed and can be debugged and viewed.
Originally, it registered the onkeydown event on the body. When the user presses the ctrl + v Key, js transfers the focus to a textarea tag. In this way, the next keyPress and keyUp events occur on textarea. Naturally, it is equivalent to copying them in textarea. Then, js transfers the focus and obtains the value from textarea. In this way, the text data in the clipboard is obtained.
The following is a small example of imitating the ZOHO sheet implementation.
Copy codeThe Code is as follows:
<Html>
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> untitled document </title>
<Script type = "text/javascript"> <! --
Function cellkeydown (event ){
If (event. ctrlKey & event. keyCode = 86 ){
Var ss = document. getElementById ("textArea ");
Ss. focus ();
Ss. select ();
// Wait for 50 milliseconds and then process the data after the keyPress event occurs
SetTimeout ("dealwithData ()", 50 );
}
}
Function dealwithData (event ){
Var ss = document. getElementById ("textArea ");
Alert (ss. value );
Ss. blur ();
}
// --> </Script>
</Head>
<Body onkeydown = "return cellkeydown (event)">
<Div>
<Textarea id = "textArea">
The obtained Excel text data can be divided by \ t, \ n to obtain the grid and row information. In this way, only the excel values of simple plain text can be obtained, and the style of the grid cannot be obtained. However, I found a method that is copied to the document of iframe (that is, the implementation method of the Online Editor), so that some style information can appear, which is particularly comprehensive in IE, it is estimated that the product can be parsed by itself. FF and Chrome can only obtain simple attributes such as row column width. I don't know who can get more comprehensive information.