| View previous topic :: View next topic |
| Author |
Message |
kympax Newbie

Joined: 03 Dec 2006 Posts: 2 Location: Phils.
|
Posted: Sun Dec 03, 2006 7:53 pm Post subject: Cell Font Style - Calc in VB |
|
|
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 |
|
 |
SergeM Super User

Joined: 09 Sep 2003 Posts: 3208 Location: Troyes France
|
|
| Back to top |
|
 |
kympax Newbie

Joined: 03 Dec 2006 Posts: 2 Location: Phils.
|
Posted: Mon Dec 04, 2006 5:55 pm Post subject: |
|
|
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 |
|
 |
|
|
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
|