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

Cell Font Style - Calc in VB

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Code Snippets
View previous topic :: View next topic  
Author Message
kympax
Newbie
Newbie


Joined: 03 Dec 2006
Posts: 2
Location: Phils.

PostPosted: Sun Dec 03, 2006 7:53 pm    Post subject: Cell Font Style - Calc in VB Reply with quote

Good day to all, im a newbie in openoffice and i'd like to learn from the experts here in coding Calc from VB. Ive searched thru this site and found out some nice samples in coding Calc cells. I have one question though, how do i make a cell's text contents change its font style (like bold, italics, etc)...

I'd also appreciate if someone would give me a reference link in coding Calc in VB.

Thanks.
Back to top
View user's profile Send private message
SergeM
Super User
Super User


Joined: 09 Sep 2003
Posts: 3208
Location: Troyes France

PostPosted: Mon Dec 04, 2006 10:13 am    Post subject: Reply with quote

perhaps here :
a thread with VB OOoCalc problem and solution http://www.oooforum.org/forum/viewtopic.phtml?t=4707
Speed comparison between VB and OOo Basic - Some results (boucles de recherches bien faites sur ensemble de cellules)
http://www.oooforum.org/forum/viewtopic.phtml?t=8005
_________________
Linux & Windows OOo3.0
UNO & C++ : WIKI
http://wiki.services.openoffice.org/wiki/Using_Cpp_with_the_OOo_SDK
In French
http://wiki.services.openoffice.org/wiki/Documentation/FR/Cpp_Guide
Back to top
View user's profile Send private message Visit poster's website
kympax
Newbie
Newbie


Joined: 03 Dec 2006
Posts: 2
Location: Phils.

PostPosted: Mon Dec 04, 2006 5:55 pm    Post subject: Reply with quote

thanks SergeM... i think i got the answer now (got this code from various threads, i forgot the sources, thanks to them)...

Code:


    Dim oServiceManager
    Dim oDesktop
    Dim oCalcDoc
    Dim oSheet
    Dim oColumn
    Dim oColumns
   
    ' Get the Service Manager object
    Set oServiceManager = CreateObject("com.sun.star.ServiceManager")
   
    ' Get the Desktop object
    Set oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")
   
    ' Hide document parameter
    Dim aLoadArgs(0)
    Set aLoadArgs(0) = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    aLoadArgs(0).Name = "Hidden"
    aLoadArgs(0).Value = True
   
    ' Create a new empty spreadsheet.
    Set oCalcDoc = oDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, aLoadArgs())
   
    ' Get the first spreadsheet from the bunch of spreadsheets in the document.
    Set oSheet = oCalcDoc.getSheets().getByIndex(0)
   
    Call oSheet.getCellByPosition(0, 0).SetFormula("Month")
    Call oSheet.getCellByPosition(0, 1).SetFormula("Jan")
    Call oSheet.getCellByPosition(0, 2).SetFormula("Feb")
    Call oSheet.getCellByPosition(0, 3).SetFormula("Mar")
    Call oSheet.getCellByPosition(1, 0).SetFormula("Sales")
    Call oSheet.getCellByPosition(1, 1).SetValue(3827)
    Call oSheet.getCellByPosition(1, 2).SetValue(3978)
    Call oSheet.getCellByPosition(1, 3).SetValue(4103)
   
    ' Set Cell Font Format
    oSheet.getCellByPosition(0, 0).CharHeight = 10 ' Font Size
    oSheet.getCellByPosition(0, 0).CharFontName = "Arial" ' Font Name
    oSheet.getCellByPosition(0, 0).CharWeight = 150 ' Font Weight
   
    ' Set column (0) width
    Set oColumns = oSheet.getColumns()
    Set oColumn = oColumns.getByIndex(0)
    oColumn.Width = 2.5 * 2540
   
    ' Save it as an Excel file.
    Dim aSaveArgs(0)
    Set aSaveArgs(0) = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    aSaveArgs(0).Name = "FilterName"
    aSaveArgs(0).Value = "MS Excel 97"
    Call oCalcDoc.storeToURL("file:///" & Replace(App.Path, "\", "/") & "/mysample.xls", aSaveArgs())
   
    ' Close doc
    oCalcDoc.Close (True)
   
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
Page 1 of 1

 
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