HTMLまたはWebページを変換する機能を追加する intoアプリケーションへのWord文書がこれまでになく簡単になりました GrabzItのNode.js API。 ただし、開始する前に、 url_to_docx, html_to_docx or file_to_docx メソッド save or save_to DOCXを実際に作成するには、メソッドを呼び出す必要があります。
DOCXとしてWebページをキャプチャすると、Webページ全体が変換されます intoa多くのページで構成できるWord文書。 Webページを変換するために必要なパラメーターは1つだけです intワード文書または HTMLをDOCXに変換する 以下の例に示すように。
client.url_to_docx("https://www.tesla.com"); //Then call the save or save_to method
client.html_to_docx("<html><body><h1>Hello World!</h1></body></html>"); //Then call the save or save_to method
client.file_to_docx("example.html"); //Then call the save or save_to method
にカスタム識別子を渡すことができます DOCX 次に示すメソッドを使用すると、この値はGrabzIt Node.jsハンドラーに返されます。 たとえば、このカスタム識別子はデータベース識別子であり、DOCXドキュメントを特定のデータベースレコードに関連付けることができます。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.url_to_docx("https://www.tesla.com", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"customId":123456}; client.file_to_docx("example.html", options); //Then call the save method client.save("http://www.example.com/handler", function (error, id){ if (error != null){ throw error; } });
Word文書にヘッダーまたはフッターを追加するには、特定の適用を要求できます。 template 生成されるDOCXに。 このテンプレートは savedを事前に指定し、ヘッダーとフッターの内容を特別な変数とともに指定します。 以下のコード例では、ユーザーは「my template」という名前で作成したテンプレートを使用しています。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"templateId":"my template"}; client.url_to_docx("https://www.tesla.com", options); //Then call the save or save_to method client.save_to("result.docx", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"templateId":"my template"}; client.html_to_docx("<html><body><h1>Hello World!</h1></body></html>", options); //Then call the save or save_to method client.save_to("result.docx", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); var options = {"templateId":"my template"}; client.file_to_docx("example.html", options); //Then call the save or save_to method client.save_to("result.docx", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });
divやspanなどのHTML要素を直接変換する場合 intGrabzItのNode.jsライブラリを使用して作成できるWord文書。 あなたは合格しなければなりません CSSセレクター に変換するHTML要素の setTargetElement
パラメータに一致する最初のデバイスのリモートコントロール URL を返します。
... <span id="Article"> <p>This is the content I am interested in.</p> <img src="myimage.jpg"> </span> ...
この例では、次のIDを持つスパン内のすべてのコンテンツをキャプチャします。 Article
、したがって、以下に示すようにこれをGrabzIt APIに渡します。
var grabzit = require('grabzit'); var client = new grabzit("Sign in to view your Application Key", "Sign in to view your Application Secret"); client.url_to_docx("http://www.bbc.co.uk/news", {"targetElement": "#Article"}); //Then call the save or save_to method client.save_to("result.docx", function (error, id){ //this callback is called once the capture is downloaded if (error != null){ throw error; } });