0

I use JExcelApi (JXL, version 2.6.12) to create an Excel file.

If a cell has an URL as value, then that cell is displayed in Excel* as plain text, but if the user double-clicks it (an thus enters edit mode), and then immediately clicks somewhere else (outside the cell), Excel will turn the cell into a clickable URL (blue and underlined, on click it is opened in the system browser, without questions like "Are you sure you want to open this link?").

How to avoid that? (I want the URL to stay as plain text, not clickable)

The cell is created like: new Label(3, 2, "http://www.example.org");

This happens even if I force text format, like this: new Label(3, 2, "http://www.example.org", new WritableCellFormat(NumberFormats.TEXT))

(this does help to prevent entries beginning with '=' to being interpreted, like =C3)

When typing into Excel by hand, this can be done by typing an apostrophe as the first character. But in code if I do new Label(3, 2, "'http://www.example.org"); the apostrophe will be visible when the file is opened in Excel.

* I use Excel 2013 on Windows

David Balažic
  • 1,319
  • 1
  • 23
  • 50

2 Answers2

0

Use the following string as the cell value

="http://www.example.org"

You may need to escape double quotes, with new Label(3, 2, "=\"http://www.example.org\""); or the like. Just make sure that string is what shows up in the resulting Excel cell. I do not have JExcelApi to test this.

  • This just makes Excel to display the value: `="http://www.example.org"` Interesting, If I click inside the element to edit it, then do nothing but click into another element, the first element changes to display `http://www.example.org` (but retaining the actual value of `="http://www.example.org"`) So it seems there is some extra step of "was edited" or similar, that makes it display differently. Weird. – David Balažic Apr 02 '19 at 09:55
  • @DavidBalažic - I could not understand what you get with this answer (perhaps posting another answer helps, for the sake of adding images), and I do not understand whether this produces the result you asked for. – sancho.s ReinstateMonicaCellio Apr 02 '19 at 12:22
-1

You may want to use

new Label(3, 2, cstr("http://www.example.org"));