Mun fahimci cewa isar da saƙon kan layi da gabatar da abun ciki mara kyau suna da mahimmanci. Don haka, buƙatar jujjuya takaddun Kalma zuwa tsarin HTML ba ta taɓa yin matsi ba. Ka yi tunanin ɓacin ran na ƙoƙarin raba daftarin aikinka na Kalma akan layi, kawai don fuskantar al’amuran tsarawa, karkatattun shimfidar wuri, da hiccus ɗin dacewa lokacin da aka duba su a masu binciken gidan yanar gizo. Wannan shine inda aka canza daga Kalma zuwa HTML matakai a matsayin wasa. - mai canzawa, yana ba da mafita wanda da kyau ya warware waɗannan matsalolin.
Wannan labarin yana zurfafa cikin mahimmancin buƙatu na ‘Takardun Kalma zuwa HTML’ ta amfani da .NET REST API. Hakanan yana ba da haske kan yadda wannan canjin ya dace da yanayin dijital don ƙirƙirar haɗin kai da jin daɗin gani kan layi don takaddunku.
- API ɗin REST don Takardun Kalma zuwa Canjin HTML
- Takardun Kalma zuwa Canjin HTML tare da C# .NET
- Maida Kalma zuwa HTML ta amfani da Umarnin CURL
API ɗin REST don Takardun Kalma zuwa Canjin HTML
Aspose.Words Cloud SDK for .NET SDK ce mai mahimmanci tana ba da mafita mai canzawa wanda ba tare da wahala ba ya cike gibin tsakanin MS Word da abun cikin yanar gizo. Ta hanyar haɗa Cloud SDK a cikin aikace-aikacen NET ɗinku, kuna buɗe ikon aiwatar da jujjuyawar ‘Takardar Magana zuwa HTML’ cikin sauƙi mai ban mamaki, tabbatar da cewa takaddun ku a shirye suke a yanar gizo ba tare da ƙulli na gyare-gyaren tsarawa da hannu ba.
Mataki na farko a cikin amfani da SDK shine ƙara ambaton sa zuwa maganin NET. Don haka, bincika ‘Aspose.Words-Cloud’ a cikin manajan fakitin NuGet kuma danna maɓallin ‘Ƙara Kunshin’. Bugu da ƙari, da fatan za a ziyarci cloud dashboard kuma sami keɓaɓɓen takaddun shaidar abokin ciniki.
Takardun Kalma zuwa Canjin HTML tare da C# .NET
Wannan sashe yana ba da cikakkun bayanai game da canza daftarin aiki na MS Word zuwa HTML domin mu iya duba daftarin aiki akan layi. A takaice, bi waɗannan matakan don duba takaddun Microsoft Word akan layi.
// Don cikakkun misalai da fayilolin bayanai, da fatan za a je zuwa
https://github.com/aspose-words-cloud/aspose-words-cloud-dotnet
// Samu bayanan abokin ciniki daga https://dashboard.aspose.cloud/
string clientSecret = "4d84d5f6584160cbd91dba1fe145db14";
string clientID = "bb959721-5780-4be6-be35-ff5c3a6aa4a2";
// ƙirƙiri abin daidaitawa ta amfani da ClinetID da bayanan Sirrin Abokin ciniki
var config = new Aspose.Words.Cloud.Sdk.Configuration { ClientId = clientID, ClientSecret = clientSecret };
// fara misali WordsApi
var wordsApi = new WordsApi(config);
// Shigar da sunan fayil na PDF
String inputFile = "test_multi_pages.docx";
// resultant fayil format
String format = "HTML";
String resultant = "resultantFile.html";
// loda abun ciki na shigar da fayil ODT don yawo misali
var sourceFile = System.IO.File.OpenRead(inputFile);
// ƙirƙiri DocumentWithFormatRequest abu na buƙatar
var response = new ConvertDocumentRequest(requestDocument, format: "HTML", outPath: "resultantFile.html");
// fara aikin daftarin aiki
wordsApi.ConvertDocument(response);
// buga saƙon nasara idan tuba ya yi nasara
if (response != null && response.Equals("OK"))
{
Console.WriteLine("Word to HTML conversion successful !");
Console.ReadKey();
}
Yanzu, bari mu bincika wasu cikakkun bayanai na snippet code da aka bayyana a sama.
// create configuration object using ClinetID and Client Secret details
var config = new Configuration { ClientId = clientID, ClientSecret = clientSecret };
// initialize WordsApi instance
WordsApi wordsApi = new WordsApi(config);
Da farko, ƙirƙiri misali na ajin ‘WordsApi’ inda muke wuce bayanan abokin ciniki azaman mahawara.
using var requestDocument = File.OpenRead("file-sample.docx");
Load da shigarwar daftarin aiki na Word daga faifan gida zuwa misalin rafi.
var response = new ConvertDocumentRequest(requestDocument, format: "HTML", outPath: "resultantFile.html");
Ƙirƙiri buƙatar jujjuya daftarin aiki yayin samar da fayil ɗin shigarwar Kalma, tsarin fitarwa azaman HTML da sunan fayil ɗin HTML mai sakamako.
wordsApi.ConvertDocument(response);
Kira API don canza Kalma zuwa HTML domin a iya nuna fayil ɗin kalma akan layi.
Maida Kalma zuwa HTML ta amfani da Umarnin CURL
Haɓaka ƙwarewar raba daftarin aiki ta hanyar jujjuya takaddun Kalma zuwa HTML ba tare da ɓata lokaci ba ta amfani da ƙarfin aiki na Aspose.Words Cloud da umarnin cURL. Wannan ƙaƙƙarfan haɗin gwiwar yana ba ku damar yin ‘Kalmar DOC zuwa HTML’ ba tare da wahala ba ta hanyar ƙirƙirar umarnin cURL don yin hulɗa tare da Aspose.Words Cloud API.
Mataki na farko a cikin wannan hanyar shine samar da alamar samun damar JWT ta aiwatar da umarni mai zuwa:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=bb959721-5780-4be6-be35-ff5c3a6aa4a2&client_secret=4d84d5f6584160cbd91dba1fe145db14" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Yanzu, da fatan za a aiwatar da wannan umarni don loda daftarin aiki da aka adana a cikin ma’ajiyar girgije kuma mu canza shi zuwa tsarin HTML, ta yadda za mu iya nuna takaddar MS Word akan layi.
curl -v "https://api.aspose.cloud/v4.0/words/{sourceFile}?format=html" \
-X GET \
-H "accept: application/octet-stream" \
-H "Authorization: Bearer <JWT Token>" \
-o "{resultantFile}"
Sauya ‘sourceFile’ tare da sunan shigar da daftarin aiki Kalma da ake samu a cikin ma’ajiyar gajimare, ‘resultantFile’ tare da sunan sakamakon HTML da za a adana a cikin gida, da ‘accessToken’ tare da alamar samun damar JWT da aka samar a sama.
Kammalawa
A ƙarshe, jujjuya takaddun Kalma zuwa tsarin HTML yana aiki azaman gada mai mahimmanci tsakanin tsarin duniyar daftarin aiki da duniyar kan layi mai ƙarfi. Tare da hanyoyi guda biyu daban-daban amma masu ƙarfi a hannunku-Aspose.Words Cloud SDK don NET da kuma amfani da umarnin cURL, kuna da sassauci don zaɓar hanyar da ta dace da ƙwarewar fasaha da abubuwan da kuke so.
Hanyoyin haɗi masu amfani
Labarai masu alaka
Muna ba da shawarar ziyartar shafukan yanar gizo masu zuwa: