Const result=[];
/* * read the upload form/
//in the first place to monitor changes in the input box, select a new file will trigger a change event
Document. QuerySelector (" # count "). The addEventListener (" change ", the function () {
//get the selected file
Var file=document. QuerySelector (" # count "). The files [0].
Var type=file. The name. The split ('. ');
If (type/type. Length - 1.=='XLSX & amp; & Type [type] length - 1!=='XLS & amp; & Type [type] length - 1! CSV==' ') {
Alert (' only option excel file imports);
return false;
}
Const reader=new FileReader ();
Reader. ReadAsBinaryString (file);
Reader. onl oad=(e)=& gt; {
Const data=https://bbs.csdn.net/topics/e.target.result;
Const zzexcel=window. XLS. Read (data, {
Type: 'binary'
});
//const result=[];
The console. The log (" length "+ JSON. Stringify (zzexcel))
For (the let I=0; i//insert ID number to form because the form of ID empty, look not to come out, manual input values
Generate random ID/* */
//time2=(year, month and day + hour, minute and second);
//var suijiId=time2 + math.h ceil (Math. The random (9999 * 10000)) + 1000. Random ID//department
//DepartID. Push (suijiId);//
Const newData=https://bbs.csdn.net/topics/window.XLS.utils.sheet_to_json (zzexcel. Sheets [zzexcel. SheetNames [I]]).
Result. Push (... NewData)
The console. The log (" STT "+ JSON. Stringify (result))
}
Biaogebumen=the result;//
The console. The log (" result ", result)//printed
}
});
Probably a excel form as follows, DepartID this column is empty, but also hope to print processing
DepartID DepartName
Altman department
Superman department
Users to export excel spreadsheet with js processing printing, don't know why DepartID no printed:
[{" DepartName ":" ultraman "}, {" DepartName ":" superman "}]
Expectations are want to print:
[{" DepartID ":" ", "DepartName" : "ultraman"}, {" DepartID ":" ", "DepartName" : "superman"}]
And then wrote a random repetitive id number shown in the insert DepartID (end) :
[{" DepartID ":" 1111 ", "DepartName" : "ultraman"}, {" DepartID ":" 2222 ", "DepartName" : "superman"}]
My problem is trying to say in the excel spreadsheet DepartID that is empty, print print, by the way, and the empty input some numerical (don't repeat random number), is now a know how to insert?
CodePudding user response:
That plug-in used you,Const newData=https://bbs.csdn.net/topics/... ;
Print what newData, if it is {" DepartName ":" altman department} "this way, that you can judge no DepartID property, and then to DepartID bonus
CodePudding user response:
Yes, print it out is like that, it is no DepartID, don't know how to add,Eventually the desired result is
[{" DepartID ":" 1111 ", "DepartName" : "ultraman"}, {" DepartID ":" 2222 ", "DepartName" : "superman"}]
CodePudding user response: