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 family | Example formats | Edit options class |
---|---|---|
WordProcessing | DOC, DOCX, DOCM, DOT, ODT | WordProcessingEditOptions |
Spreadsheet | XLS, XLSX, XLSM, XLSB | SpreadsheetEditOptions |
Delimiter-Separated Values (DSV) | CSV, TSV | DelimitedTextEditOptions |
Presentation | PPT, PPTX, PPS, POT | PresentationEditOptions |
Plain Text documents | TXT | TextEditOptions |
XML | Any XML-based format like CSPROJ, SVG, and so on | XmlEditOptions |
Mobi | Any Mobi E-book | MobiEditOptions |
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, delegate { return 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, delegate { return 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.
More resources
Advanced Usage Topics
To learn more about document viewing features, please refer to the advanced usage section.
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Editor for .NET examples, plugins, and showcase
- GroupDocs.Editor for Java examples, plugins, and showcase
- Document Editor for .NET MVC UI Example
- Document Editor for .NET App WebForms UI Modern Example
- Document Editor for Java App Dropwizard UI Modern Example
- Document Editor for Java Spring UI Example
Free Online App
Along with full-featured .NET library we provide simple, but powerful free Apps.
You are welcome to edit your Microsoft Word (DOC, DOCX, RTF etc.), Microsoft Excel (XLS, XLSX, CSV etc.), Open Document (ODT, OTT, ODS) and other documents with free to use online GroupDocs Editor App.