Skip to content

Handling of Nested Objects, when exporting to xlsx #1

@anishshobithps

Description

@anishshobithps

Firstly, thank you for this and example set, it helped me a lot.

I had a situation where, I was fetching details from the database, and it had a nested Object, but the export part would only export non-nested fields.

I was able to achieve exporting nested Object, with the help of by changing

for (const objKey in obj) {
if (Object.hasOwn(naming,objKey)) {
tempObj[naming[objKey]] = obj[objKey];
}
}

To

		Object.keys(obj).forEach(key => {
			if (typeof obj[key] === "object") {
				Object.keys(obj[key]).forEach(nestedKey => {
					if (naming[nestedKey]) {
						tempObj[naming[nestedKey]] = obj[key][nestedKey];
					}
				});
			} else {
				if (naming[key]) {
					tempObj[naming[key]] = obj[key];
				}
			}
		});

Metadata

Metadata

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions