PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

Multiple Font styles in a single Table Cell
https://forum.pdfsharp.net/viewtopic.php?f=2&t=1861
Page 1 of 1

Author:  Jogburn [ Thu Dec 01, 2011 7:59 pm ]
Post subject:  Multiple Font styles in a single Table Cell

Please excuse the base level of this question. I am a newbie and seem to be having a problem getting two different fonts inside the same cell.

I am working in Migradoc and Visual Basic Express 2010 on Windows XP

My goal for this portion is to have a table with 2 columns. The first column is just a incremental number and the second has multiple lines with each line different bold, bold italics, size....font can stay the same. I only have a few lines at the moment for testing purposes.

As a side question is it possible to only have a border line on the bottom of the cells?

Here is a simplified sample of what I want


Line 1 Text, small Font, not bold
Line 2 Text, larger Font, Bold Italics
1 Line 3 Text, Large Font, Bold
Line 4 Text, smaller Font, not bold
Line 5 Text, tiny font, not bold

Line drawing at the bottom of the fifth line


Code:
   ' Create a new MigraDoc document
        Dim document As Document = New Document
        ' Add a section to the document
        Dim section As Section = document.AddSection

        Dim style As Style = document.Styles("Normal")
        ' Because all styles are derived from Normal, the next line changes the
        ' font of the whole document. Or, more exactly, it changes the font of
        ' all styles and paragraphs that do not redefine the font.
        style.Font.Name = "Arial"
        Dim agstyle
        agstyle = document.Styles.AddStyle("agstyle", "Normal")
        agstyle.Font.Size = 8
        agstyle.Font.Bold = False
        Dim clstyle
        clstyle = document.Styles.AddStyle("clstyle", "Normal")
        clstyle.Font.Size = 9
        clstyle.Font.Bold = True
        ' Add a paragraph to the section
        Dim paragraph As Paragraph = section.AddParagraph
        paragraph.Format.Alignment = ParagraphAlignment.Center

        paragraph.AddFormattedText("1080", TextFormat.Bold)
        paragraph = section.AddParagraph
        paragraph.AddFormattedText("Dub Work Order", TextFormat.Bold)
        paragraph.Format.Alignment = ParagraphAlignment.Center


        ' Create the item table
        Dim table As MigraDoc.DocumentObjectModel.Tables.Table
        table = section.AddTable
        table.Style = "Table"
        'table.Borders.Color = TableBorder
        'table.Borders.Width = 0.25
        'table.Borders.Left.Width = 0.5
        'table.Borders.Right.Width = 0.5
        'table.Rows.LeftIndent = 0
        Dim column As MigraDoc.DocumentObjectModel.Tables.Column = table.AddColumn("1cm")
        column.Format.Alignment = ParagraphAlignment.Center

        column = table.AddColumn("10cm")
        column.Format.Alignment = ParagraphAlignment.Left
        Dim row As MigraDoc.DocumentObjectModel.Tables.Row = table.AddRow
        row.HeadingFormat = True
        row.Format.Alignment = ParagraphAlignment.Center
        row.Format.Font.Bold = True
        'row.Shading.Color = TableBlue
        Dim cnt = 0

        For x = 0 To ListBox1.Items.Count - 1
            cnt = x + 1

            row = table.AddRow
            row.Cells(0).AddParagraph(cnt)
            row.Cells(0).Format.Font.Bold = False
            row.Cells(0).Format.Alignment = ParagraphAlignment.Center
            row.Cells(0).VerticalAlignment = MigraDoc.DocumentObjectModel.Tables.VerticalAlignment.Center
            ' row.Cells(0).MergeDown = 4
            row.Cells(1).AddParagraph(DataGridView1.Rows(x).Cells("Agency").FormattedValue)
            row.Cells(1).Style = "agstyle"
            'row.Cells(1).Format.Font.Bold = True
            'row.Cells(1).Format.Font.Size = 8
            row.Cells(1).Format.Alignment = ParagraphAlignment.Left
            row.Cells(1).AddParagraph(DataGridView1.Rows(x).Cells("Client").FormattedValue)
            row.Cells(1).Style = "clstyle"
           
        Next
        Return document


I assume I am making beginner mistakes, but no matter what I try the cell ends up with the same formatting for all lines


I appreciate any help you can give me,

Thanks

Joe Ogburn

Author:  Jogburn [ Thu Dec 01, 2011 8:45 pm ]
Post subject:  Re: Multiple Font styles in a single Table Cell

Ok, I figured it out......Just being slow.

What I needed to do was to add rows to the table and put each line in a separate cell........
Then I could define styles for each cell...

I doubt that you could have multiple styles in a single cell, and not really sure why you would need it since you can merge cells.......

Well, Duh!

And Yes, I can add border JUST to the bottom of the last row in the series......

Of course after hours of staring at it, trying multiple code attempts to put multiple styles in a cell...

Five minutes after posting.......my brain started to function.....

Thanks anyway,

Joe

Author:  () => true [ Fri Dec 02, 2011 7:56 am ]
Post subject:  Re: Multiple Font styles in a single Table Cell

Jogburn wrote:
I doubt that you could have multiple styles in a single cell
You can set the style for every paragraph.
And you can use AddFormattedText to mix several font styles (normal, bold, italics, font, size) in one paragraph (i.e. in one line).

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/