Bandhingake Dokumen Word

Mbandhingake Dokumen Word nggunakake C# .NET

Amarga bisnis lan individu luwih ngandelake dokumentasi digital, kabutuhan alat perbandingan dokumen sing efisien dadi saya penting. Perbandhingan manual dokumen bisa dadi bosen, butuh wektu, lan rawan kesalahan. Semalat, kanthi kekuwatan C# .NET, sampeyan bisa ngotomatisasi proses mbandhingake dokumen Word, dadi luwih cepet, akurat, lan dipercaya. Ing kirim blog iki, kita bakal njelajah carane sampeyan bisa nggunakake .NET Cloud SDK kanggo mbandhingake dokumen Word, lan carane sampeyan bisa nggunakake fitur-fitur kasebut kanggo ngirit wektu lan nambah proses review dokumen.

REST API kanggo Mbandhingake Dokumen

Aspose.Words Cloud SDK kanggo .NET minangka alat sing kuat sing bisa mbantu sampeyan mbandhingake dokumen Word kanthi gampang. Kanthi fitur lengkap, sampeyan bisa mbandhingake loro utawa luwih dokumen, ngenali owah-owahan lan beda ing antarane, lan nggawe laporan sing nyorot owah-owahan kasebut. Apa sampeyan minangka pangembang, manajer proyek, utawa editor, SDK iki bisa mbantu sampeyan nyepetake proses mbandhingake dokumen lan ngirit wektu sampeyan.

Saiki, kanggo nggunakake SDK, goleki Aspose.Words-Cloud ing manajer paket NuGet banjur klik tombol Tambah Paket kanggo nambah referensi SDK ing proyek .NET.

Bandhingake Dokumen Word ing C#

Coba gunakake potongan kode ing ngisor iki kanggo mbandhingake dokumen Word kanthi online.

// Kanggo conto lengkap lan file data, bukak 
https://github.com/aspose-words-cloud/aspose-words-cloud-dotnet

// Entuk kredensial klien saka https://dashboard.aspose.cloud/
string clientSecret = "7f098199230fc5f2175d494d48f2077c";
string clientID = "ee170169-ca49-49a4-87b7-0e2ff815ea6e";

// nggawe obyek konfigurasi nggunakake rincian ClinetID lan Rahasia Klien
var config = new Aspose.Words.Cloud.Sdk.Configuration { ClientId = clientID, ClientSecret = clientSecret };
// miwiti conto WordsApi
var wordsApi = new WordsApi(config);

string firstDocument = "input-sample-1.docx";
string secondDocument = "input-sample-2.docx";
string resultantFile = "Comparison.docx";

// maca isi dokumen Word pisanan saka drive lokal
var firstFile = System.IO.File.OpenRead(firstDocument);
// maca dokumen Word pisanan saka drive lokal
var secondFile = System.IO.File.OpenRead(secondDocument);
try
{
    // upload dokumen Word input menyang panyimpenan maya
    wordsApi.UploadFile(new UploadFileRequest(firstFile, firstDocument));
    wordsApi.UploadFile(new UploadFileRequest(secondFile, secondDocument));

    CompareData compareData = new CompareData();
    // nemtokake dokumen sing bakal dibandhingake
    compareData.ComparingWithDocument = secondDocument;
    // rincian penulis
    compareData.Author = "Nayer Shahbaz";
    compareData.DateTime = DateTime.Now.Date;
    // format dokumen asil
    compareData.ResultDocumentFormat = "DOCX";

    // nyetel opsi comparison document
    CompareOptions options = new CompareOptions()
    {
        IgnoreCaseChanges = true,
        IgnoreFormatting = true,
        IgnoreHeadersAndFooters = true,
        IgnoreFootnotes = true,
        IgnoreComments = true,
        IgnoreTextboxes = true,
        IgnoreTables = true,
        Target = CompareOptions.TargetEnum.Current,
        AcceptAllRevisionsBeforeComparison = true
     };
     compareData.CompareOptions = options

    // Nggawe conto CreateDocument
    CompareDocumentRequest compare = new CompareDocumentRequest();
    compare.CompareData = compareData;
    compare.Name = firstDocument;
    // jeneng berkas asil
    compare.DestFileName = resultantFile;
    
    // miwiti operasi perbandingan dokumen
    wordsApi.CompareDocument(compare);
}
catch(Exception ex)
{
    // Apa wae Pengecualian sajrone upload file menyang panyimpenan Cloud
    Console.Write(ex.StackTrace);
}
// create configuration object using ClientID and Client Secret details
var config = new Configuration { ClientId = clientID, ClientSecret = clientSecret };
// initialize WordsApi instance
var wordsApi = new WordsApi(config);

Nggawe conto WordsApi nggunakake kredensial klien.

// read the content of first Word document from local drive
var firstFile = System.IO.File.OpenRead(firstDocument);
wordsApi.UploadFile(new UploadFileRequest(firstFile, firstDocument));

Waca isi dokumen Word input lan upload menyang panyimpenan Cloud.

