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.js
CHANGED
|
@@ -1244,23 +1244,46 @@ class ExportBuilder {
|
|
|
1244
1244
|
});
|
|
1245
1245
|
return this;
|
|
1246
1246
|
}
|
|
1247
|
-
|
|
1248
|
-
|
|
1247
|
+
/**
|
|
1248
|
+
* Add multiple data rows to the sheet
|
|
1249
|
+
* @param data Array of row data
|
|
1250
|
+
* @param fields Optional array of field names (for object data)
|
|
1251
|
+
* @param styles Optional array of styles per row or per cell
|
|
1252
|
+
*/
|
|
1253
|
+
addDataRows(data, fields, styles) {
|
|
1254
|
+
data.forEach((item, rowIdx) => {
|
|
1249
1255
|
const row = this.currentSheet.createRow();
|
|
1256
|
+
let rowStyle = undefined;
|
|
1257
|
+
let cellStyles = undefined;
|
|
1258
|
+
if (styles && styles[rowIdx]) {
|
|
1259
|
+
if (Array.isArray(styles[rowIdx])) {
|
|
1260
|
+
cellStyles = styles[rowIdx];
|
|
1261
|
+
}
|
|
1262
|
+
else {
|
|
1263
|
+
rowStyle = styles[rowIdx];
|
|
1264
|
+
}
|
|
1265
|
+
}
|
|
1250
1266
|
if (fields && fields.length > 0) {
|
|
1251
|
-
fields.forEach(field => {
|
|
1267
|
+
fields.forEach((field, colIdx) => {
|
|
1252
1268
|
const value = this.getNestedValue(item, field);
|
|
1253
|
-
|
|
1269
|
+
const style = cellStyles ? cellStyles[colIdx] : rowStyle;
|
|
1270
|
+
row.createCell(value, style);
|
|
1254
1271
|
});
|
|
1255
1272
|
}
|
|
1256
1273
|
else if (Array.isArray(item)) {
|
|
1257
|
-
item.forEach(value =>
|
|
1274
|
+
item.forEach((value, colIdx) => {
|
|
1275
|
+
const style = cellStyles ? cellStyles[colIdx] : rowStyle;
|
|
1276
|
+
row.createCell(value, style);
|
|
1277
|
+
});
|
|
1258
1278
|
}
|
|
1259
1279
|
else if (typeof item === 'object') {
|
|
1260
|
-
Object.values(item).forEach(value =>
|
|
1280
|
+
Object.values(item).forEach((value, colIdx) => {
|
|
1281
|
+
const style = cellStyles ? cellStyles[colIdx] : rowStyle;
|
|
1282
|
+
row.createCell(value, style);
|
|
1283
|
+
});
|
|
1261
1284
|
}
|
|
1262
1285
|
else {
|
|
1263
|
-
row.createCell(item);
|
|
1286
|
+
row.createCell(item, rowStyle);
|
|
1264
1287
|
}
|
|
1265
1288
|
});
|
|
1266
1289
|
return this;
|