1

I am developing a .NET 8 cross-platform application on Debian, which needs to interact with LibreOffice via UNO API. What i'm trying to accomplish is to save an opened Libre Office tab.

Here is my approximate code:

using unoidl.com.sun.star.frame;
using unoidl.com.sun.star.lang;
using unoidl.com.sun.star.uno;
using unoidl.com.sun.star.beans;
    
public void SaveLibreOfficeDocument()
{
    XComponentContext xLocalContext = uno.util.Bootstrap.bootstrap();
    XMultiComponentFactory xMCF = xLocalContext.getServiceManager();
    
    object desktop = xMCF.createInstanceWithContext("com.sun.star.frame.Desktop", xLocalContext);
    XComponentLoader xCL = (XComponentLoader)desktop;
    XModel xModel = (XModel)xCL.loadComponentFromURL("private:factory/scalc", "_blank", 0, new PropertyValue[0]);
    
    // Now, save the document
    XStorable xStorable = (XStorable)xModel;
    xStorable.store();
}

The problem is that I don't really know how to include all this packages (usings are highlighted as errors).

6
  • 1
    Were you able to follow the installation instructions as detailed here: api.libreoffice.org/docs/install.html? It says, for .net, you need to install Microsoft .Net SDK. Commented Mar 17 at 14:03
  • @SoftwareDveloper could you please explicitly explain how do I include it to my project. In the guide you provided, there is only explanations about installing it ti my machine, not including to project Commented Mar 18 at 7:56
  • There is a sample CSharp app with a sample Makefile at api.libreoffice.org/examples/CLI/CSharp/Spreadsheet. You need to add reference to the files in sdk''s cli directory and compile your program. What IDE are you using to develop your code? Commented Mar 18 at 16:48
  • @SoftwareDveloper Im using rider Commented Mar 20 at 8:25
  • 1
    I will compile your source and try to run it by editing the makefile. Pl keep the question open. Commented Mar 20 at 14:44

2 Answers 2

3
+50

These are the steps I followed so far on my Ubuntu machine:

  1. Install LibreOffice sdk: sudo apt-get install libreoffice-dev

  2. Locate the setenv file for LibreOffice by typing the following command on the terminal: locate setsdkenv_unix.sh

  3. Try executing the script: . /usr/lib/libreoffice/sdk/setsdkenv_unix.sh

  4. Install Microsoft SDK for Unubtu/Debian/RHEL: sudo apt-get update && sudo apt-get install -y dotnet-sdk-8.0

  5. I believe the development environment is set up for C#.

  6. If you can post your sample code, I will try to compile and execute it.

    Update:

    1. On my Ubuntu server, run the following steps:

    2. mkdir Sample

    3. cd Sample

    4. dotnet new console

    5. create a folder named winlib; mkdir winlib

    6. I installed the LibreOffice SDK for Windows on a Windows machine and copied the dlls from <LibreOffice SDK Installation Folder>\sdk\cli into my Ubuntu machine's winlib directory.

    7. Edit Sample.csproj file and add below lines

      <ItemGroup>

      <Reference Include="./winlib/*.dll" />

      </ItemGroup>

    8. There should be a file named Program.cs. Add your code to it and try building te project by typing in the command dotnet build. THis should compile without errors.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. You can see the sample of a code in the body of the question. Also note, that this app would not be run only on my machine, so try avoid installing external packages to users machine
2

You're dealing with the 'using' errors because .NET 8 doesn't have the UNO API libraries referenced. Here are some steps to fix the problem:

sudo apt-get install libreoffice-dev

This package contains the header files and libraries for making LibreOffice extensions and interacting with the UNO API.

You will also want to add the UNO API references to your .NET project by adding the LibreOffice libraries, which are usually located in /usr/lib/libreoffice/program/. However, manually referencing those libraries can be complex and platform-dependent.

1 Comment

thank you. That is almost what i needed. But I dont know how to add these libs. Is the directory you provided there are a lot of .so files. How do I include them. Also how do I know which ones to include. Also, ill need my program to be able to run on many machines, not only mine. So I'll need to make a nuget package. Could you please help me with that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.