Dokumenta rediģēšana digitālo failu modificēšanas kontekstā attiecas uz teksta, attēlu vai citu dokumenta elementu izmaiņu procesu. Datu failu digitālo rediģēšanu varētu izmantot, lai uzlabotu satura precizitāti un skaidrību, pievienotu labojumus esošajam saturam, padarītu dokumentu vieglāk lasāmu un daudz ko citu. Arvien pieaugot dažādu veidu digitālo dokumentu izmantošanai, nepieciešamība tos rediģēt elektroniski kļūst arvien aktuālāka.
Spēja elektroniski rediģēt digitālos dokumentus ir kļuvusi par būtisku prasmi ikvienam, kas strādā ar dokumentiem. Zinot, kā ātri un precīzi rediģēt PDF, Microsoft Office un citus datu failus, var ietaupīt laiku. Šim nolūkam varat izmantot GroupDocs.Editor API, kas atbalsta dažādu populāru datu failu formātu, piemēram, PDF, Word, Excel, PowerPoint, OpenDocument, RTF, teksta, HTML, e-grāmatu un daudzu citu rediģēšanu .NET un Java platformās. .
Lai sāktu rediģēt dokumentus .NET vai Java, vispirms būs jāinstalē vajadzīgā GroupDocs.Editor versija. Lūdzu, skatiet norādījumus, kas sniegti nākamajās sadaļās, lai pareizi iestatītu GroupDocs.Editor .NET vai Java.
Lūdzu, lejupielādējiet DLL vai MSI instalēšanas programmu no lejupielādes sadaļas vai izmantojiet NuGet, lai instalētu API. Varat arī izmantot pakotņu pārvaldnieka konsoli:
Lai saņemtu papildu palīdzību saistībā ar instalēšanu, lūdzu, skatiet šo rokasgrāmatu.
Java versijai varat lejupielādēt JAR failu no lejupielādes sadaļas vai pievienot tālāk norādītās repozitorija konfigurācijas un atkarība no jūsu (uz Maven balstītām) Java lietotnēm:
<repository>
<id>GroupDocsJavaAPI</id>
<name>GroupDocs Java API</name>
<url>https://repository.groupdocs.com/repo/</url>
</repository>
<dependency>
<groupId>com.groupdocs</groupId>
<artifactId>groupdocs-editor</artifactId>
<version>20.11</version>
</dependency>
Ja nepieciešama plašāka informācija, lūdzu, pārskatiet šo instalēšanas rokasgrāmatu.
Tagad, kad esat pabeidzis pareizās API versijas iestatīšanu, pārbaudīsim dažus plaši izmantotos gadījumu scenārijus vairāku formātu dokumentu rediģēšanai.
PDF formāts ir populārs failu veids, ko izmanto dokumentiem, pārskatiem un citam digitālam saturam. Tas apzīmē Portable Document Format un tiek plaši izmantots, jo tas spēj ražot augstas kvalitātes dokumentus, kurus ir viegli koplietot. Tas atšķiras no citiem populāriem datu failu formātiem, jo piedāvā fiksētu izkārtojumu un saglabā to pašu formatējumu un izkārtojumu neatkarīgi no ierīces un operētājsistēmas, kurā to lasāt vai skatāt.
Bet ko darīt, ja jums ir jāveic izmaiņas PDF dokumentā? PDF failu rediģēšana var būt grūts process, taču tam nav jābūt, ja izmantojat GroupDocs.Editor for .NET API. Šī API ļauj rediģēt PDF failus, izmantojot WYSIWYG redaktoru tāpat kā jebkuru citu dokumentu. Pašlaik PDF rediģēšana tiek atbalstīta tikai GroupDocs.Editor API .NET versijā, nevis Java versijā.
Lūdzu, izmantojiet šo kodu, lai ielādētu, rediģētu un pēc tam saglabātu PDF failu .NET:
//1. Simple preparations of input data
const string filename = "sample.pdf";
const string password = "password";
string inputPath = System.IO.Path.Combine(Common.TestHelper.PdfFolder, filename);
//2. Create a load options class with password
GroupDocs.Editor.Options.PdfLoadOptions loadOptions = new PdfLoadOptions();
loadOptions.Password = password;
//3. Create edit options and tune/adjust if necessary
GroupDocs.Editor.Options.PdfEditOptions editOptions = new PdfEditOptions();
editOptions.EnablePagination = true; //Enable pagination for per-page processing in WYSIWYG-editor
editOptions.Pages = PageRange.FromStartPageTillEnd(3); //Edit not all pages, but starting from 3rd and till the end
//4. Create an Editor instance, load a document
GroupDocs.Editor.Editor editor = new Editor(inputPath, delegate () { return loadOptions; });
//5. Edit a document and generate EditableDocument
GroupDocs.Editor.EditableDocument originalDoc = editor.Edit(editOptions);
//6. Generate HTML/CSS, send it to WYSIWYG, edit there, and obtain edited version
string originalContent = originalDoc.GetEmbeddedHtml();
string editedContent = originalContent.Replace(".NET Framework", "I love Java!!!");
//7. Generate EditableDocument from edited content
EditableDocument editedDoc = EditableDocument.FromMarkup(editedContent, null);
//8. Create and adjust save options
GroupDocs.Editor.Options.PdfSaveOptions saveOptions = new PdfSaveOptions();
saveOptions.Compliance = PdfCompliance.Pdf20;
//9. Save to a file or a stream
string outputPath = System.IO.Path.Combine(Common.TestHelper.OutputFolder, filename);
editor.Save(editedDoc, outputPath, saveOptions);
//10. Don't forget to dispose all resources
originalDoc.Dispose();
editedDoc.Dispose();
editor.Dispose(); Microsoft Word, Excel un PowerPoint ir plaši izmantoti formāti attiecīgi dokumentu, izklājlapu un prezentāciju izveidei. Tie tiek izmantoti kā standarta formāti lielākajā daļā uzņēmumu un organizāciju, un tie ir būtiski rīki ikvienam, kas vēlas efektīvi kārtot, analizēt un prezentēt datus.
Vai vēlaties programmatiski rediģēt kādu no šiem dokumentu formātiem .NET vai Java? Ja jā, varat izmantot GroupDocs.Editor API un rediģēt Microsoft Word, Excel un PowerPoint dokumentus, un, lai to izdarītu, jūsu sistēmā pat nav nepieciešams instalēt Microsoft Office.
Lai rediģētu Word dokumentus (DOCX) .NET, lūdzu, izmantojiet šo kodu:
using (FileStream fs = File.OpenRead("filepath/document.docx"))
{
// Load Document
Options.WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
loadOptions.Password = "password-if-any";
// Edit Document
using (Editor editor = new Editor(delegate { return fs; }, delegate { return loadOptions; }))
{
Options.WordProcessingEditOptions editOptions = new WordProcessingEditOptions();
editOptions.FontExtraction = FontExtractionOptions.ExtractEmbeddedWithoutSystem;
editOptions.EnableLanguageInformation = true;
editOptions.EnablePagination = true;
using (EditableDocument beforeEdit = editor.Edit(editOptions))
{
string originalContent = beforeEdit.GetContent();
List allResources = beforeEdit.AllResources;
string editedContent = originalContent.Replace("document", "edited document");
// Save Document
using (EditableDocument afterEdit = EditableDocument.FromMarkup(editedContent, allResources))
{
WordProcessingFormats docxFormat = WordProcessingFormats.Docx;
Options.WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(docxFormat);
saveOptions.EnablePagination = true;
saveOptions.Locale = System.Globalization.CultureInfo.GetCultureInfo("en-US");
saveOptions.OptimizeMemoryUsage = true;
saveOptions.Password = "password";
saveOptions.Protection = new WordProcessingProtection(WordProcessingProtectionType.ReadOnly, "write_password");
using (FileStream outputStream = File.Create("filepath/editedDocument.docx"))
{
editor.Save(afterEdit, outputStream, saveOptions);
}
}
}
}
} Lai rediģētu Word dokumentus Java valodā, lūdzu, izmantojiet šo kodu:
// Edit the Word DOC/DOCX documents in Java
Options.WordProcessingLoadOptions loadOptions = new WordProcessingLoadOptions();
loadOptions.setPassword("password-if-any");
Editor editor = new Editor("path/document.docx", loadOptions);
EditableDocument defaultWordProcessingDoc = editor.edit();
// Either edit using any WYSIWYG editor or edit programmatically
String allEmbeddedInsideString = defaultWordProcessingDoc.getEmbeddedHtml();
String allEmbeddedInsideStringEdited = allEmbeddedInsideString.replace("document", "edited document");
// Save the edited document
EditableDocument editedDoc = EditableDocument.fromMarkup(allEmbeddedInsideStringEdited, null);
WordProcessingSaveOptions saveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docx);
editor.save(editedDoc, "path/edited-document.docx", saveOptions); Varat rediģēt Excel dokumentus .NET, izmantojot šādu C# kodu:
Options.SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.Password = "password";
// Load the Spreadsheet
Editor editor = new Editor("path/spreadsheet.xlsx", delegate { return loadOptions; });
// Get 1st tab of the Spreadsheet
SpreadsheetEditOptions sheetTab1EditOptions = new SpreadsheetEditOptions();
sheetTab1EditOptions.WorksheetIndex = 0; // first worksheet
// Obtain HTML markup from some EditableDocument instance
EditableDocument firstTab = editor.Edit(sheetTab1EditOptions);
string bodyContent = firstTab.GetBodyContent(); // HTML markup from inside the HTML -> BODY element
string allContent = firstTab.GetContent(); // Full HTML markup of all document, with HTML -> HEAD header and all its content
List onlyImages = firstTab.Images;
List allResourcesTogether = firstTab.AllResources;
string editedContent = allContent.Replace("Company Name", "New Company Name");
EditableDocument afterEdit = EditableDocument.FromMarkup(editedContent, allResourcesTogether);
// Create save options
SpreadsheetFormats xlsxFormat = SpreadsheetFormats.Xlsx;
Options.SpreadsheetSaveOptions saveOptions = new SpreadsheetSaveOptions(SpreadsheetFormats.Xlsx);
// Set new opening password
saveOptions.Password = "newPassword";
saveOptions.WorksheetProtection = new WorksheetProtection(WorksheetProtectionType.All, "WriteProtectionPassword");
// Create output stream
using (FileStream outputStream = File.Create("path/editedSpreadsheet.xlsx"))
{
editor.Save(afterEdit, outputStream, saveOptions);
} Lai rediģētu Excel izklājlapas Java valodā, varat izmantot šo koda fragmentu:
// Edit the Excel XLS/XLSX documents in Java
SpreadsheetLoadOptions loadOptions = new SpreadsheetLoadOptions();
loadOptions.setPassword("password-if-any");
// Loading Spreadsheet
Editor editor = new Editor("path/sample_sheet.xlsx", loadOptions);
// Edit 1st tab of the Spreadsheet
SpreadsheetEditOptions editOptions = new SpreadsheetEditOptions();
editOptions.setWorksheetIndex(0); // index is 0-based, so this is 1st tab
EditableDocument firstTab = editor.edit(editOptions);
String bodyContent = firstTab.getBodyContent();
String allContent = firstTab.getContent();
List onlyImages = firstTab.getImages();
List allResourcesTogether = firstTab.getAllResources();
String editedSheetContent = allContent.replace("Old Company Name","New Company Name");
EditableDocument editedDoc = EditableDocument.fromMarkup(editedSheetContent, null);
SpreadsheetSaveOptions saveOptions = new SpreadsheetSaveOptions(SpreadsheetFormats.Xlsx);
saveOptions.setPassword("new-password");
editor.save(editedDoc, "path/edited_spreadsheet.xlsx", saveOptions);
firstTab.dispose();
editor.dispose()
Līdzīgi varat rediģēt arī PowerPoint prezentācijas, izmantojot GroupDocs.Editor API. Lūdzu, pārbaudiet .NET un Java rediģēšanas rokasgrāmatas, lai saņemtu papildu palīdzību.
Teksta faili (apzīmēti ar TXT) ir viens no visbiežāk izmantotajiem failu formātiem, jo tie ir viegli, vienkārši un viegli izveidojami un kopīgojami. Tie tiek izmantoti dažādos veidos, sākot no koda rakstīšanas līdz vienkāršu, tikai teksta dokumentu izveidei. Teksta dokumenti nesatur teksta formatējumu, attēlus, veidlapas, tabulas vai citus bagātināta teksta elementus.
GroupDocs.Editor API atbalsta teksta failu rediģēšanu .NET un Java platformās. Varat integrēt teksta dokumentu rediģēšanas līdzekļus esošajā lietojumprogrammā un uzlabot tās iespējas vai šim nolūkam izveidot savu teksta redaktora lietotni.
Tālāk norādīto koda paraugu var izmantot, lai rediģētu teksta failus .NET. Rediģēto failu var saglabāt TXT un tekstapstrādes (DOCM) formātos:
//Load the text file
string inputTxtPath = "C://input/file.txt";
Editor editor = new Editor(inputTxtPath);
TextEditOptions editOptions = new TextEditOptions();
editOptions.Encoding = System.Text.Encoding.UTF8;
editOptions.RecognizeLists = true;
editOptions.LeadingSpaces = TextLeadingSpacesOptions.ConvertToIndent;
editOptions.TrailingSpaces = TextTrailingSpacesOptions.Trim;
editOptions.Direction = TextDirection.Auto;
EditableDocument beforeEdit = editor.Edit(editOptions); // Create EditableDocument instance
string originalTextContent = beforeEdit.GetContent(); // Get HTML content
string updatedTextContent = originalTextContent.Replace("text", "EDITED text"); // Edit the content
List allResources = beforeEdit.AllResources; // Get resources (only one stylesheet in this case)
//Finally, create new EditableDocument
EditableDocument afterEdit = EditableDocument.FromMarkup(updatedTextContent, allResources);\
//Save the edited document to TXT and DOCM format
TextSaveOptions txtSaveOptions = new TextSaveOptions();
txtSaveOptions.AddBidiMarks = true;
txtSaveOptions.PreserveTableLayout = true;
WordProcessingSaveOptions wordSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docm);
string outputTxtPath = "C:\output\document.txt";
string outputWordPath = "C:\output\document.docm";
editor.Save(afterEdit, outputTxtPath, txtSaveOptions);
editor.Save(afterEdit, outputWordPath, wordSaveOptions); Lai rediģētu teksta failus Java, varat izmantot tālāk norādīto kodu. Pēc tam varat saglabāt modificēto dokumentu TXT vai Word (DOCM) faila formātā:
// Loading the text document
String inputTxtPath = "C://input//file.txt";
Editor editor = new Editor(inputTxtPath);
TextEditOptions editOptions = new TextEditOptions();
editOptions.setEncoding(StandardCharsets.UTF_8);
editOptions.setRecognizeLists(true);
editOptions.setLeadingSpaces(TextLeadingSpacesOptions.ConvertToIndent);
editOptions.setTrailingSpaces(TextTrailingSpacesOptions.Trim);
editOptions.setDirection(TextDirection.Auto);
EditableDocument beforeEdit = editor.edit(editOptions); // Create EditableDocument instance
String originalTextContent = beforeEdit.getContent(); // Get HTML content
String updatedTextContent = originalTextContent.replace("text", "EDITED text"); // Edit the content
List allResources = beforeEdit.getAllResources(); // Get resources (only one stylesheet actually in this case)
//Finally, create new EditableDocument
EditableDocument afterEdit = EditableDocument.fromMarkup(updatedTextContent, allResources);
//Saving the modified file to TXT and DOCM formats
TextSaveOptions txtSaveOptions = new TextSaveOptions();
txtSaveOptions.setAddBidiMarks(true);
txtSaveOptions.setPreserveTableLayout(true);
WordProcessingSaveOptions wordSaveOptions = new WordProcessingSaveOptions(WordProcessingFormats.Docm);
String outputTxtPath = "C:\\output\\document.txt";
String outputWordPath = "C:\\output\\document.docm";
editor.save(afterEdit, outputTxtPath, txtSaveOptions);
editor.save(afterEdit, outputWordPath, wordSaveOptions); E-pasta dokumenti ir faili, kas satur e-pasta ziņojuma saturu, tostarp ziņojuma pamattekstu un visus pielikumus. Šie faili parasti tiek izmantoti e-pasta ziņojumu pārsūtīšanai starp dažādiem e-pasta klientiem vai to glabāšanai standarta formātā. Tos izmanto dažādi e-pasta klienti, piemēram, Microsoft Outlook, Apple Mail un Mozilla Thunderbird. Šie dokumenti ir neatņemama daļa no tā, kā mēs savā starpā sazināmies digitālajā laikmetā.
Pieaugot šo failu tipu izmantošanai, arī to rediģēšana kļūst izplatīta. Rediģēšanas procesa automatizācija var būt nenovērtējama neatkarīgi no tā, vai vēlaties integrēt procesu ar citu sistēmu vai iekļaut pielāgotu loģiku. GroupDocs.Editor API (.NET un Java) ļauj to izdarīt. Izmantojot šos API, varat rediģēt populāru formātu e-pasta dokumentus.
Ja vēlaties ielādēt, rediģēt un saglabāt e-pasta ziņojumu (MSG), lūdzu, izmantojiet šo C# kods:
//1. Prepare a sample file const string msgFilename = "ComplexExample.msg"; string msgInputPath = System.IO.Path.Combine(Common.TestHelper.EmailFolder, msgFilename); //2. Load to the Editor class Editor msgEditor = new Editor(msgInputPath); //3. Create edit options with all content Options.EmailEditOptions editOptions = new EmailEditOptions(MailMessageOutput.All); //4. Generate an editable document EditableDocument originalDoc = msgEditor.Edit(editOptions); //5. Emit HTML from EditableDocument, send it to the client-side, edit it there in WYSIWYG-editor (omitted here) string savedHtmlContent = originalDoc.GetEmbeddedHtml(); //6. Obtain edited content from the client-side and generate a new EditableDocument from it (omitted here) EditableDocument editedDoc = EditableDocument.FromMarkup(savedHtmlContent, null); //7. Create 1st save options EmailSaveOptions saveOptions1 = new EmailSaveOptions(MailMessageOutput.Common); //8. Create 2nd save options EmailSaveOptions saveOptions2 = new EmailSaveOptions(MailMessageOutput.Body | MailMessageOutput.Attachments); //9. Generate and save 1st output MSG to the file string outputMsgPath = System.IO.Path.Combine(Common.TestHelper.OutputFolder, "OutputFile.msg"); msgEditor.Save(editedDoc, outputMsgPath, saveOptions1); //10. Generate and save 2nd output MSG to the stream Stream outputMsgStream = File.Create(Path.Combine(Common.TestHelper.OutputFolder, "OutputStream.msg")); msgEditor.Save(editedDoc, outputMsgStream, saveOptions2); //11. Dispose all resources outputMsgStream.Dispose(); editedDoc.Dispose(); originalDoc.Dispose(); msgEditor.Dispose();
Lai ielādētu, rediģētu un saglabātu e-pasta ziņojumu failu (MSG), varat izmantot šo kodu. :
//1. Prepare a sample file String msgInputPath = "C:\ComplexExample.msg"; //2. Load to the Editor class Editor msgEditor = new Editor(msgInputPath); //3. Create edit options with all content EmailEditOptions editOptions = new EmailEditOptions(MailMessageOutput.All); //4. Generate an editable document EditableDocument originalDoc = msgEditor.edit(editOptions); //5. Emit HTML from EditableDocument, send it to the client-side, edit it there in WYSIWYG-editor (omitted here) String savedHtmlContent = originalDoc.getEmbeddedHtml(); //6. Obtain edited content from the client-side and generate a new EditableDocument from it (omitted here) EditableDocument editedDoc = EditableDocument.fromMarkup(savedHtmlContent, null); //7. Create 1st save options EmailSaveOptions saveOptions1 = new EmailSaveOptions(MailMessageOutput.Common); //8. Create 2nd save options EmailSaveOptions saveOptions2 = new EmailSaveOptions(MailMessageOutput.Body | MailMessageOutput.Attachments); //9. Generate and save 1st output MSG to the file String outputMsgPath = "C:\OutputFile.msg"; msgEditor.save(editedDoc, outputMsgPath, saveOptions1); //10. Generate and save 2nd output MSG to the stream Stream outputMsgStream = "C:\OutputStream.msg"; msgEditor.save(editedDoc, outputMsgStream, saveOptions2); //11. Dispose all resources outputMsgStream.dispose(); editedDoc.dispose(); originalDoc.dispose(); msgEditor.dispose();
Varat arī uzreiz rediģēt PDF, DOCX, XLSX, PPTX, ODT, ODS, RTF, TXT, CSV, XML, EPUB un daudzus citus dokumentus, izmantojot mūsu Bezmaksas dokumentu rediģēšanas lietotnes no jūsu izvēlētās ierīces, tāpēc, lūdzu, pārbaudiet tās.
Varat viegli eksportēt datus uz Microsoft Excel no dažādiem pieejamiem avotiem, piemēram, JSON un CSV.
Turpināt lasītJums ir vairākas Excel darbgrāmatas, un jūs vēlaties tās apvienot vienā failā pārskatu veidošanai vai datu glabāšanai vienuviet.
Turpināt lasītWord dokumentu, tostarp DOC vai DOCX, konvertēšana .NET ir ļoti izplatīta prasība
Turpināt lasīt