SHEEPJS将标题名称更改为动态
我正在尝试将SheepJ中的标题名称更改为我从表单中收到的内容。这是我的表单提交功能:
onFormSubmit() {
const fileReader = new FileReader();
const solution = 'testsolution'; // normally i get this from a form input
fileReader.onload = (e) => {
this.arrayBuffer = fileReader.result;
const data = new Uint8Array(this.arrayBuffer);
const arr = [];
for (let i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
const bstr = arr.join('');
const workbook = XLSX.read(bstr, {type: 'binary'});
const first_sheet_name = workbook.SheetNames[0];
const worksheet = workbook.Sheets[first_sheet_name];
// change the column names to match entity
const records = XLSX.utils.sheet_to_json(worksheet, {raw: true});
console.log('records - ', records);
};
fileReader.readAsArrayBuffer(this.file);
}
例如,我的标题像这样进来: altid,firstName,lastname 来遵守“ testsolution”最终以这样的方式结束
我希望他们以下划线和lowercase testsolution_altid,testsolution_firstname,testsolution_lastname
的指示 。例如,下载的下载表可能包含标题:
altid,address1,address2,City,State,State
,应该像 testsolution_altid,testsolution_Address1,testssolution_address2,testsolution_city,testsolution_state_state
任何帮助都将被应用!
I am trying to change the header names in sheetJS to something I recieve from the form. Here is my form submit function:
onFormSubmit() {
const fileReader = new FileReader();
const solution = 'testsolution'; // normally i get this from a form input
fileReader.onload = (e) => {
this.arrayBuffer = fileReader.result;
const data = new Uint8Array(this.arrayBuffer);
const arr = [];
for (let i = 0; i != data.length; ++i) arr[i] = String.fromCharCode(data[i]);
const bstr = arr.join('');
const workbook = XLSX.read(bstr, {type: 'binary'});
const first_sheet_name = workbook.SheetNames[0];
const worksheet = workbook.Sheets[first_sheet_name];
// change the column names to match entity
const records = XLSX.utils.sheet_to_json(worksheet, {raw: true});
console.log('records - ', records);
};
fileReader.readAsArrayBuffer(this.file);
}
currently for example my headers come in like this:
AltId, FirstName, LastName
And I want them to end up like this with 'testsolution' apended with underscore and lowercase
testsolution_altid, testsolution_firstname, testsolution_lastname
NOTE: Header names may change depending on what sheet is uploaded. For example the next sheet uploaded may contain headers:
AltId, Address1, Address2, City, State
And should end up like
testsolution_altid, testsolution_address1, testsolution_address2, testsolution_city, testsolution_state
Any help would be appriciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终这样做的话,如果它可以帮助其他任何人:
I ended up doing it like this if it helps anyone else: