OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Using COM for OOo with different languages
Goto page Previous  1, 2, 3, 4, 5, 6
 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
hinek
General User
General User


Joined: 21 Jun 2005
Posts: 10
Location: Germany

PostPosted: Tue Apr 18, 2006 12:06 am    Post subject: Re: OpenOffice.org 2.0 Reply with quote

Seems that this error appears only when i call from an Windows Service. When I call the Method in a normal App, the code works. At least this is a point to start from ... I will stick to it and report.

hinek wrote:
Hi,

I tried my old C# Code (that works with 1.1.4) to use OOo 2.0 via COM. It didn't workout. It already failed at this line:
Code:

System.Activator.CreateInstance(_serviceManagerType);


Exception is: System.Runtime.InteropServices.COMException (0x80080005): Server execution failed

Is there an easy way changing my code to work with 2.0? Or are there now better ways to trigger OOo?

Thanks for your help.
Back to top
View user's profile Send private message
rajeshsegu
Power User
Power User


Joined: 20 Dec 2005
Posts: 53

PostPosted: Fri Jun 16, 2006 5:20 am    Post subject: OOCalc Java API - Global ServiceManager??????? Reply with quote

Hello Friends,

I have been stuck up with a problem of getting 'NumberFormatter' service from the OpenOffice server using OOCalc Java API. Some of my friends directed

http://www.oooforum.org/forum/viewtopic.phtml?t=37998
http://www.oooforum.org/forum/viewtopic.phtml?t=38002

to use the Global ServiceManager to get an instance of "NumberFormatter" service. I am badly in need of the code on how to get an instance and use Global Service Manager

TO make it more simple, please direct me the OOCalc Java API equalent to

oNumberFormatter = createUnoService("com.sun.star.util.NumberFormatter")

[ The above is in OOBasic ]

Any help would be appreciated.......

Regards,
Rajesh Segu
Back to top
View user's profile Send private message
zioseri
Newbie
Newbie


Joined: 27 Jul 2006
Posts: 1

PostPosted: Thu Jul 27, 2006 7:22 am    Post subject: Thanks everybody! Reply with quote

Thanks everybody for posting and suggests!
I was getting mad in these days to find a solution both for reflection and hidden mode..

cheers

marco
Back to top
View user's profile Send private message Send e-mail MSN Messenger
mpx200
Newbie
Newbie


Joined: 10 Aug 2006
Posts: 4

PostPosted: Thu Aug 10, 2006 11:40 pm    Post subject: edit odt file with vb.net Reply with quote

