ahmed salah

ahmed salah

  • 1.2k
  • 547
  • 64.2k

how to convert following code from type script angular to csharp ?

Nov 4 2023 10:53 PM

I work on asp.net razor page with .net core 7 .  i face issue i can't convert this function from type script to csharp asp.net razor page

and before convert this code to csharp so what this code do or what is job this function do

so can you help me please ?

 public uploadData(e: any) {
   this.tableData = null;
   this.tableTitle = null;
   this.tableRecords = [];
   this.totalPageCount = 0;
   this.dataService.StockList = null;

   // let af = ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/vnd.ms-excel']
   console.log(e.target.files[0]);
   /* wire up file reader */
   const target: DataTransfer = <DataTransfer>(<unknown>e.target);

   if (target.files.length !== 1) {
     throw new Error('Cannot use multiple files');
   }
   // if (!XLSX.includes(af, e.target.files[0].type)) {
   //   throw new Error('Cannot use multiple files');
   // }
   let reader: FileReader = new FileReader();
   reader.readAsBinaryString(target.files[0]);
   reader.onload = (e: any) => {
     /* create workbook */
     const binarystr: string = e.target.result;
     const wb: XLSX.WorkBook = XLSX.read(binarystr, { type: 'binary' });

     /* selected the first sheet */
     const wsname: string = wb.SheetNames[0];
     const ws: XLSX.WorkSheet = wb.Sheets[wsname];

     /* save data */
     const data = XLSX.utils.sheet_to_json(ws); // to get 2d array pass 2nd parameter as object {header: 1}
     console.log(data); // Data will be logged in array format containing objects

     let LengthErr = "";
     let QtyErr = "";
     this.dataService.StockList = new Array<StockLabelList>();
     data.forEach((element: any) => {
       console.log(element)
       const Bin = element;
       if (Bin.BINNO.toString().trim().length != 9) {
         LengthErr = element.BINNO;
       }
       if (Bin.QTY >= 10) {
         QtyErr = element.BINNO;
       }
       this.dataService.StockList.push({ BINNO: Bin.BINNO.toString().trim(), QTY: Bin.QTY });
     });

 


Answers (2)