
Array to Excel
Pricing
Pay per usage
Go to Apify Store

Array to Excel
Converts any array of objects to Excel
0.0 (0)
Pricing
Pay per usage
1
11
2
Last modified
2 years ago
Pricing
Pay per usage
Converts any array of objects to Excel
0.0 (0)
Pricing
Pay per usage
1
11
2
Last modified
2 years ago
# configurations.idea
# crawlee and apify storage foldersapify_storagecrawlee_storagestorage
# installed filesnode_modules
# This file tells Git which files shouldn't be added to source control
.ideadistnode_modulesapify_storagecrawlee_storagestorage
# Specify the base Docker image. You can read more about# the available images at https://crawlee.dev/docs/guides/docker-images# You can also use any other image from Docker Hub.FROM apify/actor-node-playwright-chrome:16 AS builder
# Copy just package.json and package-lock.json# to speed up the build using Docker layer cache.COPY package*.json ./
# Install all dependencies. Don't audit to speed up the installation.RUN npm install --include=dev --audit=false
# Next, copy the source files using the user set# in the base image.COPY . ./
# Install all dependencies and build the project.# Don't audit to speed up the installation.RUN npm run build
# Create final imageFROM apify/actor-node-playwright-chrome:16
# Copy only built JS files from builder imageCOPY /home/myuser/dist ./dist
# Copy just package.json and package-lock.json# to speed up the build using Docker layer cache.COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --omit=dev --omit=optional \ && echo "Installed NPM packages:" \ && (npm list --omit=dev --all || true) \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version
# Next, copy the remaining files and directories with the source code.# Since we do this after NPM install, quick build will be really fast# for most source file changes.COPY . ./
# Run the image. If you know you won't need headful browsers,# you can remove the XVFB start script for a micro perf gain.CMD ./start_xvfb_and_run_cmd.sh && npm run start:prod --silent
{ "name": "array-to-excel", "version": "0.0.1", "type": "module", "description": "This actor takes an array of objects and converts it to an excel file", "dependencies": { "apify": "^3.1.4", "crawlee": "^3.0.0" }, "devDependencies": { "@apify/tsconfig": "^0.1.0", "@types/node": "^18.0.0", "ts-node": "^10.8.0", "typescript": "^5.0.0" }, "scripts": { "start": "npm run start:dev", "start:prod": "node dist/main.js", "start:dev": "ts-node-esm -T src/main.ts", "build": "tsc", "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1" }, "author": "It's not you it's me", "license": "ISC"}
{ "extends": "@apify/tsconfig", "compilerOptions": { "module": "ES2022", "target": "ES2022", "outDir": "dist", "noUnusedLocals": false, "lib": ["DOM"] }, "include": [ "./src/**/*" ]}
# Specify the base Docker image. You can read more about# the available images at https://crawlee.dev/docs/guides/docker-images# You can also use any other image from Docker Hub.FROM apify/actor-node:16 AS builder
# Copy just package.json and package-lock.json# to speed up the build using Docker layer cache.COPY package*.json ./
# Install all dependencies. Don't audit to speed up the installation.RUN npm install --include=dev --audit=false
# Next, copy the source files using the user set# in the base image.COPY . ./
# Install all dependencies and build the project.# Don't audit to speed up the installation.RUN npm run build
# Create final imageFROM apify/actor-node:16
# Copy only built JS files from builder imageCOPY /usr/src/app/dist ./dist
# Copy just package.json and package-lock.json# to speed up the build using Docker layer cache.COPY package*.json ./
# Install NPM packages, skip optional and development dependencies to# keep the image small. Avoid logging too much and print the dependency# tree for debuggingRUN npm --quiet set progress=false \ && npm install --omit=dev --omit=optional \ && echo "Installed NPM packages:" \ && (npm list --omit=dev --all || true) \ && echo "Node.js version:" \ && node --version \ && echo "NPM version:" \ && npm --version
# Next, copy the remaining files and directories with the source code.# Since we do this after NPM install, quick build will be really fast# for most source file changes.COPY . ./
# Run the image.CMD npm run start:prod --silent
{ "actorSpecification": 1, "name": "array-to-excel", "description": "Converts an array to an excel file", "version": "0.1", "buildTag": "latest", "storages": { }}
{ "title": "Array to Excel input schema", "description": "<strong>How to use:<br><br></strong><ol><li>Configure the actor's input by providing the array of objects.</li><li>Run the actor and wait for it to complete.</li><li>Press on the <strong>\"Export\"</strong> button.</li><li>Select the <strong>\"Excel\"</strong> format.</li><li>Press on the <strong>\"Download\"</strong> button to download the Excel file.</li></ol>", "type": "object", "schemaVersion": 1, "properties": { "sourceArray": { "title": "Source Array", "description": "An array of objects to be converted to Excel. Each object represents a row in the spreadsheet, and its properties correspond to the columns.", "type": "array", "editor": "json" } }, "required": ["sourceArray"]}
1import { Actor, log } from 'apify';2import { sleep } from 'crawlee';3
4interface InputSchema {5 sourceArray: { [key: string]: string }[];6}7
8await Actor.init();9
10// Structure of input is defined in .actor/input_schema.json.11const input = await Actor.getInput<InputSchema>() || { sourceArray: [] };12
13// check if the input is array 14if (!Array.isArray(input.sourceArray)) {15 await Actor.fail('"sourceArray" is not an array');16}17
18if (input.sourceArray.length === 0) {19 await Actor.fail('"sourceArray" is empty');20}21
22const totalItems = input.sourceArray.length;23let invalidItems = 0;24// make sure all the items are object and if not log a warning for the wrong item and remove it from the array25input.sourceArray = input.sourceArray.filter((item) => {26 if (typeof item !== 'object') {27 log.warning(`"sourceArray" item is not an object:\n${JSON.stringify(item, null, 2)}`);28 invalidItems++;29 return false;30 }31 return true;32});33
34// log the total number of items and the number of failed items35log.info(`Total valid items: ${totalItems}, Failed invalid items: ${invalidItems}`);36
37await Actor.pushData(input.sourceArray);38
39await sleep(1000);40
41await Actor.exit();