Search code examples
c#libreofficeodf

Is there a way to read/modify ODF files from C# without running Libreoffice in the background?


I've been looking into using the LibreOffice SDK to edit ODF files (Writer and Calc documents/ODS spreadsheets) and I was rather astounded when I came across this in the example source:

    /** Connect to a running office that is accepting connections.
        @return  The ServiceManager to instantiate office components. */
    private XMultiServiceFactory connect( String [] args )
    {
        
        m_xContext = uno.util.Bootstrap.bootstrap();
        
        return (XMultiServiceFactory) m_xContext.getServiceManager();
    }

Are you seriously expected to install LibreOffice on any machine (quite possibly a server) and connect to a running instance of it just to edit a spreadsheet? If so, I think that's absurd. There are libraries that let you edit Excel spreadsheets (like EPPlus and NPOI) that just let you open the file in the library and not run Excel in the background. Are there any ways to do something similar for LibreOffice files?


Solution

  • There is this, but it's written in Java. I'm not aware of a C# port.

    https://odftoolkit.org/

    This appears to be a commercial library in C#, but I have not used it:

    https://www.independentsoft.de/odf/index.html

    SyncFusion's Essential File Format's library has some support for Oasis format documents:

    https://help.syncfusion.com/file-formats/introduction https://help.syncfusion.com/file-formats/docio/word-to-odt

    You may also find this article helpful which digs into lower level interactions with the ODF file format:

    https://www.codeproject.com/Articles/38425/How-to-Read-and-Write-ODF-ODS-Files-OpenDocument-2

    Finally, you might find this sample code helpful for reading a spreadsheet:

    https://weblogs.asp.net/gunnarpeipman/reading-opendocument-spreadsheets-using-c