Description: Exception is received with following code: text = model.Text wtf = model.createInstance("com.sun.star.text.TextField.URL") wtf.Representation = "testURL" wtf.URL = "www.google.de" curs = text.createTextCursor() text.insertTextContent(curs, wtf, False) Traceback (most recent call last): File "C:/Users/mt1-w/PycharmProjects/untitled1/test.py", line 73, in <module> text.insertTextContent(curs, wtf, False) __main__.IllegalArgumentException Other TextFields are working fine. Steps to Reproduce: see code from description Actual Results: can´t set Hyperlinks by Python script Expected Results: execption is caused Reproducible: Always User Profile Reset: No Additional Info:
Self-Reminder: In "com.sun.star.text.TextField.URL" case Exception is thrown at https://opengrok.libreoffice.org/xref/core/editeng/source/uno/unofield.cxx?r=966f40ee#668 In "com.sun.star.text.TextField.DateTime" case, the program reaches this line https://opengrok.libreoffice.org/xref/core/sw/source/core/unocore/unofield.cxx?r=9ff648c6#2039 wnen called from the following line https://opengrok.libreoffice.org/xref/core/sw/source/core/unocore/unotext.cxx?r=2ddc66e6#618 ============================ createInstance related code: https://opengrok.libreoffice.org/xref/core/sw/source/uibase/uno/unotxdoc.cxx?r=0e27158c#1664
https://opengrok.libreoffice.org/xref/core/sw/source/core/unocore/unoobj2.cxx?r=fbc038cc#874 https://opengrok.libreoffice.org/xref/core/sw/inc/unobaseclass.hxx?r=47c830d2#124
Just a guess, not sure: the argument to attach method is SwXTextRange and is neither SvxUnoTextRange nor SvxUnoTextRangeBase, which seems often used in editeng ?
Short update. I also tried it with the standard LibreOffice macro language BASIC. But in the end the result is the same. Also when using BASIC I get the IllegalArgumentException. It looks like to me that the UNO interface has a problem here or I´m doing it in the wrong way.
I also tried to do it the other way arround. Generated a odt file with some text hyperlinks, datetime and normal text inside. Then I tried to read all text fields of the document. But only the datetime text fields where shown. The text hyperlinks where not shown. Please see python sample code. tf = model.TextFields tfenum = model.TextFields.createEnumeration() while tfenum.hasMoreElements(): tf = tfenum.nextElement() print(tf)
> mt1-wiesent@web.de changed: > > What |Removed |Added > ---------------------------------------------------------------------------- > Assignee|libreoffice-bugs@lists.free |sbergman@redhat.com > |desktop.org | Did you mean to add me to the CC list instead? Please do not randomly assign bugs to other people.
Hello, The user himajin100000 mentioned that the problem is probably caused by the files unofield.cxx and / or unotext.cxx. I took a look in the history of these files. You where one of the main editors of these files, so I thought that maybe you can have a look to the reported bug or at least can forward the bug to the right person. Sorry for assigning this bug to you but I thought your where the right person. For a developer with good knowledge of the code, debugging of this bug shouldn´t be difficult. Unfortunatelly, I don´t have a developement setup my own and most of the time I´m programming in C I´m not that aware of C++ code. So I´m happy to get some information at least if the bug I found is a real bug or only a user fail by myself. Thanks
(In reply to Stephan Bergmann from comment #6) > > mt1-wiesent@web.de changed: > > > > What |Removed |Added > > ---------------------------------------------------------------------------- > > Assignee|libreoffice-bugs@lists.free |sbergman@redhat.com > > |desktop.org | > > Did you mean to add me to the CC list instead? Please do not randomly > assign bugs to other people. please see my new comment
Sorry, I don't have knowledge about the Writer-specific UNO API and how to use it. (Assuming this even is about manipulating Writer documents. The original description does not tell, but it very much looks like it.)
Dear mt1-wiesent, To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year. There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present. If you have time, please do the following: Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/ If the bug is present, please leave a comment that includes the information from Help - About LibreOffice. If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice. Please DO NOT Update the version field Reply via email (please reply directly on the bug tracker) Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not appropriate in this case) If you want to do more to help you can test to see if your issue is a REGRESSION. To do so: 1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/ 2. Test your bug 3. Leave a comment with your results. 4a. If the bug was present with 3.3 - set version to 'inherited from OOo'; 4b. If the bug was not present in 3.3 - add 'regression' to keyword Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa Thank you for helping us make LibreOffice even better for everyone! Warm Regards, QA Team MassPing-UntouchedBug
It looks like there’s no code to handle the URL text field in a writer document and instead it only works for editeng. For example if you create a new Draw document with some shapes then this macro works to add a link to all of the shapes in the first page: model = XSCRIPTCONTEXT.getDocument() page = model.getDrawPages().getByIndex(0) for i in range(page.getCount()): shape = page.getByIndex(i) url = model.createInstance("com.sun.star.text.TextField.URL") url.Representation = "LibreOffice website" url.URL = "https://libreoffice.org" curs = shape.createTextCursor() shape.insertTextContent(curs, url, False) In a Writer document it looks like links are instead handled by setting the HyperLinkURL property on the text. For example you can use this code snippet to add a link to the beginning of the document: model = XSCRIPTCONTEXT.getDocument() text = model.Text curs = text.createTextCursor() curs.setString("LibreOffice Website") curs.setPropertyValue("HyperLinkURL", "https://libreoffice.org") It might be nice to make Writer handle TextField.URL and convert it to some text with the right properties. I think we would need to add an entry for it in the aProvNamesId table in unocoll.cxx. Without that it looks like createInstance falls back to creating a text field for editeng, but then it throws an exception when you try to use it with insertTextContent because that expects the cursor to be an SvxUnoTextRange but it is an SwXTextRange. I think that explains the diverging code paths taken in comment #1.
Thinking about it, maybe a better approach is to just make it easier for developers to discover the HyperLinkURL property. I made a patch to add a note to the docs here: https://gerrit.libreoffice.org/c/core/+/201147/1 and then throw an exception with a helpful message if you try to instantiate textfield.URL here: https://gerrit.libreoffice.org/c/core/+/201148/1