Reading Excel File from File Picker
I currently have a workflow that is able to take an uploaded CSV and select parcels from that list. However; I'm wanting to make an upgrade to allow users to upload an excel file instead of having to convert to a csv first.
To do this, I'm trying my hand at custom developing an Activity that can process the excel file using a FileReader and the node package ExcelJS. I'm trying to keep it simple and am just trying to take the excel file and return the Workbook. I'm able to log the workbook in the console in a test react app, but when I try to pull the same code into the Custom Activity, I'm getting a few errors that are preventing me from compiling the activity, I've included an image of the code below.
Type '() => void' is missing the following properties from type 'Workbook': category, company, creator, description, and 25 more.
Type 'Promise<Workbook>' is missing the following properties from type 'Workbook': category, company, creator, description, and 25 more.
Type 'Promise<Workbook>' is missing the following properties from type 'Workbook': category, company, creator, description, and 25 more.

-
Ok, so I've gotten it to work so far, but now I'm stuck returning a promise rather than the workbook and am not sure how to resolve it in Geocortex. Below are the two functions I'm using to do the processing. In the final export default class, I'm just calling "caller(inputs.excelFile)" and returning it.
import Excel from 'exceljs'
function getWorkbookFromFile2 (excelFile: Blob) {
return new Promise((resolve) => {
const reader = new FileReader();
reader.onload = (event) => {
const data = event.target!.result as Buffer;
const loader = new Excel.Workbook();
const workbook= loader.xlsx.load(data!);
resolve(workbook);
};
reader.readAsArrayBuffer(excelFile);
});
}
async function caller(file: Blob) {
const workbook = await getWorkbookFromFile2(file);
return workbook;
}
0 -
Ok, so I've made a few tweaks and have been able to get at the result in the Workflow. So, now I've done some processing in the script so that it ends up returning a query string that I can input into a Query Activity.
So far, this works, however; after the Query returns it's result of features, the whole program kind of freezes and different Errors keep popping up in the console saying something along the lines of:
Unhandled promise rejection TypeError: e.loadPromise.isResolved is not a function
at ViewerApplication.o._canBeLoaded (Framework.bundle.js:1)
at Framework.bundle.js:1
at Array.filter (<anonymous>)
at ViewerApplication.o._findUnloadedModulesForCommand (Framework.bundle.js:1)
at ViewerApplication.o.pendingModulesForCommand (Framework.bundle.js:1)
at a.execute (Framework.bundle.js:1)
at Framework.bundle.js:1
at eval (exceljs.min.js?e8ae:11)
0 -
On further testing, I'm able to zoom to the features if it goes quickly. It seems like something is continuing to be called and if the workflow takes too long, it starts throwing the promise error.
When I try to add the query results to the results pane, I guess it takes slightly longer and starts throwing the Promise.isResolved is not a function error before the results are added.
0
Bitte melden Sie sich an, um einen Kommentar zu hinterlassen.
Kommentare
3 Kommentare