Hyperlink would have messy code with chinese in it

senario1:
String columnVal = "中文";
String url = "http://www.baidu.com/?q=" + columnVal;
HyperlinkCollection hyperlinks = rawDataSheet.getHyperlinks();
hyperlinks.add(row, col, 1, 1, url);

senario2:
cell.putValue(columnVal);

then I will save to hyperlinkTest.xlsx
ByteArrayOutputStream ms = new ByteArrayOutputStream();
workbook.save(ms, SaveFormat.XLSX);
byte[] bytesWorkbook = ms.toByteArray();

FileOutputStream fos = new FileOutputStream("C://Users//hyperlinkTest.xlsx");
fos.write(bytesWorkbook);
fos.close();
-------------------------------------------------------------------------------------------

In senario1, we would get messy code in url,
howerver we can see normally in
senario2 with chinese value(中文).


may I know how to use hyperlink with chinese charater?

Hi,


Please see the following sample code to accomplish your task for your reference:
e.g
Sample code:

Workbook workbook = new Workbook();

Worksheet rawDataSheet = workbook.getWorksheets().get(0);


int row = 2;

int col = 2;


String columnVal = “中文”;


String url = “百度一下,你就知道” + columnVal;

HyperlinkCollection hyperlinks = rawDataSheet.getHyperlinks();

int index = hyperlinks.add(row, col, 1, 1, url);

hyperlinks.get(index).setTextToDisplay(“中文”);


workbook.save(“f:\files\output1.xlsx”);

You need to use Hyperlink.setTextToDisplay() method to specify the chinese chars “中文” instead of complete URL. I have also attached the output file for your reference.

Let us know if you still find any issue.

Thank you.

It works,and thanks for your help.

Hi Roanld,

Thanks for your feedback and using Aspose.Cells.

It is good to know that your issue is resolved now. Let us know if you encounter any other issue, we will be glad to look into it and help you further.