I need a help to create a table border for range of cells in open office calc file using visual basic application. I have written the below code. It does not work. Could you please any one help to do this.
VB Code:
Code: Select all
Dim oSM As Object, SavePath As String
Dim oDesk As Object 'Objects from the API
Dim oDoc As Object 'Objects from the API
Dim oSheet As Object 'Objects from the API
Dim oItalic As Object
Dim arg()
Dim I As Integer, J As Integer
Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oDesk = oSM.CreateInstance("com.sun.star.frame.Desktop")
Set oDoc = oDesk.loadComponentFromURL("private:factory/scalc", "_blank", 0, arg())
Set oSheet = oDoc.getSheets().getByIndex(0)
SavePath = App.Path & "\SampleCalcfile.ods"
SavePath = ConvertToUrl(SavePath)
For I = 0 To Val(txtRows.Text) - 1
For J = 0 To Val(txtCols.Text) - 1
Call oSheet.getCellByPosition(J, I).setString("Row:" & I + 1 & ",Col:" & J + 1)
Next J
Next I
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, 0).CharWeight = 150 'Bold
oSheet.getCellRangeByPosition(0, 1, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).CharColor = 16711680 ' color
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, 0).CellBackColor = RGB(0, 220, 240) 'cell back color
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, 0).CharHeight = 15 'Font size
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).CharFontName = "Calibri" 'font name
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).CharPosture = 2 'Italic
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, 0).CharUnderLine = 1 'UnderLine
'// Set Fixed width to all columns
Dim range As Object
Set range = oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, 0)
Dim columns As Object
Set columns = range.getColumns()
For I = 0 To Val(txtCols.Text) - 1
columns.getByIndex(I).optimalWidth = True
Next
'//
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, 0).HoriJustify = 2 'Horizontal Alignment center
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.TopLine.Color = RGB(255, 0, 0)
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.TopLine.InnerLineWidth = 18
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.TopLine.OuterLineWidth = 36
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.TopLine.LineDistance = 24
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.IsTopLineValid = True
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.BottomLine.Color = RGB(255, 0, 0)
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.BottomLine.InnerLineWidth = 18
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.BottomLine.OuterLineWidth = 36
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.BottomLine.LineDistance = 24
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.IsBottomLineValid = True
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.LeftLine.Color = RGB(255, 0, 0)
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.LeftLine.InnerLineWidth = 18
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.LeftLine.OuterLineWidth = 36
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.LeftLine.LineDistance = 24
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.IsLeftLineValid = True
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.RightLine.Color = RGB(255, 0, 0)
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.RightLine.InnerLineWidth = 18
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.RightLine.OuterLineWidth = 36
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.RightLine.LineDistance = 24
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.IsRightLineValid = True
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.HorizontalLine.Color = RGB(0, 255, 0)
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.HorizontalLine.InnerLineWidth = 1
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.HorizontalLine.OuterLineWidth = 0
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.HorizontalLine.LineDistance = 0
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.IsHorizontalLineValid = True
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.VerticalLine.Color = RGB(0, 0, 255)
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.VerticalLine.InnerLineWidth = 0
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.VerticalLine.OuterLineWidth = 0
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.VerticalLine.LineDistance = 0
oSheet.getCellRangeByPosition(0, 0, Val(txtCols.Text) - 1, Val(txtRows.Text) - 1).tableBorder.IsVerticalLineValid = True
Call oDoc.storeToURL(SavePath, arg())
oDoc.Close (True)
Set oDoc = Nothing
MsgBox "Completed"
End
Regards,
Manikandan