HTML veya web sayfalarını dönüştürme yeteneği ekleme into Uygulamanıza yönelik Word belgeleri hiç bu kadar kolay olmamıştı GrabzİT'in Ruby API'si. Ancak başlamadan önce aradıktan sonra bunu hatırlayın. url_to_docx, html_to_docx or file_to_docx yöntemler save or save_to DOCX'i oluşturmak için yöntem çağrılmalıdır.
Web sayfalarını DOCX olarak yakalamak, tüm web sayfasını dönüştürür into Çok sayıda sayfadan oluşan bir Word belgesi. Bir web sayfasını dönüştürmek için sadece bir parametre gereklidir into bir Word belgesi veya HTML'yi DOCX'e dönüştür aşağıdaki örneklerde gösterildiği gibi.
grabzItClient.url_to_docx("https://www.tesla.com") # Then call the save or save_to method
grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>") # Then call the save or save_to method
grabzItClient.file_to_docx("example.html") # Then call the save or save_to method
Özel bir tanımlayıcıyı DOCX Aşağıda gösterilen yöntemlerde bu değer daha sonra GrabzIt Ruby işleyicinize döndürülür. Örneğin, bu özel tanımlayıcı, bir DOCX belgesinin belirli bir veritabanı kaydı ile ilişkilendirilmesine izin veren bir veritabanı tanımlayıcısı olabilir.
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::DOCXOptions.new() options.customId = "123456" grabzItClient.url_to_docx("https://www.tesla.com", options) # Then call the save method grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::DOCXOptions.new() options.customId = "123456" grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options) # Then call the save method grabzItClient.save("http://www.example.com/handler/index")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::DOCXOptions.new() options.customId = "123456" grabzItClient.file_to_docx("example.html", options) # Then call the save method grabzItClient.save("http://www.example.com/handler/index")
Bir Word belgesine üstbilgi veya altbilgi eklemek için, belirli bir dilekçe uygulamak isteyebilirsiniz. şablon üretilen DOCX'e. Bu şablon olmalı saved önceden ve herhangi bir özel değişkenle birlikte üstbilgi ve altbilgi içeriğini belirtir. Aşağıdaki örnek kodda, kullanıcı "benim şablonum" adı verilen bir şablon kullanıyor.
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::DOCXOptions.new() options.templateId = "my template" grabzItClient.url_to_docx("https://www.tesla.com", options) # Then call the save or save_to method grabzItClient.save_to("result.docx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::DOCXOptions.new() options.templateId = "my template" grabzItClient.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options) # Then call the save or save_to method grabzItClient.save_to("result.docx")
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::DOCXOptions.new() options.templateId = "my template" grabzItClient.file_to_docx("example.html", options) # Then call the save or save_to method grabzItClient.save_to("result.docx")
Doğrudan bir div veya span gibi bir HTML öğesini doğrudan dönüştürmek istiyorsanız intGrabzt'ın Ruby Gem'i ile yapabileceğiniz bir Word dökümanı. Geçmelisin CSS seçici dönüştürmek istediğiniz HTML öğesinin targetElement
yöntemi DOCXOptions sınıf.
... <span id="Article"> <p>This is the content I am interested in.</p> <img src="myimage.jpg"> </span> ...
Bu örnekte, yayındaki kimliği olan yayılma alanındaki tüm içeriği yakalamak istiyoruz. Article
bu nedenle bunu aşağıda gösterildiği gibi GrabzIt API'sine aktarıyoruz.
grabzItClient = GrabzIt::Client.new("Sign in to view your Application Key", "Sign in to view your Application Secret") options = GrabzIt::DOCXOptions.new() options.targetElement = "#Article" grabzItClient.url_to_docx("http://www.bbc.co.uk/news", options) # Then call the save or save_to method grabzItClient.save_to("result.docx")