> How to upload files to google drive using App script in hindi
एक्सेल और एडवांस एक्सेल से जुड़े सभी लेटेस्ट विडियो पाने के लिए मेरे यूट्यूब चैनल को अभी सबस्क्राइब करे लिंक नीचे है धन्यवाद |

How to upload files to google drive using App script in hindi

 

How to upload files to google drive using App script in hindi

दोस्तों यदि आप अपने किसी भी फाइल को ऑटोमेटिक तरीके से गूगल ड्राइव में सेव (How to upload files to google drive using App script in hindi) करना चाहते हैं  |तो आप उसे कैसे कर पाएंगे वह आज की इस आर्टिकल में मैं आपको बताऊंगा | 


code.gs

function getData() {
  let ws = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet1');
  let date1 = ws.getRange('H1').getValue();
  let date2 = ws.getRange('J1').getValue();
  let startDate = new Date(date1);
  let endDate = new Date(date2);
  let data = ws.getRange('A2:F1000').getValues();
  let output = data.filter(function (getData) {
    return getData[0] > startDate && getData[0] < endDate
  });
  Logger.log(output)
  Logger.log(startDate);
  Logger.log(endDate)

}


function doGet(){
  return HtmlService.createTemplateFromFile('Index').evaluate()
}


function include(filename){
  return HtmlService.createHtmlOutputFromFile(filename).getContent();
}


function submitFormData(formObject){
  let folder=DriveApp.getFolderById('1pCgU157N9Bm_2f1vpRNjfAer9gLDo7Nn');
  let mainsheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('Sheet2')
 if(formObject.filename.length>0){
    let blob=formObject.filename;
    let file= folder.createFile(blob);
    let url = file.getUrl();
    let fileName = file.getName();
    mainsheet.appendRow([new Date(),formObject.uname,formObject.qualification,formObject.address,formObject.city,formObject.state,formObject.myzip,url,fileName])
  }
}
JavaScript FILE
 
  <script>
   
   setInterval((showClock) => {
     let date = new Date();
    let time = date.toLocaleTimeString()
    document.getElementById("showTime").innerHTML=time
   }, 1000);

 window.addEventListener('load',preventSubmit);

 function preventSubmit(){
   let myForm =document.querySelectorAll('form');
   console.log(myForm)
   for(var i=0;i<myForm.length;i++){
     myForm[i].addEventListener('submit',function(e){
     e.preventDefault();
     })
   }
 }

function getFormData(formObject){
  google.script.run.withSuccessHandler(showSucess).submitFormData(formObject)
}

 function showSucess(){
   document.getElementById('showAlert').innerHTML='<div class="alert alert-success" role="alert">Data Successfully Submitted |</div>'
   document.getElementById("formdata").reset();
  setTimeout(clearAlert,4000)
 }

 function clearAlert(){
   document.getElementById('showAlert').innerHTML=""
 }
</script>

HTML FILE

<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap demo</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">
    
    <?!=include("Javascript");?>
  </head>
  <body style="background-color:#40739e">
    <div id="showTime" style="width: 120px;height: 50px;font-size: 20px; color: black;color: white"></div>
<div class="main" style="width:50%; margin:auto;padding:40px;">
    <form class="row g-3" id="formdata"  onsubmit="getFormData(this)">
  <div class="col-md-6">
    <label for="myName" class="form-label" style="color:white">User Name</label>
    <input type="text" class="form-control" name="uname" id="myName">
  </div>
  <div class="col-md-6">
    <label for="inputPassword4" class="form-label" style="color:white">Qualification</label>
    <input type="text" class="form-control" id="qualification" name="qualification">
  </div>
  <div class="col-6">
    <label for="inputAddress" class="form-label" style="color:white">Address</label>
    <input type="text" class="form-control" id="inputAddress" placeholder="1234 Main St" name="address">
  </div>
  
  <div class="col-md-6">
    <label for="inputCity" class="form-label" style="color:white">City</label>
    <input type="text" class="form-control" id="inputCity" name="city">
  </div>
  <div class="col-md-6">
    <label for="mycity" class="form-label" style="color:white">State</label>
    <input type="text" class="form-control" id="mycity" name="state">
  </div>
  <div class="col-md-6">
    <label for="inputZip" class="form-label" style="color:white">Zip</label>
    <input type="text" class="form-control" id="inputZip" name="myzip">
  </div>
  <div>
  <label for="formFileLg" class="form-label" style="color:white">Upload Files </label>
  <input class="form-control form-control-lg" id="formFileLg" type="file" name="filename">
</div>
  
  <div class="col-12">
    <button type="submit" class="btn btn-primary">Submit</button>
  </div>
</form>

<div>
  <br>
  <div id="showAlert"></div>
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/js/bootstrap.bundle.min.js" integrity="sha384-A3rJD856KowSb7dwlZdYEkO39Gagi7vIsF0jrRAoQmDKKtQBHUuLZ9AsSv4jD4Xa" crossorigin="anonymous"></script>
  </body>
</html>
Get File For practice

एक टिप्पणी भेजें

0 टिप्पणियाँ