2017-11-03 3 views
1

Google 스프레드 시트에서 셀 텍스트를 가져 와서 다음 코드를 사용하여 WordPress의 게시물에 삽입하고 있습니다. 하지만 얻을 가치가 300 개 이상 있습니다. 그래서, 300 회 이상 긴 시트 URL을 처리하지 않고 가져 오기가 쉬운 방법인지 궁금합니다. 또한 php에있을 수 있으므로 내 page.php 파일에 삽입 하겠지만 어떻게해야하는지 잘 모릅니다.Google 스프레드 시트에서 DB 가져 오기

jQuery.ajax("https://docs.google.com/spreadsheets/d/e/2PACX-1vQhp9yFq8eXagN03gn-mCN3_KPWRc2EIpswDFpHJLflFOG-XU2OMktqj03gxvUBZMAp8gYwWO5Q3MVJ/pub?gid=942917560&single=true&range=c3&output=csv").done(function(txt1){ 
 
       jQuery("#text1").html(txt1); 
 
}); 
 

 
jQuery.ajax("https://docs.google.com/spreadsheets/d/e/2PACX-1vQhp9yFq8eXagN03gn-mCN3_KPWRc2EIpswDFpHJLflFOG-XU2OMktqj03gxvUBZMAp8gYwWO5Q3MVJ/pub?gid=942917560&single=true&range=c4&output=csv").done(function(txt2){ 
 
       jQuery("#text2").html(txt2); 
 
}); 
 

 
jQuery.ajax("https://docs.google.com/spreadsheets/d/e/2PACX-1vQhp9yFq8eXagN03gn-mCN3_KPWRc2EIpswDFpHJLflFOG-XU2OMktqj03gxvUBZMAp8gYwWO5Q3MVJ/pub?gid=942917560&single=true&range=c5&output=csv").done(function(txt3){ 
 
       jQuery("#text3").html(txt3); 
 
});
<div id='text1'></div> 
 
<div id='text2'></div> 
 
<div id='text3'></div>

답변

1

음, 첫째로, 당신은 왜 스프레드 시트 (300) 전화를하고있다? 그냥 한 번 전화해서 관심있는 세포를 얻으십시오. single URL에 매개 변수가 있고 false로 설정 한 다음 원하는 셀 범위를 전달하십시오. 나는 사람들이 무엇 세포를 알 수 없기 때문에

는하지만, 난 당신이 할 수있는 것 같아요 :

function getCell(cell, id) { 
    var url = "https://docs.google.com/spreadsheets/d/e/2PACX-1vQhp9yFq8eXagN03gn-mCN3_KPWRc2EIpswDFpHJLflFOG-XU2OMktqj03gxvUBZMAp8gYwWO5Q3MVJ/pub?gid=942917560&single=true&range=" 
       + cell + "&output=csv"; 
    jQuery.ajax(url).done(function(t){ 
      $(id).html(t); 
    }); 
} 

for (var i = 0; i < 300; i++) { 
    var cell = 'c' + (i+3);  //first iteration: "c3" 
    var dest = '#text' + (i+1); //first iteration: "#text1" 
    getCell(cell, dest); 
} 
+0

완벽! 고마워. – crloa

관련 문제