Libraries to use LibreOffice with vb.net

Java, C++, C#, Delphi... - Using the UNO bridges
Locked
lacs1956
Posts: 2
Joined: Fri Jan 24, 2025 7:20 pm

Libraries to use LibreOffice with vb.net

Post by lacs1956 »

Hola a todos.

Quisiera saber que biblioteca o bibliotecas son necesarias para poder conectar a LibreOffice con vb.net

Gracias de antemano.

 Edit: English translation from MrProgrammer:
Hello everyone.

I would like to know what library or libraries are necessary to be able to connect to LibreOffice with vb.net.

Thanks in advance. 

 Edit: This is an English forum. If you want to discuss in Spanish we have OpenOffice Foro de la comunidad. If you post again in Spanish, the topic will be locked.
-- MrProgrammer, forum moderator

Este es un foro en inglés. Si prefiere discutir en español, hay OpenOffice Foro de la comunidad. Si vuelve a postear en español, el tema será bloqueado. 
LibreOffice 24 windows 11
JeJe
Volunteer
Posts: 3132
Joined: Wed Mar 09, 2016 2:40 pm

Re: Libraries to use LibreOffice with vb.net

Post by JeJe »

There won't be many people using vb.net here, you might do better with a web search,

https://stackoverflow.com/questions/453 ... office-sdk
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
ms777
Volunteer
Posts: 208
Joined: Mon Oct 08, 2007 1:33 am

Re: Libraries to use LibreOffice with vb.net

Post by ms777 »

Hi,

I use the command line compiler, not Visual Studio. But I hope that gives you some hints ...
The Powershell Script for compiling:

Code: Select all

if (-not [Environment]::Is64BitProcess) {
    Write-Error "this must be run from a 64 bit powershell window"
    exit
}

$vbc = 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe'
$cliPath = 'C:\Program Files\LibreOffice\sdk\cli\'

$cmdPars = @('/nologo', '-warnaserror+', '-debug+', '-define:DEBUG=1', '-define:TRACE=1')
#$cmdPars = @('/nologo')

('cli_basetypes', 'cli_uretypes', 'cli_oootypes', 'cli_ure', 'cli_cppuhelper') | foreach{$cmdPars += "-reference:$($cliPath)$($_).dll"}

$cmdPars += 'Writer01.vb'
& $vbc $cmdPars
... and the VB code from Writer01.vb:

Code: Select all

imports System
imports System.Collections
imports Microsoft.VisualBasic
imports unoidl.com.sun.star.lang
imports unoidl.com.sun.star.uno
imports unoidl.com.sun.star.bridge
imports uno.util

Module WriterDemo

Dim xContext As XComponentContext
Dim xServiceManager As XMultiComponentFactory 'this is XMultiServiceFactory in the OO example

Sub Main( ByVal args() As String)
	System.Console.WriteLine("Start")

	xContext  = Bootstrap.bootstrap()

	xServiceManager = DirectCast(xContext.getServiceManager(), XMultiComponentFactory)

	'Create the Desktop
	Dim xDesktop As unoidl.com.sun.star.frame.XDesktop = DirectCast(xServiceManager.createInstanceWithContext("com.sun.star.frame.Desktop", xContext), unoidl.com.sun.star.frame.XDesktop)

	'Open a new empty writer document
	Dim xComponentLoader As unoidl.com.sun.star.frame.XComponentLoader = DirectCast(xDesktop, unoidl.com.sun.star.frame.XComponentLoader)

	Dim arProps() As unoidl.com.sun.star.beans.PropertyValue = New unoidl.com.sun.star.beans.PropertyValue(){}
	Dim xComponent As unoidl.com.sun.star.lang.XComponent = xComponentLoader.loadComponentFromURL( "private:factory/swriter", "_blank", 0, arProps)

	Dim xTextDocument As unoidl.com.sun.star.text.XTextDocument = DirectCast(xComponent, unoidl.com.sun.star.text.XTextDocument)

	'Create a text object
	Dim xText As unoidl.com.sun.star.text.XText = xTextDocument.getText()
	Dim xSimpleText As unoidl.com.sun.star.text.XSimpleText = DirectCast(xText, unoidl.com.sun.star.text.XSimpleText)

	'Create a cursor object
	Dim xCursor As unoidl.com.sun.star.text.XTextCursor = xSimpleText.createTextCursor()

	'Inserting some Text
	xText.insertString(xCursor, "The first line in the newly created text document." & vbLf, false)

