Skip to main content

Quick Reference Cheatsheet

๐Ÿšจ THE BIG THREE (Never Do This!)โ€‹

โŒ 1. Text Without Runโ€‹

<!-- WRONG -->
<w:p>
<w:t>Text</w:t>
</w:p>

<!-- CORRECT -->
<w:p>
<w:r><w:t>Text</w:t></w:r>
</w:p>

โŒ 2. Table Inside Runโ€‹

<!-- WRONG -->
<w:r>
<w:tbl>...</w:tbl>
</w:r>

<!-- CORRECT -->
<w:body>
<w:tbl>...</w:tbl>
</w:body>

โŒ 3. SDT Inside Runโ€‹

<!-- WRONG -->
<w:r>
<w:sdt>...</w:sdt>
</w:r>

<!-- CORRECT (Block SDT) -->
<w:body>
<w:sdt>...</w:sdt>
</w:body>

<!-- OR (Inline SDT) -->
<w:p>
<w:sdt>
<w:sdtContent>
<w:r><w:t>Text</w:t></w:r>
</w:sdtContent>
</w:sdt>
</w:p>

Element Hierarchyโ€‹

w:document
โ””โ”€ w:body
โ”œโ”€ w:p (paragraph)
โ”‚ โ”œโ”€ w:pPr (properties)
โ”‚ โ””โ”€ w:r (run)
โ”‚ โ”œโ”€ w:rPr (properties)
โ”‚ โ””โ”€ w:t (text)
โ”‚
โ”œโ”€ w:tbl (table)
โ”‚ โ”œโ”€ w:tblPr (properties)
โ”‚ โ”œโ”€ w:tblGrid (grid definition)
โ”‚ โ””โ”€ w:tr (row)
โ”‚ โ”œโ”€ w:trPr (properties)
โ”‚ โ””โ”€ w:tc (cell)
โ”‚ โ”œโ”€ w:tcPr (properties)
โ”‚ โ””โ”€ w:p (REQUIRED)
โ”‚
โ””โ”€ w:sdt (content control, block-level)
โ”œโ”€ w:sdtPr (properties)
โ””โ”€ w:sdtContent (content)

Unit Conversionsโ€‹

UnitConversionExample
Twips โ†’ PointsDivide by 201440 twips = 72 pt (1 inch)
Half-points โ†’ PointsDivide by 2w:sz="24" = 12pt
EMUs โ†’ PointsDivide by 12700914400 EMUs = 72 pt (1 inch)
Percentage5000 = 100%w:w="2500" = 50%
Inches โ†’ TwipsMultiply by 14401 inch = 1440 twips
Inches โ†’ PointsMultiply by 721 inch = 72 points

Common Elementsโ€‹

Paragraphโ€‹

<w:p>
<w:pPr>
<w:pStyle w:val="Normal"/>
<w:jc w:val="center"/>
<w:spacing w:before="120" w:after="120"/>
</w:pPr>
<w:r>
<w:rPr>
<w:b/>
<w:sz w:val="24"/>
</w:rPr>
<w:t>Text</w:t>
</w:r>
</w:p>

Tableโ€‹

<w:tbl>
<w:tblPr>
<w:tblW w:w="5000" w:type="pct"/>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="3000"/>
</w:tblGrid>
<w:tr>
<w:tc>
<w:tcPr>
<w:tcW w:w="3000" w:type="dxa"/>
</w:tcPr>
<w:p>...</w:p>
</w:tc>
</w:tr>
</w:tbl>

Content Control (Block)โ€‹

<w:sdt>
<w:sdtPr>
<w:tag w:val="FieldName"/>
<w:alias w:val="Display Name"/>
</w:sdtPr>
<w:sdtContent>
<w:p>...</w:p>
</w:sdtContent>
</w:sdt>

Text Formattingโ€‹

PropertyXMLCode
Bold<w:b/>new Bold()
Italic<w:i/>new Italic()
Underline<w:u w:val="single"/>new Underline { Val = UnderlineValues.Single }
Font<w:rFonts w:ascii="Arial"/>new RunFonts { Ascii = "Arial" }
Font Size<w:sz w:val="24"/>new FontSize { Val = "24" } (12pt)
Color<w:color w:val="FF0000"/>new Color { Val = "FF0000" }
Highlight<w:highlight w:val="yellow"/>new Highlight { Val = HighlightColorValues.Yellow }

