Created
July 29, 2021 07:11
Star
You must be signed in to star a gist
Merge Multiple Excel Files into One using a REST API in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Merge Multiple Excel Files into One using a REST API in Node.js | |
1. Merge Multiple Excel Files using REST API in Node.js | |
2. Merge Specific Excel Sheets using Node.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global.clientId = "112f0f38-9dae-42d5-b4fc-cc84ae644972"; | |
global.clientSecret = "16ad3fe0bdc39c910f57d2fd48a5d618"; | |
global.myStorage = ""; | |
const configuration = new groupdocs_merger_cloud.Configuration(clientId, clientSecret); | |
configuration.apiBaseUrl = "https://api.groupdocs.cloud"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// initialize api | |
var fileApi = groupdocs_merger_cloud.FileApi.fromConfig(configuration); | |
// create file download request | |
let request = new groupdocs_merger_cloud.DownloadFileRequest("Output/joined.xlsx", myStorage); | |
// download file | |
let response = await fileApi.downloadFile(request); | |
// save output file in your working directory | |
fs.writeFile("C:\\Files\\joined.xlsx", response, "binary", function (err) { }); | |
console.log(response); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
let documentApi = groupdocs_merger_cloud.DocumentApi.fromKeys(clientId, clientSecret); | |
// create first join item | |
let item1 = new groupdocs_merger_cloud.JoinItem(); | |
item1.fileInfo = new groupdocs_merger_cloud.FileInfo(); | |
item1.fileInfo.filePath = "sample1.xlsx"; | |
// create second join item | |
let item2 = new groupdocs_merger_cloud.JoinItem(); | |
item2.fileInfo = new groupdocs_merger_cloud.FileInfo(); | |
item2.fileInfo.filePath = "sample2.xlsx"; | |
// create join options | |
let options = new groupdocs_merger_cloud.JoinOptions(); | |
options.joinItems = [item1, item2]; | |
options.outputPath = "Output/joined.xlsx"; | |
// create join request | |
let joinRequest = new groupdocs_merger_cloud.JoinRequest(options); | |
let result = await documentApi.join(joinRequest); | |
console.log("Document edited: " + result.path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api initialization | |
let documentApi = groupdocs_merger_cloud.DocumentApi.fromKeys(clientId, clientSecret); | |
// create first join item | |
let item1 = new groupdocs_merger_cloud.JoinItem(); | |
item1.fileInfo = new groupdocs_merger_cloud.FileInfo(); | |
item1.fileInfo.filePath = "sample1.xlsx"; | |
// create second join item | |
let item2 = new groupdocs_merger_cloud.JoinItem(); | |
item2.fileInfo = new groupdocs_merger_cloud.FileInfo(); | |
item2.fileInfo.filePath = "sample2.xlsx"; | |
item2.startPageNumber = 3 | |
item2.endPageNumber = 4 | |
// create join options | |
let options = new groupdocs_merger_cloud.JoinOptions(); | |
options.joinItems = [item1, item2]; | |
options.outputPath = "Output/joined.xlsx"; | |
// create join request | |
let joinRequest = new groupdocs_merger_cloud.JoinRequest(options); | |
let result = await documentApi.join(joinRequest); | |
console.log("Document edited: " + result.path); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// construct FileApi | |
let fileApi = groupdocs_merger_cloud.FileApi.fromConfig(configuration); | |
let resourcesFolder = 'C:\\Files\\'; | |
fs.readdir(resourcesFolder, (err, files) => { | |
files.forEach(file => { | |
// read files one by one | |
fs.readFile(resourcesFolder + file, (err, fileStream) => { | |
// create upload file request | |
let request = new groupdocs_merger_cloud.UploadFileRequest(file, fileStream, myStorage); | |
// upload file | |
fileApi.uploadFile(request) | |
.then(function (response) { | |
console.log(file + " uploaded: " + response.uploaded.length); | |
}) | |
.catch(function (error) { | |
console.log("Error: " + error.message); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment