Create a word processing document

  • OpenXML SDK
  • Spire.Doc
  • Download Sample Code

class Program
{
static void Main(string[] args)
{
	CreateWordprocessingDocument("Create a word processing document.doc");
}
public static void CreateWordprocessingDocument(string filepath)
{
	// Create a document by supplying the filepath.
	using (WordprocessingDocument wordDocument =
		WordprocessingDocument.Create(filepath, WordprocessingDocumentType.Document))
	{
		// Add a main document part.
		MainDocumentPart mainPart = wordDocument.AddMainDocumentPart();

		// Create the document structure and add some text.
		mainPart.Document = new Document();
		Body body = mainPart.Document.AppendChild(new Body());
		Paragraph para = body.AppendChild(new Paragraph());
		Run run = para.AppendChild(new Run());
		run.AppendChild(new Text("Create text in body - CreateWordprocessingDocument"));
	}
}
}

class Program
    {
        static void Main(string[] args)
        {
            CreateDocument("Invoice.docx");
        }
        public static void CreateDocument(string filepath)
        {
            Document document = new Document();
            Section section = document.AddSection();
            Documents.Paragraph para = section.AddParagraph();
            para.AppendText("SpireDoc");
            document.SaveToFile(filepath, FileFormat.Docx);
        }
    }