function myFunction() {
ex = SpreadsheetApp.openById("1FTKM8GZfmv9czrgn0rV9djNlm7W85PoW9v1iusqImUM");
sh = ex.getSheetByName("1市 勢");
number=sh.getLastRow();
var v=sh.getRange(1,1,number,40).getValues();
var indexline=-99;
for(s=0;s<15;s++){
for(sx=0;sx<5;sx++){
if(v[s][sx]=="函館市")indexline=sx;
}}
Logger.log(indexline);
fastline=0;
for(s=1;s<number;s++){
h=0;
if(v[s][indexline].indexOf("市")>-1)h=h+1;
if(fastline==0)h=h+1;
if(v[s][indexline].indexOf("市名")>-1)h=0;
if(v[s][indexline].indexOf("市 名")>-1)h=0;
if(h==2)fastline=s;
}
lastline=0;
for(s=fastline;s<number;s++){
h=0;
if(v[s][indexline].indexOf("市")>-1)h=h+1;
if(v[s][indexline].indexOf("中核")>-1)h=0;
if(v[s][indexline].indexOf("候補")>-1)h=0;
if(h==1)lastline=s;
}
Logger.log(lastline);
for(s=fastline;s<lastline+1;s++){
Logger.log(v[s][0]);
}
creditline=0;
for(s=1;s<fastline;s++){
if(v[s][indexline].indexOf("項")>-1)creditline=s;
}
Logger.log(creditline);
creditx=indexline+1;
credity=0;
for(sx=creditx;sx<40;sx++){
sp=""+v[creditline][sx]+v[creditline+1][sx]+v[creditline+2][sx]
if(sp.length>0)credity=sx;
}
Logger.log(credity);
id2="1DX_vaXcC6K-Fn0Nlg7P45e6OrNAZagIjlRg4gugVzbQ";
ex2 = SpreadsheetApp.openById(id2);
sh2 = ex2.getSheetByName("data");
var v2=new Array();
y2=lastline-fastline+1;
x2=credity-creditx+1;
for(s=0;s<y2+1;s++){
v2[s]=new Array();
}
for(s=0;s<y2+1;s++){
for(sx=0;sx<x2+1;sx++){
v2[s][sx]="*";
}}
for(s=1;s<y2+1;s++){
for(sx=1;sx<x2+1;sx++){
s1=s+fastline-1;
s2=sx+creditx-1;
v2[s][sx]=v[s1][s2];
}}
for(s=1;s<y2+1;s++){
s1=s+fastline-1;
v2[s][0]=v[s1][0];
}
for(sx=1;sx<x2+1;sx++){
s2=sx+creditx-1;
v2[0][sx]=v[creditline][s2];
}
sh2.getRange(1,1,y2+1,x2+1).setValues(v2);
}
最終更新:2018年07月14日 01:57