Create and save new document.
using Sohiso.Word;
//Create a new document
WordDocument doc = new();
//Save to file
doc.Save("new_document.docx");
Open existing document.
using Sohiso.Word;
//Open an existing document
WordDocument doc = new("path_to_existing_file.docx");
//Save document
doc.Save();
Add a paragraph to a document.
using Sohiso.Word;
using Sohiso.Word.Documents;
WordDocument doc = new();
//Create a paragraph
Paragraph paragraph = new();
//Append paragraph to the document body
doc.DocumentBody.AppendParagraph(paragraph);
doc.Save("new_document.docx");
using Sohiso.Word;
using Sohiso.Word.Documents;
WordDocument doc = new();
//Create and append a paragraph to the document body
Paragraph paragraph = doc.DocumentBody.NewParagraph();
doc.Save("new_document.docx");
Add text to a paragraph.
using Sohiso.Word;
using Sohiso.Word.Documents;
using Sohiso.Word.Enums;
WordDocument doc = new();
//Create and append a paragraph to the document body
var paragraph = doc.DocumentBody.NewParagraph();
//Add bold text to paragraph
paragraph.AddText("Hello World!", FontStyle.Bold);
doc.Save("new_document.docx");
Add a table to a document.
using Sohiso.Word;
using Sohiso.Word.Tables;
using Sohiso.Word.Units;
WordDocument doc = new();
//Create a table (number of row, list of table column widths)
Table table = new(6, new List<ILengthUnit> { InchUnit.OneInch, InchUnit.FromDouble(2), MillimeterUnit.FromDouble(100) });
//Append table to the document body
doc.DocumentBody.AppendTable(table);
doc.Save("new_document.docx");
using Sohiso.Word;
using Sohiso.Word.Tables;
WordDocument doc = new();
//Create (row count, column count) and append a table to the document body
Table table = doc.DocumentBody.NewTable(8, 4);
doc.Save("new_document.docx");
Add an image to a paragraph.
using Sohiso.Word;
using Sohiso.Word.Documents;
using Sohiso.Word.Drawings;
WordDocument doc = new();
var paragraph = doc.DocumentBody.NewParagraph();
//Create image from file and add it to the paragraph
Image image = new("path_to_image.jpg");
paragraph.AddImage(image);
doc.Save("new_document.docx");