Author Topic: TableStyle with TextStyle 2011 - C#  (Read 2720 times)

0 Members and 1 Guest are viewing this topic.

Dale Bartlett

  • Mosquito
  • Posts: 17
TableStyle with TextStyle 2011 - C#
« on: March 08, 2011, 04:00:34 AM »
Hi All,
This is my first post, so be gentle.
I wish to create a Table Style utilising Text Styles (fixed height) for each of the row types (Title, Header, Data). The Table Style is to be created ahead of generating the table, so row and column numbers are not fixed. I have scoured the web (and this site), but to no avail. With the new 2011 Row Inherit process, presumably I set one row in the style, but I can't find how to make a particular row type use a particular text style.
Many thanks and compliments to all contributers, I have only recently discovered this resource.
Regards, Dale

Jeff H

  • Needs a day job
  • Posts: 6144
Re: TableStyle with TextStyle 2011 - C#
« Reply #1 on: March 08, 2011, 04:18:29 AM »
Welome to the Swamp!

Have you looked at TableStyle.SetTextStyle(ObjectId id, string styleName)
id = TextStyleTableRecord object ID
styleName = cell style name

If you need help implementing it please reply back.


Dale Bartlett

  • Mosquito
  • Posts: 17
Re: TableStyle with TextStyle 2011 - C#
« Reply #2 on: March 08, 2011, 06:36:09 AM »
Hi Jeff,
Thanks for the reply. I believe I have resolved it (not yet tested!!):
                // Set text style 
                ts.SetTextStyle(textStyleTitleId, (int)RowType.TitleRow); // title row
                ts.SetTextStyle(textStyleHeaderId, (int)RowType.HeaderRow); // header row
                ts.SetTextStyle(textStyleDataId, (int)RowType.DataRow); // data row
                // Set text alignment
                ts.SetAlignment(CellAlignment.MiddleCenter, (int)RowType.TitleRow); // title row
                ts.SetAlignment(CellAlignment.MiddleCenter, (int)RowType.HeaderRow); // header row
                ts.SetAlignment(CellAlignment.MiddleLeft, (int)RowType.DataRow); // data row
Regards, Dale

Quote from: Jeff H
Welome to the Swamp!
Have you looked at TableStyle.SetTextStyle(ObjectId id, string styleName)
id = TextStyleTableRecord object ID
styleName = cell style name
If you need help implementing it please reply back.

bieres

  • Guest
Re: TableStyle with TextStyle 2011 - C#
« Reply #3 on: March 08, 2011, 01:42:34 PM »
Hello, do not speak English
Code: [Select]
Public Sub Tb_CrtStl()
        Dim nombre As String = GetString("Nombre del estilo:")
        Dim mrgVrt As Double = GetDouble("Margen celda Vertical.")
        Dim mrgHrz As Double = GetDouble("Margen celda Horizontal:")
        Dim alTxTl As Double = GetDouble("Altura del texto del titulo.")
        Dim alTxCab As Double = GetDouble("Altura del texto de las cabeceras.")
        Dim alTxDt As Double = GetDouble("Altura del texto de los datos.")
        Try
            Dim styleName As String = nombre
            Dim doc As Document = Application.DocumentManager.MdiActiveDocument
            Dim db As Database = doc.Database
            Using tr As Transaction = doc.TransactionManager.StartTransaction()
                Dim tsId As ObjectId = ObjectId.Null
                Dim sd As DBDictionary = DirectCast(tr.GetObject(db.TableStyleDictionaryId, _
                                                            OpenMode.ForRead), DBDictionary)
                ' Comprobar si existe
                If sd.Contains(styleName) Then
                    Application.SetSystemVariable("CTABLESTYLE", nombre)
                    Return
                Else
                    ' si no existe lo crea
                    Dim ts As New TableStyle()
                    ts.VerticalCellMargin = mrgVrt
                    ts.HorizontalCellMargin = mrgHrz
                    ts.SetTextHeight(alTxCab, RowType.HeaderRow)
                    ts.SetTextHeight(alTxTl, RowType.TitleRow)
                    ts.SetTextHeight(alTxDt, RowType.DataRow)
                    ts.SetAlignment(CellAlignment.MiddleCenter, RowType.TitleRow)
                    ts.SetAlignment(CellAlignment.MiddleCenter, RowType.DataRow)
                    ts.SetAlignment(CellAlignment.MiddleCenter, RowType.HeaderRow)
                    sd.UpgradeOpen()
                    tsId = sd.SetAt(styleName, ts)
                    tr.AddNewlyCreatedDBObject(ts, True)
                    sd.DowngradeOpen()
                    tr.Commit()
                End If
            End Using
            Application.SetSystemVariable("CTABLESTYLE", nombre)
            Return
        Catch ex As Exception
            Return
        End Try
    End Sub

fixo

  • Guest
Re: TableStyle with TextStyle 2011 - C#
« Reply #4 on: March 16, 2011, 04:03:12 PM »
bieres,

Nice code,

Gracias