Chỉnh sửa tài liệu trong bối cảnh sửa đổi các tệp kỹ thuật số của bạn đề cập đến quá trình thay đổi văn bản, hình ảnh hoặc các thành phần khác trong tài liệu. Chỉnh sửa kỹ thuật số các tệp dữ liệu có thể được sử dụng để cải thiện độ chính xác và rõ ràng của nội dung, thêm các chỉnh sửa cho nội dung hiện có, làm cho tài liệu dễ đọc hơn và hơn thế nữa. Với việc sử dụng ngày càng nhiều các loại tài liệu kỹ thuật số khác nhau, nhu cầu chỉnh sửa chúng bằng phương pháp điện tử ngày càng trở nên quan trọng.
Khả năng chỉnh sửa tài liệu kỹ thuật số bằng điện tử đã trở thành một kỹ năng cần thiết cho bất kỳ ai làm việc với tài liệu. Biết cách chỉnh sửa PDF, Microsoft Office và các tệp dữ liệu khác một cách nhanh chóng và chính xác có thể là một cách tiết kiệm thời gian tuyệt vời. Với mục đích này, bạn có thể sử dụng API GroupDocs.Editor hỗ trợ chỉnh sửa một loạt định dạng tệp dữ liệu phổ biến như PDF, Word, Excel, PowerPoint, OpenDocument, RTF, Văn bản, HTML, sách điện tử và nhiều định dạng khác trên nền tảng .NET và Java .
Để bắt đầu chỉnh sửa tài liệu của bạn bằng .NET hoặc Java, trước tiên bạn cần cài đặt phiên bản GroupDocs.Editor được yêu cầu. Vui lòng tham khảo hướng dẫn được chia sẻ trong các phần sau để thiết lập đúng GroupDocs.Editor cho .NET hoặc Java.
Vui lòng tải xuống trình cài đặt DLL hoặc MSI từ phần tải xuống hoặc sử dụng NuGet để cài đặt API. Bạn cũng có thể sử dụng Bảng điều khiển quản lý gói:
Để được trợ giúp thêm về cài đặt, vui lòng xem hướng dẫn này.
Đối với phiên bản Java, bạn có thể tải xuống tệp JAR từ phần tải xuống hoặc thêm các cấu hình sau cho kho lưu trữ và phụ thuộc trong các ứng dụng Java (dựa trên Maven) của bạn:
<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>
Vui lòng xem lại hướng dẫn cài đặt này nếu bạn cần thêm thông tin.
Bây giờ bạn đã hoàn tất việc thiết lập đúng phiên bản API, hãy kiểm tra một số trường hợp được sử dụng rộng rãi để chỉnh sửa tài liệu đa định dạng của bạn.
Định dạng PDF là loại tệp phổ biến được sử dụng cho các tài liệu, báo cáo và nội dung kỹ thuật số khác. Nó là viết tắt của Định dạng Tài liệu Di động và được sử dụng rộng rãi nhờ khả năng tạo ra các tài liệu chất lượng cao, dễ chia sẻ. Nó khác với các định dạng tệp dữ liệu phổ biến khác vì nó cung cấp một bố cục cố định và nó duy trì cùng một định dạng và bố cục bất kể bạn đang đọc hoặc xem nó trên thiết bị và hệ điều hành nào.
Nhưng nếu bạn cần thay đổi tài liệu PDF thì sao? Chỉnh sửa tệp PDF có thể là một quá trình phức tạp nhưng không nhất thiết phải như vậy nếu bạn đang sử dụng GroupDocs.Editor cho .NET API. API này cho phép bạn chỉnh sửa các tệp PDF bằng trình chỉnh sửa WYSIWYG giống như bất kỳ tài liệu nào khác. Hiện tại, tính năng chỉnh sửa PDF chỉ được hỗ trợ trong phiên bản .NET của API GroupDocs.Editor chứ không phải trong phiên bản Java.
Vui lòng sử dụng mã sau để tải, chỉnh sửa và sau đó lưu tệp PDF trong .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 và PowerPoint là các định dạng được sử dụng rộng rãi để tạo tài liệu, bảng tính và bản trình bày tương ứng. Chúng được sử dụng làm định dạng tiêu chuẩn trong hầu hết các doanh nghiệp và tổ chức và là công cụ cần thiết cho bất kỳ ai muốn tổ chức, phân tích và trình bày dữ liệu một cách hiệu quả.
Bạn đang muốn chỉnh sửa theo chương trình bất kỳ định dạng tài liệu nào trong .NET hoặc Java? Nếu có, bạn có thể sử dụng API GroupDocs.Editor và chỉnh sửa tài liệu Microsoft Word, Excel và PowerPoint và thậm chí bạn không cần cài đặt Microsoft Office trên hệ thống của mình để thực hiện việc này.
Để chỉnh sửa tài liệu từ (DOCX) trong .NET, vui lòng sử dụng mã này:
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);
}
}
}
}
} Để chỉnh sửa tài liệu Word trong Java, vui lòng sử dụng mã sau:
// 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); Bạn có thể chỉnh sửa tài liệu Excel trong .NET bằng mã C# sau:
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);
} Để chỉnh sửa bảng tính Excel trong Java, bạn có thể sử dụng đoạn mã sau:
// 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()
Tương tự, bạn cũng có thể chỉnh sửa bản trình bày PowerPoint bằng API GroupDocs.Editor. Vui lòng kiểm tra .NET và Hướng dẫn chỉnh sửa Java để được trợ giúp thêm.
Tệp văn bản (ký hiệu là TXT) là một trong những định dạng tệp được sử dụng phổ biến nhất vì chúng nhẹ, đơn giản, dễ tạo và chia sẻ. Chúng được sử dụng theo nhiều cách khác nhau, từ viết mã đến tạo các tài liệu thuần túy, chỉ có văn bản. Tài liệu văn bản không chứa bất kỳ định dạng văn bản, hình ảnh, biểu mẫu, bảng hoặc bất kỳ thành phần văn bản có định dạng nào khác.
API GroupDocs.Editor hỗ trợ chỉnh sửa tệp văn bản trong nền tảng .NET và Java. Bạn có thể tích hợp các tính năng chỉnh sửa tài liệu văn bản vào ứng dụng hiện tại của mình và nâng cao khả năng của nó hoặc xây dựng ứng dụng soạn thảo văn bản của riêng bạn cho mục đích này.
Bạn có thể sử dụng mã mẫu dưới đây để chỉnh sửa tệp văn bản trong .NET. Tệp đã chỉnh sửa có thể được lưu ở định dạng TXT và xử lý văn bản (DOCM):
//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); Để chỉnh sửa tệp văn bản trong Java, bạn có thể sử dụng mã hiển thị bên dưới. Sau đó, bạn có thể lưu tài liệu đã sửa đổi thành định dạng tệp TXT hoặc Word (DOCM):
// 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); Tài liệu email là các tệp chứa nội dung của thư email, bao gồm nội dung thư và mọi tệp đính kèm. Các tệp này thường được sử dụng để chuyển thư email giữa các ứng dụng email khác nhau hoặc để lưu trữ chúng ở định dạng chuẩn. Chúng được sử dụng bởi nhiều ứng dụng email khác nhau như Microsoft Outlook, Apple Mail và Mozilla Thunderbird. Những tài liệu này là một phần không thể thiếu trong cách chúng ta giao tiếp với nhau trong thời đại kỹ thuật số.
Với sự gia tăng trong việc sử dụng các loại tệp này, việc chỉnh sửa chúng cũng trở nên phổ biến. Tự động hóa quy trình chỉnh sửa có thể là vô giá cho dù bạn muốn tích hợp quy trình với hệ thống khác hay kết hợp logic tùy chỉnh. API GroupDocs.Editor (dành cho .NET và Java) cho phép bạn làm điều đó. Bạn có thể chỉnh sửa các tài liệu email có định dạng phổ biến bằng cách sử dụng các API này.
Nếu bạn đang muốn tải, chỉnh sửa và lưu một email (MSG), vui lòng sử dụng Mã C#:
//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();
Để tải, chỉnh sửa và lưu tệp tin email (MSG), bạn có thể sử dụng mã sau :
//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();
Bạn cũng có thể chỉnh sửa PDF, DOCX, XLSX, PPTX, ODT, ODS, RTF, TXT, CSV, XML, EPUB và nhiều tài liệu khác một cách nhanh chóng bằng Ứng dụng chỉnh sửa tài liệu miễn phí từ thiết bị bạn chọn, vì vậy, vui lòng kiểm tra chúng.
Bạn có thể dễ dàng xuất dữ liệu sang Microsoft Excel từ nhiều nguồn có sẵn khác nhau như JSON và CSV.
Tiếp tục đọcBạn có một số sổ làm việc Excel và bạn muốn kết hợp chúng lại với nhau thành một tệp để báo cáo hoặc để giữ dữ liệu ở một nơi
Tiếp tục đọcChuyển đổi tài liệu Word bao gồm DOC hoặc DOCX trong .NET là một yêu cầu rất phổ biến
Tiếp tục đọc