We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Placing Checkbox in Center of a cell in Word

It seems, that I am not able to place a checkbox horizontally aligned in a cell in Aspose Words.

    private void InsertCheckBox(Cell cell)
    {
        cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
        StructuredDocumentTag SdtCheckBox = new StructuredDocumentTag(Builder.Document, SdtType.Checkbox, MarkupLevel.Inline)
        {
            Tag = "Berichtspflicht",
            Title = "Berichtspflicht",
            Checked = false
        };
        // No effect
        Builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;
        // Does not work until filled
        SdtCheckBox.ContentsFont.Size = 20;
        // Insert content control into the document 
        Builder.InsertNode(SdtCheckBox);
        // Works for empty checkboxes
        ((Run)SdtCheckBox.FirstChild).Font.Size = 20;
        var x = (Paragraph) SdtCheckBox.ParentNode;
        x.ParagraphFormat.Alignment = ParagraphAlignment.Center;
    }

What i my failure?

Thanks in advance

Holger

@Holger_Schulze,

To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your simplified input Word document
  • Aspose.Words 19.4 generated output document showing the undesired behavior
  • Your expected document showing the correct output. You can create expected document by using MS Word.
  • Please also create a simplified standalone console application (source code without compilation errors) that helps us to reproduce your current problem on our end and attach it here for testing. Please do not include Aspose.Words DLL files in it to reduce the file size.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

Hello,

I do not have any specific Input Document. I am generating a new Document from scratch. All I want to know is how to insert a StructuredDocumentTag CheckBox centered in a cell with a specific fontsize (20 points).

@Holger_Schulze,

Please see these input/output documents (Docs.zip (18.8 KB)) and try running the following code:

Document doc = new Document("E:\\Temp\\in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);

Table table = doc.FirstSection.Body.Tables[0];
Cell cell = table.Rows[1].FirstCell;
cell.CellFormat.VerticalAlignment = CellVerticalAlignment.Center;
cell.FirstParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;

builder.MoveTo(cell.FirstParagraph);

StructuredDocumentTag checkbox = new StructuredDocumentTag(doc, SdtType.Checkbox, MarkupLevel.Inline);
checkbox.Checked = true;
checkbox.Tag = "sdt1";
checkbox.ContentsFont.Bold = true;
checkbox.ContentsFont.Name = "Arial";
checkbox.ContentsFont.Color = Color.Red;

builder.InsertNode(checkbox);

doc.Save("E:\\Temp\\19.4.docx");

Hope, this helps.