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
XMLAny XML-based format like CSPROJ, SVG, and so onXmlEditOptions

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();

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.setWorksheetIndex(0);//index is 0-based, so this is 1st tab

SpreadsheetEditOptions editOptions2 = new SpreadsheetEditOptions();
editOptions2.setWorksheetIndex(1);//index is 0-based, so this is 2nd tab

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.getImages();
List<IHtmlResource> allResourcesTogether = document.getAllResources();

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.