Home > front end >  Read the form, the content of the empty the column value no display, how to add value
Read the form, the content of the empty the column value no display, how to add value

Time:11-13

How to achieve this? Js for excel spreadsheet content
 
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:

enjoys a high reputation in the name of a reference 2 floor response:
yes, print it out is like that, is that there is no DepartID, don't know how to add,

Eventually the desired result is
[{" DepartID ":" 1111 ", "DepartName" : "ultraman"}, {" DepartID ":" 2222 ", "DepartName" : "superman"}]


Add in oneself ah, similar to the following...
 for (const depart in newData) {
if(! Depart. DepartID) {
Depart. DepartID='11111'
}
}

CodePudding user response:

Just don't know how to add!
Add this code, or the like, [{" DepartName ":" altman department "}, {" DepartName ":" "superman department}]

 

For (the let I=0; i

Const newData=https://bbs.csdn.net/topics/window.XLS.utils.sheet_to_json (zzexcel. Sheets [zzexcel. SheetNames [I]]).

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

For (the let I=0; i if(! Depart. DepartID) {
Depart. DepartID=suijiId;
}
}



Result. Push (... NewData)
The console. The log (" STT "+ JSON. Stringify (result))
}
Biaogebumen=the result;//for the following change
The console. The log (" result ", result)
}



console. The log (" length "+ JSON. Stringify (zzexcel. Sheets));

Just print the following (found fewer A2, A3 the two empty cell, and A1 print out) :

{
"Sheet1" : {
! "" Ref ":" A1: B3,
"" A1 ": {
"T" : "s",
"V", "DepartID",
"R" : "& lt; T> DepartID" ,
"H", "DepartID",
"W", "DepartID"
},
" B1 ": {
"T" : "s",
"V" : "DepartName,"
"R" : "& lt; T> DepartName" ,
"H" : "DepartName,"
"W" : "DepartName
"},
" B2 ": {
"T" : "s",
"V", "altman department,"
"R" : "& lt; T> ? Xx?? 1??????? E? ¨ e? ¨ & lt;/t>" ,
"H", "altman department,"
"W", "altman department
"},
" B3 ": {
"T" : "s",
"V" : "superman department,"
"R" : "& lt; T> E??? Ooe? ¨ e? ¨ & lt;/t>" ,
"H" : "superman department,"
"W" : "superman department
"}
},
"Sheet2" : {},
"Sheet3" : {}
}
  • Related