开发者

freezing pane in excel sheet being written with python using openoffice uno module

I have a Python script that reads a OpenOffice odt template and creates a xls file after inserting required data. I am using OpenOffice uno module with python.

I need to perform freeze pane in the xls being generated. I applied the freeze pane as required in the odt template being used but the freeze pane is not being applied to the xls being generated. Is there any way I can progra开发者_Go百科matically set freeze pane option in the xls being generated?

Any inbuilt function or anything.


For freezing the window with uno I found that it only works if you open your document with the option Hidden=False. When Hidden is set to True it will not apply the freeze command.

    import uno

    #function for setting parameters
    def make_property_array(**kwargs):
    """convert the keyword arguments to a tuple of PropertyValue unostructures"""
    array = []
    for name, value in kwargs.iteritems():
        prop = uno.createUnoStruct("com.sun.star.beans.PropertyValue")
        prop.Name = name
        prop.Value = value
        array.append(prop)
    return tuple(array)

    #load the document
    url = "file:///" + pathtoyourfile.replace("\\","/")
    document = desktop.loadComponentFromURL(url, "_blank", 0, make_property_array(Hidden=False))

    #set cell A1 as active
    table.getCellByPosition(0,0)
    #freeze the sheet at row 1
    document.CurrentController.freezeAtPosition(0,1)
    #save document in Excelformat
    document.storeAsURL(url.replace("ods","xls"), make_property_array(FilterName="MS Excel 97", Overwrite=True))
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