CompareData compareData = new CompareData();
compareData.ComparingWithDocument = secondDocument;
compareData.Author = "Nayyer Shahbaz";
compareData.DateTime = DateTime.Now.Date;
compareData.ResultDocumentFormat = "DOCX";

Nggawe conto obyek CompareData ing ngendi kita nemtokake jeneng dokumen sing bakal dibandhingake, rincian penulis, informasi tanggal & wektu lan format kanggo dokumen asil.

CompareOptions options = new CompareOptions()
{
    IgnoreCaseChanges = true,
    IgnoreFormatting = true,
    IgnoreHeadersAndFooters = true,
    IgnoreFootnotes = true,
    IgnoreComments = true,
    IgnoreTextboxes = true,
    IgnoreTables = true,
    Target = CompareOptions.TargetEnum.Current,
    AcceptAllRevisionsBeforeComparison = true
};
compareData.CompareOptions = options;

Gawe conto CompareOptions ing ngendi kita nemtokake macem-macem opsi perbandingan.

CompareDocumentRequest compare = new CompareDocumentRequest();
compare.CompareData = compareData;
compare.Name = firstDocument;
compare.DestFileName = resultantFile;

Nemtokake conto CompareData, jeneng dokumen Word sumber lan jeneng file output sing ngemot asil perbandingan.

wordsApi.CompareDocument(compare);

Miwiti operasi perbandingan dokumen lan ngasilake output ing panyimpenan Cloud.

Mbandhingake Loro Dokumen nggunakake Perintah cURL

Kita wis ngrembug manawa mbandhingake dokumen Word bisa dadi tugas sing tantangan lan butuh wektu, utamane nalika nangani macem-macem file utawa format sing rumit. Untunge, perintah Aspose.Words Cloud lan cURL nyedhiyakake solusi sing kuat kanggo mbandhingake dokumen Word kanthi cepet lan gampang. Kita bisa mbandhingake loro utawa luwih dokumen, nglacak owah-owahan, lan nggawe laporan rinci sing nyorot beda antarane dokumen.

Saiki, tindakake printah ing ngisor iki kanggo nggawe token akses JWT adhedhasar ID Klien lan rincian Rahasia Klien.

curl -v "https://api.aspose.cloud/connect/token" \
 -X POST \
 -d "grant_type=client_credentials&client_id=a41d01ef-dfd5-4e02-ad29-bd85fe41e3e4&client_secret=d87269aade6a46cdc295b711e26809af" \
 -H "Content-Type: application/x-www-form-urlencoded" \
 -H "Accept: application/json"

Sawise Token JWT wis digawe, tindakake printah ing ngisor iki kanggo mbandhingake rong dokumen Word kanthi online lan, simpen file asil ing panyimpenan awan.

curl -v "https://api.aspose.cloud/v4.0/words/{sourceFirst}/compareDocument?destFileName={differenceFile}" \
-X PUT \
-H  "accept: application/json" \
-H  "Authorization: Bearer {accessToken}" \
-H  "Content-Type: application/json" \
-d "{\"ComparingWithDocument\":\"input-sample-2.docx\",\"Author\":\"Nayyer Shahbaz\",\"DateTime\":\"2023-04-23T06:02:29.481Z\",\"CompareOptions\":{\"IgnoreCaseChanges\":true,\"IgnoreTables\":true,\"IgnoreFields\":true,\"IgnoreFootnotes\":true,\"IgnoreComments\":true,\"IgnoreTextboxes\":true,\"IgnoreFormatting\":true,\"IgnoreHeadersAndFooters\":true,\"Target\":\"Current\",\"AcceptAllRevisionsBeforeComparison\":true},\"ResultDocumentFormat\":\"docx\"}"

Ganti {sourceFirst} nganggo jeneng dokumen Word input (saiki ing panyimpenan Cloud), {accessToken} nganggo token akses JWT sing digawe ing ndhuwur lan {differenceFile} kanthi jeneng dokumen Word asil sing nyorot prabédan perbandingan .

perbandingan dokumen tembung

Gambar:- Pratinjau perbandingan dokumen Word nggunakake .NET REST API.

Kesimpulan

Kesimpulane, mbandhingake dokumen Word bisa dadi tugas sing angel, nanging kanthi bantuan Aspose.Words Cloud lan perintah cURL utawa NET Cloud SDK sing kuat, sampeyan duwe solusi sing kuat. Apa sampeyan luwih seneng nggarap C# .NET utawa luwih seneng nggunakake alat baris perintah kayata cURL, Aspose.Words Cloud nawakake macem-macem opsi kanggo mbandhingake loro utawa luwih dokumen, nglacak owah-owahan, lan ngasilake laporan rinci. Kanthi fitur sing fleksibel lan bisa disesuaikan, iki minangka sumber daya sing penting kanggo sapa wae sing rutin nggarap dokumen Word. Dadi apa ora nyoba lan ndeleng carane bisa mbantu nyepetake proses perbandingan dokumen sampeyan.

Pranala Migunani

Artikel sing gegandhengan

Disaranake kanggo ngunjungi blog ing ngisor iki: