function myFunction() {
id="1mKzhcldaXJ0NTqUPh-L8zaqF8MnkbeViI6WFictsg_0";
ex = SpreadsheetApp.openById(id);
sh = ex.getSheetByName("data");
number=sh.getLastRow()-1;
numberx=sh.getLastColumn()-1
var v=sh.getRange(1,1,number+1,numberx+1).getValues();
fastline=0;
for(s=1;s<20;s++){
str=""+v[s][0];
if(str.indexOf("Years/Months")>-1)fastline=s+1;
}
Logger.log(fastline);
for(s=fastline;s<number;s++){
str=""+v[s][0];
if(str.length>0)lastline=s+1;
}
Logger.log(lastline);
creditline=0;
for(s=1;s<fastline;s++){
str=""+v[s][0];
if(str.indexOf("報道")>-1)creditline=s;
}
Logger.log(creditline);
creditx=1;
credity=0;
for(sx=1;sx<numberx+1;sx++){
str=""+v[creditline+3][sx];
if(str.length>0)credity=sx;
}
var credit=new Array();
var subcredit=new Array();
for(sx=creditx;sx<credity+1;sx++){
credit[sx]=""+v[creditline][sx];
subcredit[sx]=""+v[creditline+1][sx];
}
for(sx=creditx;sx<credity+1;sx++){
h=0;
if(credit[sx].length>0)h=h+1;
if(subcredit[sx].length<1)h=h+1;
if(h==2)subcredit[sx]="合計";
}
for(sx=creditx;sx<credity+1;sx++){
h=0;
if(credit[sx].length<1)credit[sx]=credit[sx-1];
if(subcredit[sx].length<1)subcredit[sx]=subcredit[sx-1];
}
var m=new Array();
var q=new Array();
n=0;
for(sx=creditx;sx<credity+1;sx++){
str=""+v[creditline+3][sx]
if(str.indexOf("金")>-1)n=n+1;
if(str.indexOf("金")>-1)m[n]=sx;
}
Logger.log(n);
number_m=n;
n=0;
for(sx=creditx;sx<credity+1;sx++){
str=""+v[creditline+3][sx]
if(str.indexOf("数")>-1)n=n+1;
if(str.indexOf("数")>-1)q[n]=sx;
}
Logger.log(n);
number_q=n;
var delta_q=new Array();
for(s=0;s<lastline-fastline+3;s++){
delta_q[s]=new Array();
}
id="1mKzhcldaXJ0NTqUPh-L8zaqF8MnkbeViI6WFictsg_0";
ex = SpreadsheetApp.openById(id);
sh = ex.getSheetByName("数量");
for(s=fastline;s<lastline+1;s++){
s1=s-fastline+2;
delta_q[s1][0]=v[s][0];
for(sx=1;sx<number_q+1;sx++){
s2=q[sx];
delta_q[s1][sx]=""+v[s][s2];
}
}
for(sx=1;sx<number_q+1;sx++){
s2=q[sx];
delta_q[0][sx]=credit[s2];
delta_q[1][sx]=subcredit[s2];
}
sh.getRange(1,1,lastline-fastline+3,number_q+1).setValues(delta_q);
var delta_m=new Array();
for(s=0;s<lastline-fastline+3;s++){
delta_m[s]=new Array();
}
id="1mKzhcldaXJ0NTqUPh-L8zaqF8MnkbeViI6WFictsg_0";
ex = SpreadsheetApp.openById(id);
sh = ex.getSheetByName("金額");
for(s=fastline;s<lastline+1;s++){
s1=s-fastline+2;
delta_m[s1][0]=v[s][0];
for(sx=1;sx<number_m+1;sx++){
s2=m[sx];
delta_m[s1][sx]=""+v[s][s2];
}
}
for(sx=1;sx<number_m+1;sx++){
s2=m[sx];
delta_m[0][sx]=credit[s2];
delta_m[1][sx]=subcredit[s2];
}
sh.getRange(1,1,lastline-fastline+3,number_m+1).setValues(delta_m);
}
最終更新:2017年12月26日 07:26