我試圖使用basil.js將CSV導入到InDesign文檔中。然而,根據該數據集,我往往會得到一個錯誤:使用basil.js從CSV導入數據到InDesign
Javascript Error!
Error Number: 21
Error String: undefined object is not an object
Engine: main
File: /Users/...
includes/core.js
Line: 137 Source:
app.doScript(function() {
我的劇本是根據本Working with CSV files演示除了我已經修改了它的數據所以只有一個行每行提出,並將其插入一個每4行新一頁。這是我的腳本:
#includepath "~/Documents/;%USERPROFILE%Documents";
#include "basiljs/bundle/basil.js";
function draw() {
// load & convert
var data = b.CSV.decode(b.loadString("donorsopenS.csv"));
for (var i = 0; i < data.length; i++) {
data[i].Zip = parseInt(data[i].Zip);
};
// text settings
b.textSize(12);
b.textFont('Helvetica');
b.textAlign(Justification.LEFT_ALIGN);
b.units(b.MM);
var i = 0;
var verticalUnitSize = 20;
var horizontalUnitSize = 50;
for (var i = 0; i < data.length; i++) {
for (var y = 0; y < 4; y++) {
var posX = horizontalUnitSize;
var posY = y*(verticalUnitSize);
var Contributor = data[i].Contributor;
var PositionBoard = data[i].PositionBoard;
var Amount = data[i].Amount;
var Recipient = data[i].Recipient;
b.text(Contributor, 0, posY,50,20);
b.text(PositionBoard, posX, posY,50,20);
b.text(Amount, posX*2, posY,50,20);
b.text(Recipient, posX*3, posY,50,20);
// stop drawing if no more rows are available
if (i > data.length) break;
i++;
};
// add new page
if (i < data.length-1) {
b.addPage();
}
}
}
b.go();
它正常工作與10行的數據集 - here is a sample dataset,但是當它是一個不同的行數將返回錯誤。即使在這種情況下,如果我要更改for循環,以便每頁顯示5行,它就會中斷。
任何幫助,非常感謝。謝謝!
感謝您的及時響應!這解決了我的問題。導入1800行左右的數據集最後導致我的InDesign崩潰:P – christopher
您是否嘗試將其轉換爲JSON並直接包含它? https://www.npmjs.com/package/babyparse? – fabianmoronzirfas