I am facing issue's while Creating clickable email link in csv through Java.
While I am using simple FileWriter class
String ES_QUOTE = "\"";`
StringBuilder mailString = new StringBuilder();
mailString.append("=HYPERLINK(");
mailString.append("\"mailto:");
mailString.append(value);
mailString.append("\",\"");
mailString.append(value);
mailString.append("\")");
writer.append(ES_QUOTE mailString.toString() ES_QUOTE);
To generate the csv file. The email is displaying as plain text, but after I double click the cell to edit and then I click out of the cell, then only its displaying as expected "underline blue colored hyperlink".
I also have another implementation where I am using OpenCsv apis CsvWriter class where I am trying to create clickable Link with the following code.
OutputStreamWriter osw = new OutputStreamWriter(fileOutputStream, "UTF-8");
CSVWriter writer = new CSVWriter(osw);
StringBuilder buffer = new StringBuilder();
buffer.append("=HYPERLINK(");
buffer.append("\"");
buffer.append("mailto:");
buffer.append(resultRow.get(listValue.get(count)));
buffer.append("\",\"");
buffer.append(resultRow.get(listValue.get(count)));
buffer.append("\")");
writer.writeNext(buffer.split(",(?=(?:[^\"]*\"[^\"]*\")*[^\"]*$)"));
writer.close();
osw.close();
But I am getting the whole String of "HyperLink function" as it is....its not even been detected as a function while opening through MsExcel...
Can you please help any workaround..I will much appreciate your help. Thank you.
CodePudding user response:
CSV files are just comma-delimited text. They do not and cannot include any formatting instructions, including whether a particular cell's contents is a link or not.
Whether or not a cell with text in a hyperlink format is treated as a link is up to the viewing application (Microsoft Excel, Apple Numbers, etc.). There isn't anything that can be done to force this.