can anyone post a solution in vb.net 2005(#develop) for creating new or edit exist .odt document and place text to specific place in to the document.
Back to top
View user's profile Send private message MSN Messenger
diegolaz
Newbie
Newbie


Joined: 14 Aug 2006
Posts: 1

PostPosted: Mon Aug 14, 2006 8:13 am    Post subject: PHP-COM access denied Reply with quote

Hi have PHP 5.1.4 with OO.org 2.0.3 just installed.

But I get:
Code:
Fatal error: Uncaught exception 'com_exception' with message 'Failed to create COM object `com.sun.star.ServiceManager': Server execution failed ' in c:\Inetpub\wwwroot\pdf\word2pdf.php:13 Stack trace: #0 c:\Inetpub\wwwroot\pdf\word2pdf.php(13): com->com('com.sun.star.Se...') #1 c:\Inetpub\wwwroot\pdf\word2pdf.php(33): word2pdf('file:///C:/doc_...', 'file:///C:/doc_...') #2 {main} thrown in c:\Inetpub\wwwroot\pdf\word2pdf.php on line 13


where line 13 has
Code:
$osm = new COM("com.sun.star.ServiceManager") or die ("Please be sure that OpenOffice.org is installed.\n");


System is windows xp with IIS
Any ideas??

From phpinfo() I get:
COM support enabled
DCOM support disabled
com.allow_dcom 0 0
com.autoregister_casesensitive 1 1
com.autoregister_typelib 0 0
com.autoregister_verbose 0 0
com.code_page no value no value
com.typelib_file no value no value
Back to top
View user's profile Send private message
aleksve
Newbie
Newbie


Joined: 02 May 2007
Posts: 1

PostPosted: Wed May 02, 2007 1:05 am    Post subject: Different redering on different machines Reply with quote

Seems they finally fixed it in 2.2
Back to top
View user's profile Send private message
ritchie
Newbie
Newbie


Joined: 11 Oct 2007
Posts: 2

PostPosted: Thu Oct 11, 2007 7:03 am    Post subject: To terminate soffice.exe Reply with quote

This works to terminate sovffice.exe
Code:
Sub CloseSoffice()
Dim objProcess As Object
Dim colProcessList
Dim strComputer
strComputer = "."
Dim objWMIService
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colProcessList = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = 'soffice.exe'")

For Each objProcess In colProcessList
Call objProcess.Terminate
Next

Set objWMIService = Nothing

End Sub

_________________
ritchie
Back to top
View user's profile Send private message
JoGaBar
General User
General User


Joined: 25 Oct 2007
Posts: 7

PostPosted: Tue Nov 06, 2007 7:37 pm    Post subject: Schdluded Task: How call (with OLE) "com.sun.star.Servi Reply with quote

--------------------------------------------------------------------------------
Hi:

Schdluded Task: How call (with OLE) "com.sun.star.ServiceManager" ?

I programmed with Harbour (clipper) to processing data make, using
calc, file .xls. This work very, very good and nice in any session,
but this program is necesary work like Scheduled task in my Windows
2000 Server.

Are only 2 or 3 programs and not necesary buy licenc of Microsoft
Office, if can make same with OpenOffice

Error when program is called by Scheduled Task is in:

oServiceManager := TOleAuto():New("com.sun.star.ServiceManager")

How can make work my program ?
Back to top
View user's profile Send private message
prof72
Newbie
Newbie


Joined: 23 Jan 2008
Posts: 3

PostPosted: Tue Jan 29, 2008 8:28 am    Post subject: Reply with quote

I have used the C example to great success, my question is how to call

hr = AutoWrap(DISPATCH_METHOD, &vDocument, pdispDesktop, L"loadComponentFromURL", 4, params[3], params[2], params[1], params[0]);

where params[3] is setup so the app/doc will be hidden?

Code:
   SAFEARRAYBOUND sab[1];
   sab[0].lLbound = 0;
   sab[0].cElements = 2;
   params[3].parray = SafeArrayCreate(VT_VARIANT, 1, sab);

   long t=0;
   VARIANT y[2];
   VariantInit(&y[0]);
   VariantInit(&y[1]);
   y[0].vt = VT_BSTR;
   y[0].bstrVal = ::SysAllocString(L"Hidden");
   y[1].vt = VT_BOOL;
   y[1].boolVal = TRUE;
   SafeArrayPutElement(params[3].parray, &t, &y[0]); ++t;
   SafeArrayPutElement(params[3].parray, &t, &y[1]);


doesn't work I get Exception occured.
Also how would I close the opened app afterwards?

[/code]hr = AutoWrap(DISPATCH_METHOD, &vUnused, pdispDocument, L"close", 0);[/code]

returns Type Mismatch.

TIA.
Back to top
View user's profile Send private message
sk4977
Newbie
Newbie


Joined: 02 Jun 2008
Posts: 1

PostPosted: Mon Jun 02, 2008 3:05 am    Post subject: OOo with COM+C on Win32 Reply with quote

How to create an array of PropertyValue objects was also one of the problems I had. It took me a while to figure it out and now things work (mostly), so I wrote a little post about how to get it all to work in C on my blog. Maybe it helps some people (and don't hesitate to tell me if I'm doing something wrong there or if there are easier ways to things).

Now to answer prof72's questions (even if they are like 4 months old and he probably figured things out by now). I wrote a function to create a PropertyValue object (packaged in a VARIANT):
Code:

void MakePropertyValue( IDispatch* pStardesktop, OLECHAR* Name, VARIANT Value, VARIANT* PV )
{
   VARIANT       aArgs;
   VARIANT       resultMe;
   VARIANT       parm[2];
   IDispatch*    pdispValueObj;
   
   // create a property value object...
   VariantInit( &parm[0] );
   parm[0].vt = VT_BSTR;
   parm[0].bstrVal = SysAllocString( L"com.sun.star.beans.PropertyValue" );
   AutoWrap( DISPATCH_METHOD, &resultMe, pStardesktop, L"Bridge_GetStruct", 1, parm[0] );
   pdispValueObj = resultMe.pdispVal;
   VariantClear( &parm[0] );

   // set name and value...
   VariantInit( &parm[0] );
   parm[0].vt = VT_BSTR;
   parm[0].bstrVal = SysAllocString( Name );

   VariantInit( &resultMe );
   AutoWrap( DISPATCH_PROPERTYPUT, &resultMe, pdispValueObj, L"Name", 1, parm[0] );
   VariantInit( &resultMe );
   AutoWrap( DISPATCH_PROPERTYPUT, &resultMe, pdispValueObj, L"Value", 1, Value );

   VariantClear( &parm[0] );

   // return object packaged in a VARIANT...
   VariantInit( &aArgs );
   aArgs.vt = VT_DISPATCH;
   aArgs.pdispVal = pdispValueObj;

   *PV = aArgs;
}    // MakePropertyValue

Which you can then use like this:
Code:

   VariantInit( &parm[0] );
        parm[0].vt = VT_BOOL;
        parm[0].boolVal = TRUE;
   MakePropertyValue( pStardesktop, L"Hidden", parm[0], &aArgs );
   
   pPropVal = SafeArrayCreateVector( VT_VARIANT, 0, 1 );
   SafeArrayPutElement( pPropVal, &ix1, &aArgs );
       
   // Attempt to open new document...
   VariantInit( &resultDoc );
   VariantInit( &parm[0] );
   parm[0].vt = VT_BSTR;
   parm[0].bstrVal = SysAllocString( L"private:factory/swriter" );

   VariantInit( &parm[1] );
   parm[1].vt = VT_BSTR;
   parm[1].bstrVal = SysAllocString( L"_blank" );

   VariantInit( &parm[2] );
   parm[2].vt = VT_I4;
   parm[2].lVal = 0;

   VariantInit( &parm[3] );
   parm[3].vt = VT_ARRAY | VT_VARIANT;
   parm[3].parray = pPropVal;

   AutoWrap( DISPATCH_METHOD, &resultDoc, pStardesktop, L"loadComponentFromURL", 4, parm[3], parm[2], parm[1], parm[0] );

   pDoc = resultDoc.pdispVal;


And your call to the close() method fails because it needs an argument (a boolean -- whether to really close it even if it hasn't been saved yet) -- see Closing a document in the OOo wiki for more about that.

Hope this helps.
Back to top
View user's profile Send private message
bluewind3541
General User
General User


Joined: 01 Nov 2008
Posts: 9
Location: China Beijing

PostPosted: Sun Nov 02, 2008 6:49 pm    Post subject: Reply with quote

Hi,really good article.
But I'm new here.Known the openoffice API just a month.
Don't understand your article so much.

I've written a macro that can help to convert ppt to jpg.
But I want to invoke it in PHP.I don't know how to do it.
According to your article,I should start oo as a service.Is that right?

This is my macro,can you transplant it to PHP for me?
And how to start oo as a service?

__________________________________________________________
REM ***** BASIC *****

Sub Main
SplitSlides()
End Sub

Sub SplitSlides()
' This is the name of the Impress document to split
' into separate documents.
' Each page of this Impress document is saved as a
' separate document, as a PDF, and also as a Flash.
cImpressDocToSplit = "F:\test.ppt"


' Open the document to find out how many pages it has.
oDoc = OpenDocument( cImpressDocToSplit )

nNumPages = oDoc.getDrawPages().getCount()

' Now that we know how many pages it has, close it.
oDoc.dispose()

' Get the name of the document, but without a filename suffix.
cImpressDocToSplitNoSuffix = Left( cImpressDocToSplit, Len( cImpressDocToSplit ) - 4 )


' Now loop once for each page.
nHighestPageNumber = nNumPages-1
' nPageToSave = 2
For nPageToSave = 0 To nHighestPageNumber

' Open the document.
oDoc = OpenDocument( cImpressDocToSplit )

' Delete all pages except the one we're interested in keeping
' on this loop.
DeleteAllPagesExcept( oDoc, nPageToSave )

' Prepare to save the document in multiple forms.
' First get the new filename to save it under.
cNewName = cImpressDocToSplitNoSuffix + " -- page " + CSTR( nPageToSave + 1 )

' Save the document as a new impress document.


' Save it as a JPG
ExportToJPG( oDoc, cNewName )

' Close the document without saving it.
oDoc.dispose()
Next

End Sub


' Pass in the pathname to an Impress document.
' This opens the document, and returns it.
Function OpenDocument( cImpressDoc )

' Open the Impress document.

' Open the Impress document.
Dim args(0) As New com.sun.star.beans.PropertyValue
'Set the property value to be Hidden=TRUE
args(0).Name = "Hidden"
args(0).Value = TRUE
oDoc = StarDesktop.LoadComponentFromURL( ConvertToURL( cImpressDoc ), "_blank", 0, args() )
' Return the document
OpenDocument() = oDoc
End Function


' Delete all pages of an Impress or Draw document,
' EXCEPT for a certian page that we want to keep.
Function DeleteAllPagesExcept( oDoc, nPageToKeep )
nNumPages = oDoc.getDrawPages().getCount()
nHighestPageNumber = nNumPages-1

' Delete the last page, then the page before that,
' then the page before that, until we get to the
' page to keep.
' This deletes all pages AFTER the page to keep.
nPageToDelete = nHighestPageNumber
Do while nPageToDelete > nPageToKeep
' Get the page.
oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
' Tell the document to remove it.
oDoc.getDrawPages().remove( oPage )

nPageToDelete = nPageToDelete - 1
Loop

' Delete all the pages before the page to keep.
For i = 0 To nPageToKeep - 1
' Delete the first page.
nPageToDelete = 0
' Get the page.
oPage = oDoc.getDrawPages().getByIndex( nPageToDelete )
' Tell the document to remove it.
oDoc.getDrawPages().remove( oPage )
Next
End Function


Function MakePropertyValue( Optional cName As String, Optional uValue ) As com.sun.star.beans.PropertyValue
Dim oPropertyValue As New com.sun.star.beans.PropertyValue
If Not IsMissing( cName ) Then
oPropertyValue.Name = cName
EndIf
If Not IsMissing( uValue ) Then
oPropertyValue.Value = uValue
EndIf
MakePropertyValue() = oPropertyValue
End Function



Sub ExportToPDF( oDoc, cFilename )
cUrl = ConvertToURL( cFilename + ".pdf" )

oArgs = Array(_
MakePropertyValue( "URL", cURL ),_
MakePropertyValue( "FilterName", "impress_pdf_Export" ),_
)

oController = oDoc.getCurrentController()
oFrame = oController.getFrame()

oDispatcher = createUnoService( "com.sun.star.frame.DispatchHelper" )
oDispatcher.executeDispatch( oFrame, ".uno:ExportTo", "", 0, oArgs() )
End Sub



Sub ExportToSWF( oDoc, cFilename )
cUrl = ConvertToURL( cFilename + ".swf" )

oArgs = Array(_
MakePropertyValue( "URL", cURL ),_
MakePropertyValue( "FilterName", "impress_flash_Export" ),_
)

oController = oDoc.getCurrentController()
oFrame = oController.getFrame()

oDispatcher = createUnoService( "com.sun.star.frame.DispatchHelper" )
oDispatcher.executeDispatch( oFrame, ".uno:ExportTo", "", 0, oArgs() )
End Sub


Sub ExportToJPG( oDoc, cFilename )

Dim sFileUrl As String

sFileUrl = ConvertToURL( cFilename + ".jpg" )
oDrawPage = oDoc.getDrawPages().getByIndex(0)

'creating filter data
Dim aFilterData (7) as new com.sun.star.beans.PropertyValue
'properties valid for all filters
aFilterData(0).Name = "PixelWidth" '
aFilterData(0).Value = oDrawPage.Width*(72/2540) 'convert => mm => inches => pixels (72 points per inch)
aFilterData(1).Name = "PixelHeight"
aFilterData(1).Value = oDrawPage.Height*(72/2540) 'convert => mm => inches => pixels (72 points per inch)

'filter data for the image/jpeg MediaType
aFilterData(2).Name ="Quality"
aFilterData(2).Value = 50
aFilterData(3).Name ="ColorMode"
aFilterData(3).Value = 0

'filter data for the image/png MediaType
'aFilterData(2).Name ="Compression"
'aFilterData(2).Value = 9
'aFilterData(3).Name ="Interlaced"
'aFilterData(3).Value = 0

'filter data for the image/gif MediaType
'aFilterData(2).Name ="Translucent"
'aFilterData(2).Value = true
'aFilterData(3).Name ="Interlaced"
'aFilterData(3).Value = 0

'filter data for the image/bmp MediaType
'aFilterData(2).Name ="Color"
'aFilterData(2).Value = 7
'aFilterData(3).Name ="ExportMode"
'aFilterData(3).Value = 0
'aFilterData(4).Name ="Resolution"
'aFilterData(4).Value = 300
'aFilterData(5).Name ="RLE_Coding"
'aFilterData(5).Value = true
'aFilterData(6).Name ="LogicalWidth"
'aFilterData(6).Value = 2000
'aFilterData(7).Name ="LogicalHeight"
'aFilterData(7).Value = 2000

Dim aArgs (2) as new com.sun.star.beans.PropertyValue

aArgs(0).Name = "MediaType"
aArgs(0).Value = "image/jpeg"
aArgs(1).Name = "URL"
aArgs(1).Value = sFileUrl
aArgs(2).Name = "FilterData"
aArgs(2).Value = aFilterData()

xExporter = createUnoService( "com.sun.star.drawing.GraphicExportFilter" )
xExporter.setSourceDocument( oDrawPage )

xExporter.filter( aArgs() )

End Sub



___________________________________________________________


Thanks a lot!
Back to top
View user's profile Send private message Send e-mail MSN Messenger
augiedog
Newbie
Newbie


Joined: 03 Nov 2008
Posts: 1

PostPosted: Mon Nov 03, 2008 8:28 am    Post subject: Need more 'C' COM example help Reply with quote

I am using C to get a COM IDispatch to the Service manager, and am able to instantiate OOCalc instanace and insert text into cells. I need to be able to color the text and justify it now. That's all, and I'm done. But I have been going nuts trying to figure out how to do this by looking through all the IDL, and sparse COM examples. Basically I need to see an example of how to implement the below BASIC code into COM 'C' code.

THANK YOU VERY MUCH

sub MyText
rem ----------------------------------------------------------------------
rem define variables
dim document as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint"
args1(0).Value = "$A$1"

dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())

rem ----------------------------------------------------------------------
dim args2(0) as new com.sun.star.beans.PropertyValue
args2(0).Name = "Color"
args2(0).Value = 16711680

dispatcher.executeDispatch(document, ".uno:Color", "", 0, args2())
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets All times are GMT - 8 Hours
Goto page Previous  1, 2, 3, 4, 5, 6
Page 6 of 6

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group