sheetra 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.esm.js +30 -7
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +30 -7
- package/dist/index.js.map +1 -1
- package/dist/types/builders/export-builder.d.ts +7 -1
- package/dist/types/index.d.ts +7 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1242,23 +1242,46 @@ class ExportBuilder {
|
|
|
1242
1242
|
});
|
|
1243
1243
|
return this;
|
|
1244
1244
|
}
|
|
1245
|
-
|
|
1246
|
-
|
|
1245
|
+
/**
|
|
1246
|
+
* Add multiple data rows to the sheet
|
|
1247
|
+
* @param data Array of row data
|
|
1248
|
+
* @param fields Optional array of field names (for object data)
|
|
1249
|
+
* @param styles Optional array of styles per row or per cell
|
|
1250
|
+
*/
|
|
1251
|
+
addDataRows(data, fields, styles) {
|
|
1252
|
+
data.forEach((item, rowIdx) => {
|
|
1247
1253
|
const row = this.currentSheet.createRow();
|
|
1254
|
+
let rowStyle = undefined;
|
|
1255
|
+
let cellStyles = undefined;
|
|
1256
|
+
if (styles && styles[rowIdx]) {
|
|
1257
|
+
if (Array.isArray(styles[rowIdx])) {
|
|
1258
|
+
cellStyles = styles[rowIdx];
|
|
1259
|
+
}
|
|
1260
|
+
else {
|
|
1261
|
+
rowStyle = styles[rowIdx];
|
|
1262
|
+
}
|
|
1263
|
+
}
|
|
1248
1264
|
if (fields && fields.length > 0) {
|
|
1249
|
-
fields.forEach(field => {
|
|
1265
|
+
fields.forEach((field, colIdx) => {
|
|
1250
1266
|
const value = this.getNestedValue(item, field);
|
|
1251
|
-
|
|
1267
|
+
const style = cellStyles ? cellStyles[colIdx] : rowStyle;
|
|
1268
|
+
row.createCell(value, style);
|
|
1252
1269
|
});
|
|
1253
1270
|
}
|
|
1254
1271
|
else if (Array.isArray(item)) {
|
|
1255
|
-
item.forEach(value =>
|
|
1272
|
+
item.forEach((value, colIdx) => {
|
|
1273
|
+
const style = cellStyles ? cellStyles[colIdx] : rowStyle;
|
|
1274
|
+
row.createCell(value, style);
|
|
1275
|
+
});
|
|
1256
1276
|
}
|
|
1257
1277
|
else if (typeof item === 'object') {
|
|
1258
|
-
Object.values(item).forEach(value =>
|
|
1278
|
+
Object.values(item).forEach((value, colIdx) => {
|
|
1279
|
+
const style = cellStyles ? cellStyles[colIdx] : rowStyle;
|
|
1280
|
+
row.createCell(value, style);
|
|
1281
|
+
});
|
|
1259
1282
|
}
|
|
1260
1283
|
else {
|
|
1261
|
-
row.createCell(item);
|
|
1284
|
+
row.createCell(item, rowStyle);
|
|
1262
1285
|
}
|
|
1263
1286
|
});
|
|
1264
1287
|
return this;
|