Paragraph Formattingโ€‹

PropertyXMLCode
Alignment<w:jc w:val="center"/>new Justification { Val = JustificationValues.Center }
Before Spacing<w:spacing w:before="240"/>new SpacingBetweenLines { Before = "240" }
After Spacing<w:spacing w:after="120"/>new SpacingBetweenLines { After = "120" }
Line Spacing<w:spacing w:line="276" w:lineRule="auto"/>new SpacingBetweenLines { Line = "276", LineRule = LineSpacingRuleValues.Auto }
Left Indent<w:ind w:left="720"/>new Indentation { Left = "720" }
First Line Indent<w:ind w:firstLine="360"/>new Indentation { FirstLine = "360" }

Table Propertiesโ€‹

PropertyXMLCode
Width (%)<w:tblW w:w="5000" w:type="pct"/>new TableWidth { Width = "5000", Type = TableWidthUnitValues.Pct }
Width (abs)<w:tblW w:w="5000" w:type="dxa"/>new TableWidth { Width = "5000", Type = TableWidthUnitValues.Dxa }
Alignment<w:jc w:val="center"/>new TableJustification { Val = TableRowAlignmentValues.Center }
Cell Span<w:gridSpan w:val="2"/>new GridSpan { Val = 2 }
V-Merge Start<w:vMerge w:val="restart"/>new VerticalMerge { Val = MergedCellValues.Restart }
V-Merge Continue<w:vMerge w:val="continue"/>new VerticalMerge { Val = MergedCellValues.Continue }
Can't Split<w:cantSplit/>new CantSplit()

Border Stylesโ€‹

new TableBorders(
new TopBorder { Val = BorderValues.Single, Size = 4, Color = "000000" },
new BottomBorder { Val = BorderValues.Single, Size = 4, Color = "000000" },
new LeftBorder { Val = BorderValues.Single, Size = 4, Color = "000000" },
new RightBorder { Val = BorderValues.Single, Size = 4, Color = "000000" },
new InsideHorizontalBorder { Val = BorderValues.Single, Size = 4, Color = "000000" },
new InsideVerticalBorder { Val = BorderValues.Single, Size = 4, Color = "000000" }
)

Border Values:

  • Single - Single line
  • Double - Double line
  • Dotted - Dotted line
  • Dashed - Dashed line
  • None - No border

Size: Eighths of a point (4 = 0.5pt, 8 = 1pt)


Namespacesโ€‹

using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing; // w:
using DocumentFormat.OpenXml.Drawing; // a:
using DocumentFormat.OpenXml.Drawing.Wordprocessing; // wp:
using DocumentFormat.OpenXml.Drawing.Pictures; // pic:
PrefixNamespacePurpose
w:WordprocessingMLCore document elements
r:RelationshipsReferences between parts
wp:Drawing WordprocessingMLInline/anchored drawings
pic:PictureImages
a:DrawingGraphic properties
v:VMLLegacy shapes

OOXML โ†” SFDT Quick Mappingโ€‹

OOXMLSFDTNotes
w:pblock with inlinesParagraph
w:r + w:tinline with textText run
w:tbltableTable
w:trrowTable row
w:tccellTable cell
w:pPrparagraphFormatParagraph properties
w:rPrcharacterFormatCharacter properties
w:sz (half-pts)fontSize (pts)Font size: divide by 2
Spacing (twips)Spacing (pts)Divide by 20
w:drawingimageString (base64)Image

Common Code Patternsโ€‹

Create Documentโ€‹

using (var doc = WordprocessingDocument.Create(
filepath, WordprocessingDocumentType.Document))
{
var mainPart = doc.AddMainDocumentPart();
mainPart.Document = new Document();
var body = mainPart.Document.AppendChild(new Body());

// Add content

mainPart.Document.Save();
}

Add Paragraphโ€‹

