admin 管理员组文章数量: 1086019
In a Libre Office Writer text document, i would like to reset all explicitely applied font size settings, both in text paragraphs as well as in tables.
For paragraphs i can find such explicit settings by checking whether getPropertyState("CharHeight")
returns DIRECT_VALUE
.
Sadly, when i also process tables in the document, the cell content does show a value of CharHeight
which is different from the one in the Standard
paragraph style, but when checking the property state it does return DEFAULT_VALUE
which indicates that no explicit value has been set.
My code (executed as python macro) looks like this:
...
elements = doc.getText().createEnumeration()
while elements.hasMoreElements():
element = elements.nextElement()
if element.supportsService("com.sun.star.text.Paragraph"):
# This works fine
if element.getPropertyState("CharHeight") == DIRECT_VALUE:
element.setPropertyToDefault("CharHeight")
elif element.supportsService("com.sun.star.text.TextTable"):
cell_names = element.getCellNames()
for cell_name in cell_names:
cell = element.getCellByName(cell_name)
cell_cursor = cell.createTextCursor()
# the following condition never results to be True for my document
if cell_cursor.getPropertyState("CharHeight") == DIRECT_VALUE:
cell_cursor.setPropertyToDefault("CharHeight")
...
Resetting the value to default has no effect, which is in line with the value not beeing directly set in the first place, just then i wonder, where does the actual value (15pt in my case) come from?
When i fetch all properties of the cell text curser in the original situation, and after resetting all direct formatting with CTRL+M, and compare the properties, then only 4 properties change. CharAutoStyleName gets cleared from some cryptic value to "0", CharHeight is reduced to the expected 12pt, CharHeightAsian also is reduced, and CharStyleNames is changed from an (empty) sequence to -void- .
Sadly i am able to reproduce this effect from the macro. Neither can i reset CharAutoStyleName programatically (i get a RuntimeException), nor CharStyleNames (which was an empty sequence anyway).
In case embedded picture does not work:
In a Libre Office Writer text document, i would like to reset all explicitely applied font size settings, both in text paragraphs as well as in tables.
For paragraphs i can find such explicit settings by checking whether getPropertyState("CharHeight")
returns DIRECT_VALUE
.
Sadly, when i also process tables in the document, the cell content does show a value of CharHeight
which is different from the one in the Standard
paragraph style, but when checking the property state it does return DEFAULT_VALUE
which indicates that no explicit value has been set.
My code (executed as python macro) looks like this:
...
elements = doc.getText().createEnumeration()
while elements.hasMoreElements():
element = elements.nextElement()
if element.supportsService("com.sun.star.text.Paragraph"):
# This works fine
if element.getPropertyState("CharHeight") == DIRECT_VALUE:
element.setPropertyToDefault("CharHeight")
elif element.supportsService("com.sun.star.text.TextTable"):
cell_names = element.getCellNames()
for cell_name in cell_names:
cell = element.getCellByName(cell_name)
cell_cursor = cell.createTextCursor()
# the following condition never results to be True for my document
if cell_cursor.getPropertyState("CharHeight") == DIRECT_VALUE:
cell_cursor.setPropertyToDefault("CharHeight")
...
Resetting the value to default has no effect, which is in line with the value not beeing directly set in the first place, just then i wonder, where does the actual value (15pt in my case) come from?
When i fetch all properties of the cell text curser in the original situation, and after resetting all direct formatting with CTRL+M, and compare the properties, then only 4 properties change. CharAutoStyleName gets cleared from some cryptic value to "0", CharHeight is reduced to the expected 12pt, CharHeightAsian also is reduced, and CharStyleNames is changed from an (empty) sequence to -void- .
Sadly i am able to reproduce this effect from the macro. Neither can i reset CharAutoStyleName programatically (i get a RuntimeException), nor CharStyleNames (which was an empty sequence anyway).
In case embedded picture does not work: https://ibb.co/MD81vmMN
Share Improve this question edited Apr 1 at 21:09 Janosch asked Mar 27 at 22:26 JanoschJanosch 1,2642 gold badges11 silver badges19 bronze badges 4 |1 Answer
Reset to default 0I'm pretty sure that "auto" in CharAutoStyleName means what most people think of as direct formatting, as explained in my comment about automatically managed. So it means your text has some formatting that is not from a named style.
However, if the font and size don't seem to be set, and setPropertyToDefault
for name and size isn't getting the job done, then maybe there's some orphaned formatting that didn't get cleaned out. As mentioned in the comments, unzipping would show whether this is the case.
I don't suppose setting CharAutoStyleName to 0 would fix the problem? The cryptic name is probably the generated id of the style definition in content.xml, which gets declared higher up in the file. Hopefully if you delete the name, then LibreOffice would recognize it and delete the definition, or not include the unused definition when saving the file.
The reliable and obvious solution would be to use the dispatcher to call the "Clear Direct Formatting" action. Use the macro recorder to figure out the name of the call. Here is an example of using the dispatcher.
oFrame = ThisComponent.CurrentController.Frame
oDispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
oDispatcher.executeDispatch(oFrame, ".uno:Reload", "", 0, Array())
本文标签: unoWhere do table cells get their CharHeight from in LibreOffice WriterStack Overflow
版权声明:本文标题:uno - Where do table cells get their CharHeight from in LibreOffice Writer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744065223a2527464.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
CharAutoStyleName
at forum.openoffice./en/forum/viewtopic.php?p=518969. Also, my answer here is partly related: stackoverflow/a/42409510/5100564. – Jim K Commented Apr 3 at 15:17