Skip to content

Instantly share code, notes, and snippets.

@yiskang
Created July 12, 2024 05:37
Show Gist options
  • Save yiskang/f7d27fae17fcd7c0eb76ef8a6959d8cc to your computer and use it in GitHub Desktop.
Save yiskang/f7d27fae17fcd7c0eb76ef8a6959d8cc to your computer and use it in GitHub Desktop.
Read Excel (XLXS) file from ACC Docs
const { SdkManagerBuilder } = require('@aps_sdk/autodesk-sdkmanager');
const { OssClient } = require('@aps_sdk/oss');
const XLSX = require('xlsx');
const axios = require('axios');
const sdk = SdkManagerBuilder.create().build();
const ossClient = new OssClient(sdk);
(async () => {
//urn:adsk.objects:os.object:wip.dm.prod/f98e8976-e9be-5667-9021-7572d8f2c00f.xlsx
let bucketKey = 'wip.dm.prod';
let objectName = 'f98e8976-e9be-5667-9021-7572d8f2c00f.xlsx';
let accessToken = 'eyJh...u7g';
let downloadUrlRes = await ossClient.ossApi.signedS3Download(accessToken, bucketKey, objectName);
let signedRes = downloadUrlRes.response?.data;
const url = signedRes.url;
//console.log(signedRes.url);
const res = await axios.get(url, { responseType: 'arraybuffer' });
/* res.data is a Buffer */
const workbook = XLSX.read(res.data);
let data = []
const sheets = workbook.SheetNames
for (let i = 0; i < sheets.length; i++) {
const temp = XLSX.utils.sheet_to_json(
workbook.Sheets[workbook.SheetNames[i]]
);
temp.forEach((sheetData) => {
console.log(sheetData);
data.push(sheetData);
});
}
//console.log(data);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment