Skip to content Skip to sidebar Skip to footer

Select, Copy From Ie And Paste To Excel

So the basic question is, how can I make table nicely copy pastable from IE to Excel or OpenOffice calc. The page is located here: http://tuudik.lohv.eu/Asjad/EURXML/ The table is

Solution 1:

Why not modify your PHP script to write the page content directly to Excel, writing the content to excel cells rather than HTML where you're writing to the <td> elements, then set the headers to download it... so passing an additional 'format' parameter to your script could determine the output format as HTML of XLS. The PHPExcel library offers the capability of generating XLS files in pure PHP. A link on your HTML page could then offer the option to recreate the output directly as an XLS file for download, rather than copy-and-paste.

Solution 2:

In my experiences copying from html pages is best done through a text editor that doesn't have formatting. This way the content is usually delimited in some kind (tab usually) that makes pasting to a spreadsheet much easier.

  • Copy table from browser
  • Paste in notepad, select, copy again
  • Paste in Spreadsheet application

Might not answer your question directly but if you somehow can make the data copyable as plain text with tab delimiter (as in a hidden div or something) - you would probably have greater success in pasting it into spreadsheets that supports all kinds of formatting.

Solution 3:

Using a slightly different approach, try the Get External Data feature in excel

( i tested on Using Excel 2010, but 2007 is similar, and it is available in 2003 in a slightly different guise )

From menu Data/Get External Data/From Web

opens a form:

  • paste address;(eg http://bit.ly/Kurss) and click Go
  • web page is displayed
  • scroll down to the table you want
  • select it with the little yellow arrow thingy
  • Click Import

Voila, data is in excel, as unformatted data from a background query!

Then whenever you waht to update the data, just click Refresh

Solution 4:

I to needed a way to copy html table information and paste into excel. I used a combination of techniques. First I added this code so I could automatically copy data into the paste buffer of the clients pc.

How do I copy to the clipboard in JavaScript?

// Copies a string to the clipboard. Must be called from within an // event handler such as click. May return false if it failed, but// this is not always possible. Browser support for Chrome 43+, // Firefox 42+, Safari 10+, Edge and IE 10+.// IE: The clipboard feature may be disabled by an administrator. By// default a prompt is shown the first time the clipboard is // used (per session).functioncopyToClipboard(text) {
    if (window.clipboardData && window.clipboardData.setData) {
        // IE specific code path to prevent textarea being shown while dialog is visible.return clipboardData.setData("Text", text); 

    } elseif (document.queryCommandSupported && document.queryCommandSupported("copy")) {
        var textarea = document.createElement("textarea");
        textarea.textContent = text;
        textarea.style.position = "fixed";  // Prevent scrolling to bottom of page in MS Edge.document.body.appendChild(textarea);
        textarea.select();
        try {
            returndocument.execCommand("copy");  // Security exception may be thrown by some browsers.
        } catch (ex) {
            console.warn("Copy to clipboard failed.", ex);
            returnfalse;
        } finally {
            document.body.removeChild(textarea);
        }
    }
}

I then created a copy string. Separate the cell values by a tab \t and separate the rows by a new line \n. see the example below.

I create the copy data string using PHP.

//-- Create data for a single table row//-- We needed to escape single quotes for HTML and javascript$copy_data= str_replace("'","\'",$col1."\t".$col2."\t".$col3);

//-- Create data for a multi rows//-- Separate multiple rows by \n but needs to be escaped so use \\n$copy_data= str_replace("'","\'",$col1."\t".$col2."\t".$col3."\\n".$col1."\t".$col2."\t".$col3."\\n".$col1."\t".$col2."\t".$col3);

Then I place it in a copy button on the web page.

<ahref="#"onclick="copyToClipboard('<?=$copy_data?>')">Copy</a>

Then you click on the "Copy" link to get the data into your copy buffer. Next go to Excel and click in the cell where you want to paste the data, then do a paste.

Post a Comment for "Select, Copy From Ie And Paste To Excel"