https://bz.apache.org/ooo/show_bug.cgi?id=126950
Issue ID: 126950
Issue Type: DEFECT
Summary: Cannot change URL textfield in Calc cell when
referenced via paragraph text portions enumeration
Product: App Dev
Version: 4.1.2
Hardware: PC
OS: Linux 64-bit
Status: UNCONFIRMED
Severity: Normal
Priority: P5 (lowest)
Component: api
Assignee: [email protected]
Reporter: [email protected]
Created attachment 85519
--> https://bz.apache.org/ooo/attachment.cgi?id=85519&action=edit
Contains macros to show the bug changing URL textfield values
A Calc table cell contains a hyperlink as a URL textfield.
I want to change its URL and Representation elements. So I enumerate the cell's
text paragraph text portions and test if the actual textfield supports the
service com.sun.star.text.TextField.URL:
Sub WriteCellFieldURL()
Dim oCell
Dim oParEnum, oPar
Dim oPortionsEnum, oPortion, oField
oCell = ThisComponent.Sheets(0).getCellByPosition(0, 0)
oParEnum = oCell.Text.createEnumeration()
Do While oParEnum.hasMoreElements()
oPar = oParEnum.nextElement()
oPortionsEnum = oPar.createEnumeration()
Do While oPortionsEnum.hasMoreElements()
oPortion = oPortionsEnum.nextElement()
If oPortion.TextPortionType = "TextField" Then
oField = oPortion.TextField
If oField.supportsService("com.sun.star.text.TextField.URL") Then
Print oField.Representation & ": " & oField.URL
oField.Representation = "New file"
oField.URL = "file:///home/volker/newfile.pdf"
Print oField.Representation & ": " & oField.URL 'New URL content
Exit Do
End If
End If
Loop
Loop
Print oCell.String 'Old cell content
End Sub
But when I try to change the contents of the URL textfield, these new values
are not saved in the cell.
If I rather enumerate the cell's textfields directly, I find that the actual
field does not seem to support the service com.sun.star.text.TextField.URL.
Sub WriteCellFieldURL()
Dim oCell
Dim oFieldsEnum, oField
oCell = ThisComponent.Sheets(0).getCellByPosition(0, 0)
oFieldsEnum = oCell.TextFields.createEnumeration()
Do While oFieldsEnum.hasMoreElements()
oField = oFieldsEnum.nextElement()
Print "Field found"
If oField.supportsService("com.sun.star.text.TextField.URL") Then
Print oField.Representation & ": " & oField.URL
oField.Representation = "New file"
oField.URL = "file:///home/volker/newfile.pdf"
Print oField.Representation & ": " & oField.URL
Exit Do
End If
Loop
End Sub
So the field is not found.
My workaround is to enumerate the textfields as above and use an error handler
when reading the actual field's URL element. In this case the changes are
saved!
Sub WriteCellFieldURL()
Dim oCell
Dim oFieldsEnum, oField
Dim sURL As String
oCell = ThisComponent.Sheets(0).getCellByPosition(0, 0)
oFieldsEnum = oCell.TextFields.createEnumeration()
On Local Error Goto NoURL
Do While oFieldsEnum.hasMoreElements()
oField = oFieldsEnum.nextElement()
sURL = oField.URL
Print oField.Representation & ": " & oField.URL
oField.Representation = "New file"
oField.URL = "file:///home/volker/newfile.pdf"
Print oField.Representation & ": " & oField.URL
NoURL:
Loop
Print oCell.String
End Sub
Is it one bug or two bugs?
I have attached a file showing the effect. The behaviors explained above are
produced by starting the Subs WriteCellFieldURL1 through ...3 in its macro
module.
I tested with AOO 4.1.2 under Linux 64-Bit openSUSE 13.2 as well as under
Windows 7.
Volker
--
You are receiving this mail because:
You are the assignee for the issue.