질문하기

Hi-Angel's profile - activity

2019-01-21 14:03:07 +0200 질문에 답변하였습니다 how do i copy a row in windows?

Select the rows, then hold Ctrl+Alt simultaneously, and drag selection with mouse to wherever you want the copy to be pl

2017-12-16 19:35:02 +0200 받은 배지  유명한 질문 (source)
2017-12-16 19:35:02 +0200 받은 배지  주목할 만한 질문 (source)
2017-09-02 21:02:51 +0200 으뜸 답변으로 표시됨 An option like «missing font substitution»?

I'm working at firm that have an internal site with docs, presentations, etc… For I am trying to open some «pptx», or even plain «doc» format, I see mostly a punctuation symbols, a text is invisible. I figured out that the problem is that there was used some font, that I am missing → and indeed, if I select a word and change a font, it is shown correctly…

So, is there some option to substitute a font if it is missing?

OS: Kubuntu

2016-09-20 11:06:17 +0200 질문하였습니다 Save widget arrangement

I just need LO Writer to save widgets as I arranged them. I.e. every time I open lowriter, I place the widget with font familiy/size to be the first (because otherwise it hides behind "»" symbol, even though being one of the most used ones).

Google offers only development topics on the qurey, probably the question wasn't asked before.

2016-05-09 12:55:13 +0200 받은 배지  유명한 질문 (source)
2015-09-23 17:06:29 +0200 받은 배지  인기있는 질문 (source)
2015-08-23 13:24:19 +0200 받은 배지  인기있는 질문 (source)
2015-08-23 09:28:49 +0200 받은 배지  유명한 질문 (source)
2015-08-17 06:17:49 +0200 코멘트달린 답변 Style from a file doesn't work

like Heading1, Heading2, etc. And of course when I tried to load styles from that file, it didn't work; at least no the way I thought it should.

2015-08-17 06:15:38 +0200 받은 배지  논객
2015-08-17 06:15:38 +0200 코멘트달린 답변 Style from a file doesn't work

I probably had a bad explanation: for this to work one needs to know of what styles set to text pieces beforehand, thus configure just these styles in a separate file, and load it. And it works. But I haven't work much atm with office documents, and I was thinking it works rather like CSS. E.g. Heading1 would be rather an element than a style. Thus what I actually did — changed in the supposed to contain styles document a manual formatting for pieces of text that were produced by converter,

2015-08-17 05:46:23 +0200 받은 배지  주목할 만한 질문 (source)
2015-08-16 21:29:44 +0200 질문에 답변하였습니다 UNO: change page style?

In the end I am again figured it out by myself ☺ The page style could be set for a paragraph with the property «PageDescName». So I wrote a function in python — it accepts the opened document as a "file", and just changes the style name of the very first paragraph. Works like a charm.

def setFirstPage(file):
    """Sets the first page style to «First Page»"""
    enumeration = file.Text.createEnumeration()
    enumeration.nextElement().PageDescName = 'First Page'
2015-08-16 16:47:47 +0200 질문하였습니다 UNO: change page style?

I'm trying to set the first page style to, well… «First page» ☺

But I couldn't get it work. E.g. supposing the file is the current document, then:

>>> cursor = file.Text.createTextCursor()
>>> cursor.setPropertyValue("PageStyleName", "First Page")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
__main__.PropertyVetoException: Property is read-only: 'PageStyleName

Why is this? What am I supposed to do? I also found that the property appears for enumerating paragraphs, however attempt to change it there ends the same way for me.

[edit: removed redundant tag]

2015-08-16 00:28:47 +0200 질문에 답변하였습니다 How to exclude some chapters from automatic numbering of headings?

Actually you don't need to create a new style. You could just click right mouse button for a "Heading" with unwanted numbering, next in the popup menu choose «Paragraph… → Numbering style → None».

Sometimes it is grayed out for some reason, though… Anyway, I wrote a function in PyUNO which was always working for me — even if the submenu for some reason grayed out. I'll leave it here if anybody would want it:

HEADING1 = "Heading 1"
HEADING2 = "Heading 2"

def removeNumberingSomeHeading1s(text):
    """Removes numbering from the first Heading1 (intro), then skips two heading1s (chapters), and
removes from the rest Heading1s and Heading2s"""
    enumeration = text.createEnumeration()
    heading1s = 0
    while enumeration.hasMoreElements():
        par = enumeration.nextElement()
        if ( par.supportsService("com.sun.star.text.Paragraph") and
            par.ParaStyleName != None):
            if par.ParaStyleName == HEADING1:
                heading1s = heading1s + 1
            if ((heading1s > 3 or heading1s == 1) and
                par.ParaStyleName == HEADING1 or
                par.ParaStyleName == HEADING2):
                    par.setPropertyValue("NumberingStyleName", "NONE")

