Last active
May 15, 2024 04:50
-
-
Save fileformat-words/e603bfcb94ae8598b1eff9e18553cfe3 to your computer and use it in GitHub Desktop.
C# Create DOCX Roman and Alphabetic Paragraphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Create a document with roman+alphabetic paragraphs using FileFormat.Words (https://www.nuget.org/packages/FileFormat.Words) | |
// The resulting docx document should be like this: https://imgur.com/d7ywVPG | |
// Initialize docx document | |
FileFormat.Words.Document doc = new FileFormat.Words.Document(); | |
// Initialize document body | |
FileFormat.Words.Body body = new FileFormat.Words.Body(doc); | |
// Initialize a paragraph | |
FileFormat.Words.IElements.Paragraph para = new FileFormat.Words.IElements.Paragraph(); | |
// Add a run to paragraph | |
para.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = "This document is generated by FileFormat.Words." }); | |
// Append paragraph to the document body | |
body.AppendChild(para); | |
// Reset paragraph | |
para = new FileFormat.Words.IElements.Paragraph(); | |
// Add a run to paragraph | |
para.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = "Below are roman and alphabetic paragraphs:" }); | |
// Append paragraph to the document body | |
body.AppendChild(para); | |
// Reset paragraph | |
para = new FileFormat.Words.IElements.Paragraph { Style = "ListParagraph"}; | |
// Add a run to paragraph | |
para.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = "First roman at first level" }); | |
// Set roman numbering for the paragraph | |
para.IsRoman = true; | |
para.NumberingId = 1; | |
para.NumberingLevel = 1; | |
// Append paragraph to the document body | |
body.AppendChild(para); | |
// Reset paragraph | |
para = new FileFormat.Words.IElements.Paragraph { Style = "ListParagraph" }; | |
// Add a run to paragraph | |
para.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = "First alphabetic at second level" }); | |
// Set alphabetic numbering for the paragraph | |
para.IsAlphabeticNumber = true; | |
para.NumberingId = 1; | |
para.NumberingLevel = 2; | |
// Append paragraph to the document body | |
body.AppendChild(para); | |
// Reset paragraph | |
para = new FileFormat.Words.IElements.Paragraph { Style = "ListParagraph" }; | |
// Add a run to paragraph | |
para.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = "Second alphabetic at second level" }); | |
// Set alphabetic numbering for the paragraph | |
para.IsAlphabeticNumber = true; | |
para.NumberingId = 1; | |
para.NumberingLevel = 2; | |
// Append paragraph to the document body | |
body.AppendChild(para); | |
// Reset paragraph | |
para = new FileFormat.Words.IElements.Paragraph { Style = "ListParagraph" }; | |
// Add a run to paragraph | |
para.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = "Second roman at first level" }); | |
// Set roman numbering for the paragraph | |
para.IsRoman = true; | |
para.NumberingId = 1; | |
para.NumberingLevel = 1; | |
// Append paragraph to the document body | |
body.AppendChild(para); | |
// Reset paragraph | |
para = new FileFormat.Words.IElements.Paragraph(); | |
// Add a run to paragraph | |
para.AddRun(new FileFormat.Words.IElements.Run | |
{ Text = "The document ends here..." }); | |
// Append paragraph to the doucment body | |
body.AppendChild(para); | |
// Save docx document to the disk | |
doc.Save("RomanAlphabeticParas.docx"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment