none
docx table extra vertical space RRS feed

  • Question

  • I am trying to create a word document using the openxml formats sdk 2.0 and I am able to generate the table and fill it in with content, but I need to remove the extra space in the table.  I have been trying hideMark, but that doesn't seem to be working.

    Here is a small block of text to show what I am doing.  If anyone can help I would appreciate it.

            Dim document As DocumentFormat.OpenXml.Packaging.WordprocessingDocument = _
            WordprocessingDocument.Create("C:\tabletest.docx", _
            DocumentFormat.OpenXml.WordprocessingDocumentType.Document)
    
            Dim mainDocumentPart As MainDocumentPart = document.AddMainDocumentPart()
            mainDocumentPart.Document = New Document()
    
            Dim documentBody As New Body()
            mainDocumentPart.Document.Append(documentBody)
    
            Dim titleParagraphe As New Paragraph()
            Dim titleRun As New Run()
            Dim titleText As New Text("Testing the hidemark table cell property")
            titleRun.Append(titleText)
            titleParagraphe.Append(titleRun)
    
            documentBody.Append(titleParagraphe)
            documentBody.Append(New Paragraph(New Run(New Text(" "))))
    
            Dim tbl As New Table
            Dim tr As New TableRow
            Dim TblCells(2) As TableCell
            'Dim cellList As List(Of DocumentFormat.OpenXml.OpenXmlElement)
            'cellList = New List(Of DocumentFormat.OpenXml.OpenXmlElement)
    
            Dim tblPr As New TableProperties()
            Dim tblCellPr As New TableCellProperties()
            Dim tblBorders As New TableBorders()
            Dim tblWidth As New TableWidth()
            Dim tblbkgrnd As New Shading()
            Dim runPr As New RunProperties()
            Dim runFt As New RunFonts()
            Dim runFtSize As New FontSize
    
            'tblWidth.Width = 550
            'tblPr.Append(tblWidth)
    
            tblPr = New TableProperties()
            tblBorders.TopBorder = New TopBorder()
            tblBorders.TopBorder.Val = New EnumValue(Of BorderValues)(BorderValues.BasicBlackDots)
            tblBorders.BottomBorder = New BottomBorder()
            tblBorders.BottomBorder.Val = New EnumValue(Of BorderValues)(BorderValues.BasicBlackDots)
            tblBorders.LeftBorder = New LeftBorder()
            tblBorders.LeftBorder.Val = New EnumValue(Of BorderValues)(BorderValues.BasicBlackDots)
            tblBorders.RightBorder = New RightBorder()
            tblBorders.RightBorder.Val = New EnumValue(Of BorderValues)(BorderValues.BasicBlackDots)
            tblBorders.InsideHorizontalBorder = New InsideHorizontalBorder()
            tblBorders.InsideHorizontalBorder.Val = BorderValues.[Single]
            tblBorders.InsideVerticalBorder = New InsideVerticalBorder()
            tblBorders.InsideVerticalBorder.Val = BorderValues.[Single]
            tblPr.Append(tblBorders)
            tbl.Append(tblPr)
    
            'runPr = New RunProperties()
            'runFtSize = New FontSize
            'runFtSize.Val = Convert.ToUInt32("20")
            ''runPr.FontSize.Val = Convert.ToUInt32("20")
            ''runPr.RunFonts.Ascii = "Arial Narrow"
    
            'runFt = New RunFonts()
            'runFt.Ascii = "Arial Narrow"
            'runFt.HighAnsi = "Arial Narrow"
            'runFt.ComplexScript = "Arial"
    
            'runPr.Append(runFtSize, runFt)
            'Dim doNotWrap As HideMark
            '' Dim fnNoWrap As New NoWrap
    
            'doNotWrap = New HideMark()
            ''fnNoWrap = New NoWrap
            'doNotWrap.Val = New EnumValue(Of OnOffOnlyValues)(OnOffOnlyValues.On)
            'fnNoWrap.Val = New EnumValue(Of OnOffOnlyValues)(OnOffOnlyValues.On)
    
            tr = New TableRow
            TblCells(0) = New TableCell()
            TblCells(1) = New TableCell()
            TblCells(2) = New TableCell()
    
            'tblCellPr = New TableCellProperties()
            'tblbkgrnd = New Shading()
    
            'tblbkgrnd.Fill = "99CCFF"
            ' tblCellPr.Append(tblbkgrnd)
            'tblCellPr.Append(doNotWrap)
            ' tblCellPr.Append(fnNoWrap)
            'TblCells(0).Append(tblCellPr)
    
            'tblCellPr = New TableCellProperties()
            'doNotWrap = New HideMark()
            '' doNotWrap.Val = New EnumValue(Of OnOffOnlyValues)(OnOffOnlyValues.On)
            'tblCellPr.Append(doNotWrap)
    
            'TblCells(1).Append(tblCellPr)
    
            'tblCellPr = New TableCellProperties()
            'doNotWrap = New HideMark()
            'doNotWrap.Val = New EnumValue(Of OnOffOnlyValues)(OnOffOnlyValues.On)
            'tblCellPr.Append(doNotWrap)
            'TblCells(1).Append(tblCellPr)
    
            ' TblCells(2).Append(CType(tblCellPr.Clone, TableCellProperties))
    
            TblCells(0).Append(New Paragraph(New Run(New Text(" column #1 "))))
            TblCells(1).Append(New Paragraph(New Run(New Text(" column #2 "))))
            TblCells(2).Append(New Paragraph(New Run(New Text(" column #3 "))))
    
            tr.Append(TblCells(0))
            tr.Append(TblCells(1))
            tr.Append(TblCells(2))
    
            tbl.Append(tr)
    
            documentBody.Append(tbl)
    
            document.MainDocumentPart.Document.Save()
            document.Dispose()
    Monday, September 14, 2009 1:01 PM

Answers

  • turned out that my problem with not with hidemark at all.  I solved my problem by adding SpacingBetweenLines class to the paragraph properties for each paragraph in each table cell.  The table looks great now.
    Thursday, September 17, 2009 2:36 AM