var para = new Paragraph();
var run = new Run();
run.AppendChild(new Text("Hello World"));
para.AppendChild(run);
body.AppendChild(para);

Add Formatted Textโ€‹

var run = new Run();
var runProps = new RunProperties(
new Bold(),
new FontSize { Val = "28" },
new Color { Val = "FF0000" }
);
run.AppendChild(runProps);
run.AppendChild(new Text("Bold Red Text"));

Create Table Cellโ€‹

var cell = new TableCell();
cell.AppendChild(new TableCellProperties(
new TableCellWidth { Width = "3000", Type = TableWidthUnitValues.Dxa }
));
var para = new Paragraph(new Run(new Text("Cell content")));
cell.AppendChild(para);

Validationโ€‹

Open XML SDK Toolโ€‹

  1. Download from GitHub releases
  2. Open DOCX file
  3. Click "Validate"
  4. Review errors

Programmatic Validationโ€‹

using (var doc = WordprocessingDocument.Open("file.docx", false))
{
var validator = new OpenXmlValidator();
var errors = validator.Validate(doc);

foreach (var error in errors)
{
Console.WriteLine($"{error.Path}: {error.Description}");
}
}

File Structureโ€‹

document.docx (ZIP)
โ”œโ”€ [Content_Types].xml
โ”œโ”€ _rels/
โ”‚ โ””โ”€ .rels
โ”œโ”€ word/
โ”‚ โ”œโ”€ document.xml โ† Main content
โ”‚ โ”œโ”€ styles.xml โ† Styles
โ”‚ โ”œโ”€ numbering.xml โ† Lists
โ”‚ โ”œโ”€ settings.xml
โ”‚ โ”œโ”€ fontTable.xml
โ”‚ โ”œโ”€ _rels/
โ”‚ โ”‚ โ””โ”€ document.xml.rels โ† Relationships
โ”‚ โ””โ”€ media/
โ”‚ โ”œโ”€ image1.png
โ”‚ โ””โ”€ image2.jpg
โ””โ”€ docProps/
โ”œโ”€ app.xml
โ””โ”€ core.xml

AppraiSys Specificโ€‹

Default Stylesโ€‹

  • Normal - Base paragraph style
  • Heading1 - 16pt bold, centered
  • Heading2 - 14pt bold, left
  • NormalTable - Standard table
  • PropertyImagesTable - Photo gallery table
  • ImageLineSpacing1_15 - For image paragraphs

Standard Measurementsโ€‹

  • Font size: 11pt (22 half-points)
  • Line spacing: 1.15 (276 twips)
  • Cell margins: 108 twips left/right, 0 top/bottom
  • Page margins: 1 inch (1440 twips)

Content Control Tagsโ€‹

  • PropertyAddress
  • PropertyType
  • SubjectPropertyInfo
  • ComparablesTable
  • PropertyPhotos

Debugging Tipsโ€‹

Document Won't Openโ€‹

  1. Rename .docx to .zip
  2. Extract contents
  3. Check word/document.xml for XML errors
  4. Use OpenXML SDK tool

Images Missingโ€‹

  1. Check /word/media/ folder exists
  2. Check document.xml.rels has image relationships
  3. Verify relationship IDs match

Formatting Lostโ€‹

  1. Check styles.xml exists
  2. Verify style IDs match in document.xml
  3. Ensure w:pStyle or w:rStyle references valid style

Error Messagesโ€‹

ErrorCauseFix
"Element X cannot be child of Y"Wrong nestingCheck hierarchy rules
"Required element missing"Missing required childAdd required element
"Invalid attribute value"Wrong value typeCheck valid values
"Relationship not found"Missing .rels entryAdd relationship

Quick Formulasโ€‹

Points to Twips:    points ร— 20
Twips to Points: twips รท 20
Half-pts to Points: halfPoints รท 2
Points to Half-pts: points ร— 2
EMUs to Points: emus รท 12700
Inches to Twips: inches ร— 1440
Inches to Points: inches ร— 72
Percentage (width): (percent รท 100) ร— 5000

Resourcesโ€‹


๐Ÿ’ก Print this page and keep it at your desk for quick reference!