'	xray(xText)
	
' here starts the image insertion
	Dim image = DirectCast(xComponent, XMultiServiceFactory).createInstance("com.sun.star.text.GraphicObject")

	DirectCast(image, unoidl.com.sun.star.beans.XPropertySet).setPropertyValue("GraphicURL", New uno.Any("file:///C:/Users/Martin/Desktop/pic.png"))
	DirectCast(image, unoidl.com.sun.star.beans.XPropertySet).setPropertyValue("AnchorType", New uno.Any(GetType(unoidl.com.sun.star.text.TextContentAnchorType), unoidl.com.sun.star.text.TextContentAnchorType.AS_CHARACTER))
	DirectCast(image, unoidl.com.sun.star.beans.XPropertySet).setPropertyValue("Width", New uno.Any(2500))
	DirectCast(image, unoidl.com.sun.star.beans.XPropertySet).setPropertyValue("Height", New uno.Any(2500))

	xray(image)
	
	xText.insertTextContent(xCursor, image, False)
End Sub

Sub xray(target)
    Dim mspf = xServiceManager.createInstanceWithContext("com.sun.star.script.provider.MasterScriptProviderFactory", xContext)

	Dim tSPF = GetType(unoidl.com.sun.star.script.provider.XScriptProviderFactory)
	Dim mCreateScriptProvider = tSPF.GetMethod("createScriptProvider")
	Dim scriptProvider = mCreateScriptProvider.invoke(mspf, New Object(){New uno.Any("")})

	Dim tXScriptProvider = GetType(unoidl.com.sun.star.script.provider.XScriptProvider)
	Dim mGetScript = tXScriptProvider.GetMethod("getScript")
	Dim script = mGetScript.invoke(scriptProvider, New Object(){"vnd.sun.star.script:XrayTool._Main.Xray?language=Basic&location=application"})
	
	Dim tXScript = GetType(unoidl.com.sun.star.script.provider.XScript)
	Dim mInvoke = tXScript.GetMethod("invoke")

	Dim args1 as uno.Any() = New uno.Any(){New uno.Any(GetType(Object), target)}
	Dim args2 as Int16() = New Int16(){}
	Dim args3 as uno.Any() = New uno.Any(){}

	mInvoke.invoke(script, New Object() {args1, args2, args3})
End Sub

End Module
sveld
Posts: 31
Joined: Sat Dec 07, 2019 8:33 am
Location: The Netherlands

Re: Libraries to use LibreOffice with vb.net

Post by sveld »

Programming is not really my area, but maybe the following link is helpfull as modernizing .NET bindings for LibreOffice were a 2024 Google Summer of Code project for LibreOffice and I believe this is to be released as part of LibreOffice 25.2.
https://gist.github.com/RMZeroFour/80e5 ... abc396e839
If you run into issues post on ask.libreoffice.com or open a ticket in Bugzilla case you run into issues.
LibreOffice 24.8 on Win11 and Linux (mostly openSUSE Tumbleweed), Collabora Office App on IOS and Android, Collabora Office Online (CODE) with Nextcloud (Office)
lacs1956
Posts: 2
Joined: Fri Jan 24, 2025 7:20 pm

Re: Libraries to use LibreOffice with vb.net

Post by lacs1956 »

Gracias por responder.

¿Cómo se llama la librería?
¿Dónde se puede obtener?

No la encuentro por ningún lado.

 Edit: Topic locked.
lacs1956 posted again in Spanish without an English translation after being warned above not to do that.
lacs1956 will be banned from the forum if they continue to violate forum policy.
-- MrProgrammer, forum moderator  
LibreOffice 24 windows 11
Locked