添加转换HTML或网页的功能 into将Word文档发送到您的应用程序从未如此简单 GrabzIt的Node.js API。 但是,在开始之前,请记住 url_to_docx, html_to_docx or file_to_docx 方法 save or save_to 必须调用方法才能实际创建DOCX。
当DOCX转换整个网页时捕获网页 int可以包含许多页面的Word文档。 只需一个参数即可转换网页 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文档中,可以请求您要应用特定的 模板 生成的DOCX。 该模板必须是 saved并会指定页眉和页脚的内容以及任何特殊变量。 在下面的示例代码中,用户正在使用他们创建的名为“我的模板”的模板。
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元素 int您可以使用GrabzIt的Node.js库获得Word文档。 您必须通过 CSS选择器 您希望转换为HTML元素的 setTargetElement
参数。
... <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; } });