Though I am using it in a script with another things, I guess you can use it as a macro in the LO itself (I didn't try). Also I guess you'd need to update TOC after the work is done.

I'll also leave here a full working test code that I used. But note that for the test code to work you need to start libreoffice as a server before, like soffice "--accept=socket,host=localhost,port=8100;urp;" --headless --invisible

import uno

# that's like a consts, but they isn't since consts not allowed in python 😝
HEADING1 = "Heading 1"
HEADING2 = "Heading 2"

def removeNumberingSomeHeading1s(text):
    """Removes numbering from the first Heading1 (intro), then skips two heading1s (chapters), and
removes from the rest Heading1s and Heading2s"""
    enumeration = text.createEnumeration()
    heading1s = 0
    while enumeration.hasMoreElements():
        par = enumeration.nextElement()
        if ( par.supportsService("com.sun.star.text.Paragraph") and
            par.ParaStyleName != None):
            if par.ParaStyleName == HEADING1:
                heading1s = heading1s + 1
            if ((heading1s > 3 or heading1s == 1) and
                par.ParaStyleName == HEADING1 or
                par.ParaStyleName == HEADING2):
                    par.setPropertyValue("NumberingStyleName", "NONE")

localContext = uno.getComponentContext()

resolver = localContext.ServiceManager.createInstanceWithContext(
                "com.sun.star.bridge.UnoUrlResolver", localContext )

smgr = resolver.resolve( "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)

file = desktop.loadComponentFromURL("file:///tmp/test.odt" ,"_blank", 0, ())
removeNumberingSomeHeading1s(file.Text)
file.storeAsURL("file:///tmp/test3.odt",())
file.dispose()
2015-08-15 23:45:18 +0200 코멘트달린 답변 Adding legalised headings to my document.

Funny — that started work properly after I saved the document, and restarted the Office.

2015-08-15 23:13:45 +0200 코멘트달린 답변 Adding legalised headings to my document.

Thing to add: it is needed to also choose a style in the «Outline Numbering» (e.g. «Heading 1», «Heading 2», etc). Anyway, that doesn't work properly. For some reason the style of «Heading 2»s not being restarted for every «Heading 1».

2015-08-10 08:45:26 +0200 받은 배지  유명한 질문 (source)
2015-08-09 14:49:32 +0200 질문하였습니다 Managing server from UNO?

When one wants to use UNO API in the script, they should start LibreOffice with --headless option. But because of the 4 years old bug one couldn't once start a server, and don't care about it anymore — the server always needs to be started just before the script, and killed just after the script worked out.

Is there a way to either use UNO without the server, either somehow start the server from the API itself, so that the script would be able to see when it's ready to accept connections?

ATM I am using a workaround where I am starting a server, and then wait for some time because otherwise the code would be executed before the server ready to accept connections.

2015-08-09 14:37:47 +0200 질문에 답변하였습니다 Automate file insert?

Okay, since it isn't the last thing I need to automate, I finally wrote a script using LO UNO API with python.

First one needs to start a server with the command below, so the executed script would connect to this instance.

soffice "--accept=socket,host=localhost,port=8100;urp;" --headless --invisible

I commented the code below, I hope it is clear. This code workig for me atm.

#!/usr/bin/python3
import uno
import os

def absoluteUrl(relativeFile):
    """Constructs absolute path to the current dir in the format required by PyUNO that working with files"""
    return "file:///" + os.path.realpath(".") + "/" + relativeFile

def parBreak(document, cursor):
    """Inserts a paragraph break at cursor position"""
    document.Text.insertControlCharacter( cursor.End,
                                          uno.getConstantByName('com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK'),
                                  False)

def updateTOC(document):
    """Update links in table of contents"""
    iList = document.getDocumentIndexes()
    assert(iList.getCount() > 0), "Table of contents not found, aborting!"
    for i in range(0, iList.getCount()):
        iList.getByIndex(i).update()

localContext = uno.getComponentContext()
resolver = localContext.ServiceManager.createInstanceWithContext(
                "com.sun.star.bridge.UnoUrlResolver", localContext )
smgr = resolver.resolve( "uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager" )
remoteContext = smgr.getPropertyValue( "DefaultContext" )
desktop = smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",remoteContext)
file = desktop.loadComponentFromURL(absoluteUrl("./build/output.odt") ,"_blank", 0, ())

#insert at the beginning the file with title page and TOC
cursor = file.Text.createTextCursor()
cursor.gotoStart(False)
#to not screw the first paragraph formatting let's first make an empty one here
parBreak(file, cursor)
cursor.gotoStart(False)
cursor.insertDocumentFromURL(absoluteUrl("./Title\'n\'TOC.odt"), ())
updateTOC(file) #the inserted TOC needs to be updated

#save the file
file.storeAsURL(absoluteUrl("./build/Курсовая.odt"),())
file.dispose()

A possible pit — the function insertDocumentFromURL doesn't tell anything when something gone wrong, e.g. if the file not exist (with the weird format for file paths that would happen pretty often). So one could use only indirect logic to figure out whether something gone wrong. In the code above the logic is the assert() in the function that updates TOC.

2015-08-09 13:03:41 +0200 코멘트달린 답변 How can I use soffice from the command line when Quickstarter is running?

Doesn't work, it either complains I/O error : Is a directory, then if I create an empty file, it says parser error : Document is empty.

2015-08-09 12:25:44 +0200 받은 배지  개근상
2015-08-04 19:27:27 +0200 받은 배지  주목할 만한 질문 (source)
2015-08-04 19:17:49 +0200 코멘트달린 답변 Automate file insert?

Thank you, that worked! I should mention however that I had problems with it: the only combination that worked — when both the files are «.odt». With «.docx» LOWriter always shows a message «Can't read content!», and disappears with an advice to restore the document at the next start. An interesting and strange thing is that despite the critical error the app prints no messages to stdin/stderr.

2015-08-04 16:03:16 +0200 받은 배지  인기있는 질문 (source)
2015-08-04 11:52:40 +0200 받은 배지  시민 패트롤 (source)
2015-08-04 11:51:40 +0200 질문에 댓글을 달았습니다 Automate file insert?

Hm, it seems that there're few examples for C++, but I found ones for python! Perhaps not everything lost.

2015-08-03 21:28:55 +0200 질문에 댓글을 달았습니다 Automate file insert?

Omg, that's not easy… There's a bunch of documentation, almost no complete examples, and everything needs a good understanding of LO internals… I have no much time for that, let's see if I can do anything with that in the future.

2015-08-03 11:58:51 +0200 질문에 댓글을 달았습니다 Automate file insert?

I found some «UNO api». Perhaps if what I'm asking is possible, that have to be done with that. I'll look at this closer when I happen to be at home.

2015-08-03 07:28:58 +0200 질문하였습니다 Automate file insert?

I have a file with a title page and table of contents, plus I have a file with the content itself. I need to merge the files. Actually what I am looking for is the action being signed in menu as Insert → File…, however I'd wanted to automatize the process to use it in script because the second file I am getting from a Markdown.

Any hints? I didn't find anything relevant in manual. Though I found a page describing scripting but it seems that everything there is a GUI only scripting.

It is also an interesting question in general because I guess that's not the last thing I'd wanted automatize.

2015-08-03 00:33:52 +0200 받은 배지  인기있는 질문 (source)
2015-08-02 17:28:07 +0200 질문에 답변하였습니다 Style from a file doesn't work

After some hours of experimenting I realized a disappointing answer. To understand that it is needed to see a few concepts: when the style modified, instead of saving that globally, Office saves it exclusively for the document being edited. Hence one needs a way to import a style from a document.

The «load» menu most probably meant just an import. The reason which confused me that hard was the name of the LibreOffice wiki article Using Styles From Another Document or Template. That looks exactly like what I was looked for — I have a document that I am getting from a converter from Markdown, and I need to apply automatically styles to all elements. But it isn't.

2015-08-02 15:04:10 +0200 질문을 편집했습니다 Style from a file doesn't work

Perhaps it is a bug, but I still hope that I am doing something wrong.

I configured styles for section, subsection, and a plain text in a file, and saved the file separately.

After that I am opening a copy of the file without styles being configured, and with Wiki steps I am loading styles from the file saved in previous paragraph. With disregard whether I selected a text, or not — styles from the other file never being applied.

UPD1: I found a weird thing: I unpacked both «.odt» files, and found there styles.xml which are absolutely the same in both files, and does contain my styles. Then I changed style of a plain text, and unpacked that again, and… styles.xml haven't change!

UPD2: okay, I found that the currently used paragraph style is being saved in the content.xml file. And loading a style simply doesn't work — paragraphs are still using the same style as before.

2015-08-02 14:08:49 +0200 질문에 댓글을 달았습니다 Bad Allocation error after upgrading from 4.0.3.3 to 4.2.5.2

It is obviously a bug, you have to report it.