dutt123
dutt123

Reputation: 3

Convert text to a Hyperlink using CSV writer in java

I have a java class using csv writer which creates csv file.As know everything will be in text format,I want a specific column data to be a hyperlink.For example consider a table with 1 rows and 4 columns OUTPUT is : when opened in excel .Each entry will be in a new cell Col1 Col2 Col3 Col4

OUTPUT when opened in Open Office Col1,Col2,Col3,Col4

The above data is when I open my csv file in excel.This creation is done by my csv writer in java. What I wanted here is that Col3 should be a hyperlink Below is my code

 public String[] convertEntry(Info ItemInfo) {
        String[] columns = new String[NUMBER_OF_COLUMNS];
        columns[1] = "Col1;
        columns[2] = "Col2";
        columns[3] = "Col3";
        columns[4] = "Col4";
        return columns;
    }

Hope am clear.Any help is appreciated

Upvotes: 0

Views: 685

Answers (1)

kendavidson
kendavidson

Reputation: 1460

It's ugly but:

this,is,a,=HYPERLINK("http://www.google.com"),test,csv

Will automatically create it. Otherwise you can turn on the configuration for autocompletion in Excel so they always change. But CSV is supposed to be text, I would suggest leaving it as just the URL and having the user know what they are doing to change it.

EDIT:

public String[] convertEntry(Info ItemInfo) {
    String[] columns = new String[NUMBER_OF_COLUMNS];
    columns[1] = "Col1;
    columns[2] = "Col2";
    columns[3] = "=HYPERLINK(" + ItemInfo.Col3 + ")";
    columns[4] = "Col4";
    return columns;
}

Just wrap the value in the =HYPERLINK() function and it will automatically be a link in excel.

Upvotes: 0

Related Questions