Edit document

This article describes how to open for editing a previously loaded document, which options should be applied, and how to send document content to the WYSIWYG HTML-editor or any other editing application.

When document is loaded into the instance of the Editor class, it is possible to open it for editing. In terms of GroupDocs.Editor, open a document for edit implies creating an instance of EditableDocument class by calling an Editor.Edit() instance method. There are two overloads of the Edit method. First one obtains a single parameter — inheritor of IEditOptions interface.
Each format family has its own implementation of IEditOptions interface. They are listed in the table below.

Format familyExample formatsEdit options class
WordProcessingDOC, DOCX, DOCM, DOT, ODTWordProcessingEditOptions
SpreadsheetXLS, XLSX, XLSM, XLSBSpreadsheetEditOptions
Delimiter-Separated Values (DSV)CSV, TSVDelimitedTextEditOptions
PresentationPPT, PPTX, PPS, POTPresentationEditOptions
Plain Text documentsTXTTextEditOptions
Fixed-layout formatPDFPdfEditOptions
Fixed-layout formatXPS (including OpenXPS)XpsEditOptions
XMLAny XML-based format like CSPROJ, SVG, and so onXmlEditOptions
eBookMOBI, AZW3, ePubEbookEditOptions
EmailEML, EMLX, TNEF, MSG, HTML, MHTML, ICS, VCF, PST, MBOX, OFTEmailEditOptions

Second overload is parameterless — it chooses the most appropriate default edit options based on input document format.

EditableDocument instance holds a version of input document, converted to internal intermediate format according to edit options. When it is ready, it can emit HTML, CSS and other appropriate content, that can be passed directly to the WYSIWYG-editor. This is demonstrated below.

string inputFilePath = "C:\\input_path\\document.docx"; //path to some document
Editor editor = new Editor(inputFilePath, new WordProcessingLoadOptions());
EditableDocument openedDocument = editor.Edit();//with default edit options

WordProcessingEditOptions editOptions = new WordProcessingEditOptions();
editOptions.EnableLanguageInformation = true;
editOptions.EnablePagination = true;

EditableDocument anotherOpenedDocument = editor.Edit(editOptions);

There can be generated several EditableDocument instances from a single Editor instance with different edit options. For example, for WordProcessing document, first time user can call Edit() method with disabled paged mode, and for the second time — with enabled. In other words, there can be generated several different EditableDocument representations of the single original document. Other example — there can be multiple EditableDocument instances for a single input Spreadsheet document, where each instance represents different tab of the Spreadsheet document. Such example is shown below.

string inputXlsxPath = "C://input/spreadsheet.xlsx";
Editor editor = new Editor(inputXlsxPath, new SpreadsheetLoadOptions());

SpreadsheetEditOptions editOptions1 = new SpreadsheetEditOptions();
editOptions1.WorksheetIndex = 0;//index is 0-based, so this is 1st tab
editOptions1.ExcludeHiddenWorksheets = true;
  
SpreadsheetEditOptions editOptions2 = new SpreadsheetEditOptions();
editOptions2.WorksheetIndex = 1;//index is 0-based, so this is 2nd tab
editOptions2.ExcludeHiddenWorksheets = false;
  
EditableDocument firstTab = editor.Edit(editOptions1);
EditableDocument secondTab = editor.Edit(editOptions2);

When EditableDocument instance is ready, it can emit HTML-markup, CSS-markup and other resources in different forms for passing them to the client-side WYSIWYG HTML-editor or any other application, that can edit HTML documents. It is briefly shown in the example below.

EditableDocument document = editor.Edit();
string bodyContent = document.GetBodyContent();
List<IImageResource> onlyImages = document.Images;
List<IHtmlResource> allResourcesTogether = document.AllResources;

For more information about obtaining HTML markup and resources from EditableDocument please visit Get HTML markup in different forms, Working with resources, and Save HTML to folder articles.