How to convert Excel XLSX to PDF in Node.js
The first step is to add a reference to our package.json for the document processing library:
"dependencies": {
"cloudmersive-convert-api-client": "^1.2.7"
}
Now, all we have to do is call convertDocumentXlsxToPdf to convert our Excel Document (XLSX) format file into a PDF file:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');
var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikey
var Apikey = defaultClient.authentications['Apikey'];
Apikey.apiKey = 'YOUR API KEY';var apiInstance = new CloudmersiveConvertApiClient.ConvertDocumentApi();var inputFile = Buffer.from(fs.readFileSync("C:\\temp\\inputfile").buffer); // File | Input file to perform the operation on.var callback = function(error, data, response) {
if (error) {
console.error(error);
} else {
console.log('API called successfully. Returned data: ' + data);
}
};
apiInstance.convertDocumentXlsxToPdf(inputFile, callback);
That’s all there is to it, and it is free.
Note that this function is specifically for XLSX. Other functions are available for XLS, as well as auto-detection of the document type and generalized conversion into PDF.
You can also use this library to convert XLSX files into JSON, and even enumerate and manipulate the contents of the XLSX file, for example to add or remove a header, watermark, row of data, etc.