JDK-8043947 : Export to clipboard and import to LibreOffice / Excel not working
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 8
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2014-05-23
  • Updated: 2014-05-27
  • Resolved: 2014-05-27
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 6.1.7601]

A DESCRIPTION OF THE PROBLEM :
Copy from JTable to clipboard and paste to Excel does not work like in SE7. The header / descriptor which was added does not exist in SE 8 anymore.

What's the problem?
In SE 7 the header was built by Java, in SE 8 there is no header set for html format.

Example for the (missing) html prefixed header:

SourceURL:about:blank
<!--StartFragment-->Version:1.0
StartHTML:0000000164
EndHTML:0000003980
StartFragment:0000000478
EndFragment:0000003969
... here goes my html, something like <!DOCTYPE ...><HTML> ... </HMTL>...
<!--EndFragment-->




REGRESSION.  Last worked in version 7u51

ADDITIONAL REGRESSION INFORMATION: 
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
What I did:
I used older, known on SE 7 working code, to export html of a JTable / JTree to system clipboard via an extended TransferHandler and a TransferHandler with some DataFlavors for HTML as simple HTML code. Exported html is a default html code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>

<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
<TITLE></TITLE>
<META NAME="GENERATOR" CONTENT="CSV-Tool">
<STYLE>
<!--
BODY,DIV,TABLE,THEAD,TBODY,TFOOT,TR,TH,TD,P { font-family:"Arial"; font-size:x-small }
-->
</STYLE>

</HEAD>

<BODY TEXT="#000000">
<TABLE CELLSPACING="0" COLS="6" BORDER="0">
<COLGROUP WIDTH="10"></COLGROUP>
<COLGROUP WIDTH="80"></COLGROUP>
<COLGROUP WIDTH="100"></COLGROUP>
<COLGROUP WIDTH="100"></COLGROUP>
<COLGROUP WIDTH="40"></COLGROUP>
<COLGROUP WIDTH="40"></COLGROUP>
<TR>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">3</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">16911335</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2588426</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2588685</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
</TR>
<TR>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">4</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">16911335</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2588520</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2588818</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
</TR>
<TR>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">5</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">16911335</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2588524</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F3016946, W0F3018319, W0F3016917</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">035871202353, 035871202350, C6F2124393</FONT></TD>
</TR>
<TR>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">6</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">16911335</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2592652</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2588068</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
</TR>
<TR>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">7</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">16911335</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2592719</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2592304</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">n.a.</FONT></TD>
</TR>
<TR>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">8</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">16911335</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2592910</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2591930</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">W0F2591930</FONT></TD>
<TD HEIGHT="17" ALIGN="LEFT" SDNUM="1031;0;@"><FONT FACE="Arial">035356706273, 035356706279</FONT></TD>
</TR>
</TABLE>
</BODY>

</HTML>

How to repeat it:
Build a simple swing project (compiled for java 6) with a JTable or JTree in it. Try to export something from this table via e.g. ctrl+c and import it to Excel via ctrl+v. To confirm this behaviour try to run this code with jre/jdk 7 and jre/jdk 8. It will not work with SE 8 (SE 6 had a bug too, where the header was faulty). To confirm the clipboard content it's perfect to use the following tool, which helped me a lot to see the real clipboard contents: http://www.peterbuettner.de/develop/tools/clipview/

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
This should be imported this via system clipboard to Excel / Libre as Excel-like content (some cells / rows) 
ACTUAL -
Excel / Libre complains something like "Clipboard content could not be imported" without further informations.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
None, Excel / Libre does not give more informations than the following:

Dialog with message "Clipboard content could not be imported" without further informations.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
Today I have none available but I can bring one if needed
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Ugly but works: Generate the missing header by something like this:

                DecimalFormat df = new DecimalFormat("0000000000");

                String START_HTML = "<HTML>\r\n";
                String END_HTML = "</HTML>\r\n";
                String START_TABLE = "<TABLE ";
                String END_TABLE = "</TABLE>\r\n";

                String prefixVersion = "Version:1.0\r\n";
                String prefixStartHtml = "StartHTML:@@@@@@@@@@\r\n";
                String prefixEndHtml = "EndHTML:@@@@@@@@@@\r\n";
                String prefixStartFragment = "StartFragment:@@@@@@@@@@\r\n";
                String prefixEndFragment = "EndFragment:@@@@@@@@@@\r\n";

                Integer prefixLength = prefixVersion.length() + prefixStartHtml.length() + prefixEndHtml.length()
                        + prefixStartFragment.length()
                        + prefixEndFragment.length();

                String startHTML = df.format(prefixLength + html.indexOf(START_HTML, 0) + START_HTML.length());
                String endHTML = df.format(prefixLength + html.indexOf(END_HTML, 0));
                String startFragment = df.format(prefixLength + html.indexOf(START_TABLE, 0));
                String endFragment = df.format(prefixLength + html.indexOf(END_TABLE, 0) + END_TABLE.length());

                String prefix = prefixVersion +
                        getPrefix(prefixStartHtml, startHTML) +
                        getPrefix(prefixEndHtml, endHTML) +
                        getPrefix(prefixStartFragment, startFragment) +
                        getPrefix(prefixEndFragment, endFragment);

    private String getPrefix(String source, String toReplace) {
        return source.replace("@@@@@@@@@@", toReplace);
    }


Comments
The fix for the JDK-8038999 also fixes the current issue. The JDK-8038999 has not been backported to the JDK 8.
27-05-2014