I have a problem while pasting my contents (or text) generated by Java code into excel.
The problem is that my Java code generates a String with multiple lines, i.e. with line breaks (\n
) included. When I try to copy this content and paste it into an Excel file, I am getting a multiline text with a square box symbol. I came to know that Windows uses \r\n
for line breaks and not just \n
. I tried to replace my \n
with \r\n
and paste the generated text, but I am getting the same square boxes in my Excel file. Here is my sample code:
String myString = "a1\nb1";
String tmpString =myString.replace("\n","\r\n");
System.out.println( "Original = " +"\""+myString+"\"");
System.out.println( "Result = " +"\""+tmpString+"\"");
I have used the " " to wrap the text. When I tried to paste tmpstring in Excel, I got the square box. How can I remove the boxes with multiple lines in my cell?