Public Sub Style1(styleName as string)
Dim styDef As ObjectId = ObjectId.Null
Dim titleStyle As ObjectId = ObjectId.Null
Dim headerStyle As ObjectId = ObjectId.Null
Dim textStyle As ObjectId = ObjectId.Null
Dim titleStyleName As String = "ArialBold"
Dim headerStyleName As String = "Weird"
Dim textStyleName As String = "Arial"
Dim titleSize As Double = 0.2
Dim headerSize as Double = 0.15
Dim textSize As Double = 0.1
Dim textColor As Color = Color.FromColorIndex(ColorMethod.ByAci, CShort(7))
Dim frameColor As Color = Color.FromColorIndex(ColorMethod.ByAci, CShort(4))
Dim backColor As Color = Color.FromColorIndex(ColorMethod.ByAci, CShort(2)
Try
Using dBase As Database = HostApplicationServices.WorkingDatabase
Using trans As Transaction = dBase.TransactionManager.StartTransaction()
'First, get the tablestyle dictionary
Using tbStyleDict As DBDictionary = DirectCast(trans.GetObject(dBase.TableStyleDictionaryId, OpenMode.ForRead, False), DBDictionary)
Dim tableStyle As New TableStyle()
Try
'if it exists, set to it
tableStyle = DirectCast(trans.GetObject(tbStyleDict.GetAt(styleName), OpenMode.ForRead, False), TableStyle)
styDef = tableStyle.ObjectId
'Else create it
Catch
Try
'better make sure these fonts exist before using them!
titleStyle = SetStyle(titleStyleName, "Arial Black", dBase, trans)
headerStyle = SetStyle(headerStyleName, "Algerian", dBase, trans)
textStyle = SetStyle(textStyleName, "Arial", dBase, trans)
tbStyleDict.UpgradeOpen()
tbStyleDict.SetAt(styleName, tableStyle)
tableStyle.Description = styleName
tableStyle.IsHeaderSuppressed = False
tableStyle.IsTitleSuppressed = False
'why back color not working?
' Set background color
tableStyle.SetBackgroundColor(backColor,1) 'data row
tableStyle.SetBackgroundColor(backColor,2) 'title row
tableStyle.SetBackgroundColor(backColor,4) 'header row
' make a heavy "box" around the table
tableStyle.SetGridLineWeight(LineWeight.LineWeight100, 1, 2) 'title row
tableStyle.SetGridLineWeight(LineWeight.LineWeight100, 8, 2) 'title row
tableStyle.SetGridLineWeight(LineWeight.LineWeight100, &H20, 2) 'title row
' Set text height & cell spacing
tableStyle.VerticalCellMargin = 0.1
tableStyle.HorizontalCellMargin = 0.1
tableStyle.SetTextHeight(titleSize, 2) 'title row
tableStyle.SetTextHeight(headerSize, 4) 'header row
tableStyle.SetTextHeight(textSize, 1) 'data row
' Set text style
tableStyle.SetTextStyle(titleStyle, 2) 'title row
tableStyle.SetTextStyle(headerStyle, 4) 'header row
tableStyle.SetTextStyle(textStyle, 1) 'data row
' Set text alignment
tableStyle.SetAlignment(CellAlignment.MiddleCenter, 2) 'title row
tableStyle.SetAlignment(CellAlignment.MiddleCenter, 4) 'header row
tableStyle.SetAlignment(CellAlignment.MiddleLeft, 1) 'data row
' Set text color
tableStyle.SetColor(textColor, 2) 'title row
tableStyle.SetColor(textColor, 4) 'header row
tableStyle.SetColor(textColor, 1) 'data row
' Set frame color
tableStyle.SetGridColor(frameColor, 15, 2) 'title row
tableStyle.SetGridColor(frameColor, &H10, 2) 'title row
tableStyle.SetGridColor(frameColor, &H20, 2) 'title row
tableStyle.SetGridColor(frameColor, 15, 4) 'header row
tableStyle.SetGridColor(frameColor, &H10, 4) 'header row
tableStyle.SetGridColor(frameColor, &H20, 4) 'header row
tableStyle.SetGridColor(frameColor, 15, 1) 'data row
tableStyle.SetGridColor(frameColor, &H10, 1) 'data row
tableStyle.SetGridColor(frameColor, &H20, 1) 'data row
trans.AddNewlyCreatedDBObject(tableStyle, True)
styDef = tableStyle.ObjectId
Catch
main.logger.Error("Could not create table style" & styleName)
End Try
End Try
tableStyle.Dispose()
End Using
trans.Commit()
End Using
End Using
Catch
main.logger.Error("Could access table style dictionary")
End Try
End Sub
Edited by: perry59 on Nov 11, 2009 9:32 PM