事实上,我用截图库插入数据到谷歌表和它的工作罚款为一个或两行数据发送一次点击,但当我发送两行以上的数据插入谷歌表,然后它跳过了一些行,像一些5行,它只输入了2或3行,如果我一次发送大约10行数据,然后它有时也在插入2 0或3 4 5行数据。我只想在发送数据时按相同的顺序插入所有行数据。请帮助我哪里我错了实际上我是新的安卓系统。提前谢谢。
public class AdddatatoGSheet {
final Context context ;
public AdddatatoGSheet(Context context) {
this.context = context;
}
public void addItemToSheet(String USER_NAME,String Party,String Address,String State,String GSTIN, String Mobile, String EMAIL,String Closing_Balance,String ITEM,String GST,String CESS,String HSN,String SALE_RATE, String PUR_RATE,String QTY,String AMT,String GST_AMT,String CESS_AMT,String TOTAL)
{
// final ProgressDialog loading = ProgressDialog .show(context,"Adding Item","Please wait");
// final String name = editTextItemName.getText().toString().trim();
final String USER_NAMES = USER_NAME;
final String PartyS = Party;
final String AddressS = Address;
final String StateS = State;
final String GSTINS = GSTIN;
final String MobileS = Mobile;
final String EMAILS = EMAIL;
final String Closing_BalanceS = Closing_Balance;
final String ITEMS = ITEM;
final String GSTS = GST;
final String CESSS = CESS;
final String HSNS = HSN;
final String SALE_RATES = SALE_RATE;
final String PUR_RATES = PUR_RATE;
final String QTYS = QTY;
final String AMTS = AMT;
final String GST_AMTS = GST_AMT;
final String CESS_AMTS = CESS_AMT;
final String TOTALS = TOTAL;
StringRequest stringRequest = new StringRequest(Request.Method.POST, "https://script.google.com/macros/s/AKfycbxEI2Zua_79qLkUpMSpfyFjNEshYti8wPD34ZFrmsy45tLGJbE/exec",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> parmas = new HashMap<>();
parmas.put("action","addItem");
parmas.put("USER_NAME",USER_NAMES);
parmas.put("Party",PartyS);
parmas.put("Address",AddressS);
parmas.put("State",StateS);
parmas.put("GSTIN",GSTINS);
parmas.put("Mobile",MobileS);
parmas.put("EMAIL",EMAILS);
parmas.put("Closing_Balance",Closing_BalanceS);
parmas.put("ITEM",ITEMS);
parmas.put("GST",GSTS);
parmas.put("CESS",CESSS);
parmas.put("HSN",HSNS);
parmas.put("SALE_RATE",SALE_RATES);
parmas.put("PUR_RATE",PUR_RATES);
parmas.put("QTY",QTYS);
parmas.put("AMT",AMTS);
parmas.put("GST_AMT",GST_AMTS);
parmas.put("CESS_AMT",CESS_AMTS);
parmas.put("TOTAL",TOTALS);
return parmas;
}
};
int socketTimeOut = 20000;
RetryPolicy retryPolicy = new DefaultRetryPolicy(socketTimeOut, 0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES);
stringRequest.setRetryPolicy(retryPolicy);
RequestQueue queue = Volley.newRequestQueue(context);
queue.add(stringRequest);
}
}
在这里我调用additemtosheet方法。
private class adddata extends AsyncTask<ArrayList<HashMap<String, String>>, Integer, String> {
private String resp;
ProgressDialog progressDialog;
@Override
protected String doInBackground(ArrayList<HashMap<String, String>>... params) {
ArrayList<HashMap<String, String>> resultlist;
resultlist = params[0];
for (int i=0;i<resultlist.size();i++) {
HashMap<String, String> hmap = resultlist.get(i);
String a = hmap.get("snipervalues");
String b = hmap.get("snipervalues2");
String c = hmap.get("addrs");
String d = hmap.get("states");
String ee = hmap.get("gstins");
String f = hmap.get("mob");
String g = hmap.get("emails");
String h = hmap.get("c_blncs");
String ii = hmap.get("snumber");
String j = hmap.get("gstid1");
String k = hmap.get("cessid1");
String l = hmap.get("hsnid1");
String m = hmap.get("SaleRate1");
String n = hmap.get("purrateid1");
String o = hmap.get("qtyid1");
String p = hmap.get("amtid1");
String q = hmap.get("gstamtid1");
String r = hmap.get("cessamtid1");
String s = hmap.get("totalid1");
try {
String aa = a;
String bb = b;
String cc = c;
String dd = d;
String eee = ee;
String ff = f;
String gg = g;
String hh = h;
String iii = ii;
String jj = j;
String kk = k;
String ll = l;
String mm = m;
String nn = n;
String oo = o;
String pp = p;
String qq = q;
String rr = r;
String ss = s;
Log.d("value is ", aa + bb + cc + dd + eee + ff + gg + hh);
Log.d("value is new ", bb);
Log.d("value is ", oo);
adddatatoGSheet.addItemToSheet(aa, bb, cc, dd, eee, ff, gg, hh, iii, jj, kk, ll, mm, nn, oo, pp, qq, rr, ss);
//
} catch (Exception e) {
Log.d("Submit fail msz", e.getMessage());
}
}
String s2 = Boolean.toString(true);
return s2;
}
@Override
protected void onPostExecute(String result) {
// execution of result of Long time consuming operation
progressDialog.dismiss();
Intent intent = new Intent(selectparty.this,MainActivity.class);
startActivity(intent);
// finalResult.setText(result);
}
@Override
protected void onPreExecute() {
progressDialog = ProgressDialog.show(selectparty.this,
"ProgressDialog",
"Inserting Data to "+" GSheet...");
}
}
这是我的代码,不使用asynctask。用这种方法我得到了同样的问题。
public void addItemToSheet(String USER_NAME,String Party,String Address,String State,String GSTIN, String Mobile, String EMAIL,String Closing_Balance,String ITEM,String GST,String CESS,String HSN,String SALE_RATE, String PUR_RATE,String QTY,String AMT,String GST_AMT,String CESS_AMT,String TOTAL)
{
final ProgressDialog loading = ProgressDialog .show(context,"Adding Item","Please wait");
final String USER_NAMES = USER_NAME;
final String PartyS = Party;
final String AddressS = Address;
final String StateS = State;
final String GSTINS = GSTIN;
final String MobileS = Mobile;
final String EMAILS = EMAIL;
final String Closing_BalanceS = Closing_Balance;
final String ITEMS = ITEM;
final String GSTS = GST;
final String CESSS = CESS;
final String HSNS = HSN;
final String SALE_RATES = SALE_RATE;
final String PUR_RATES = PUR_RATE;
final String QTYS = QTY;
final String AMTS = AMT;
final String GST_AMTS = GST_AMT;
final String CESS_AMTS = CESS_AMT;
final String TOTALS = TOTAL;
StringRequest stringRequest = new StringRequest(Request.Method.POST, "https://script.google.com/macros/s/AKfycbxEI2Zua_79qLkUpMSpfyFjNEshYti8wPD34ZFrmsy45tLGJbE/exec",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
loading.dismiss();
Toast.makeText(context,response,Toast.LENGTH_LONG).show();
Intent intent = new Intent(context,MainActivity.class);
context.startActivity(intent);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}
) {
@Override
protected Map<String, String> getParams() {
Map<String, String> parmas = new HashMap<>();
parmas.put("action","addItem");
parmas.put("USER_NAME",USER_NAMES);
parmas.put("Party",PartyS);
parmas.put("Address",AddressS);
parmas.put("State",StateS);
parmas.put("GSTIN",GSTINS);
parmas.put("Mobile",MobileS);
parmas.put("EMAIL",EMAILS);
parmas.put("Closing_Balance",Closing_BalanceS);
parmas.put("ITEM",ITEMS);
parmas.put("GST",GSTS);
parmas.put("CESS",CESSS);
parmas.put("HSN",HSNS);
parmas.put("SALE_RATE",SALE_RATES);
parmas.put("PUR_RATE",PUR_RATES);
parmas.put("QTY",QTYS);
parmas.put("AMT",AMTS);
parmas.put("GST_AMT",GST_AMTS);
parmas.put("CESS_AMT",CESS_AMTS);
parmas.put("TOTAL",TOTALS);
return parmas;
}
};
int socketTimeOut = 500000;// u can change this .. here it is 50 seconds
RetryPolicy retryPolicy = new DefaultRetryPolicy(socketTimeOut, 0, DefaultRetryPolicy.DEFAULT_MAX_RETRIES);
stringRequest.setRetryPolicy(retryPolicy);
RequestQueue queue = Volley.newRequestQueue(context);
queue.add(stringRequest);
}
这是我的谷歌应用程序脚本插入数据到谷歌表,我需要在这里改变什么?
var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1v0X41-iWPt0QhCwSi8xWO8R8T0HmHj22vc_NcYgsDSk/edit#gid=0");
var sheet = ss.getSheetByName('Item11'); // be very careful ... it is the sheet name .. so it should match
function doPost(e){
var action = e.parameter.action;
if(action == 'addItem'){
return addItem(e);
}
}
function addItem(e){
var date = new Date();
//var timeStamp = date.getTime();
var currentTime = date.toLocaleTimeString();
var id = sheet.getLastRow(); // Item1
//var itemName = e.parameter.itemName;
//var brand = e.parameter.brand;
var USER_NAME = e.parameter.USER_NAME;
var Party = e.parameter.Party;
var Address = e.parameter.Address;
var State = e.parameter.State;
var GSTIN = e.parameter.GSTIN;
var Mobile = e.parameter.Mobile;
var EMAIL = e.parameter.EMAIL;
var Closing_Balance = e.parameter.Closing_Balance;
var ITEM = e.parameter.ITEM;
var GST = e.parameter.GST;
var CESS = e.parameter.CESS;
var HSN = e.parameter.HSN;
var SALE_RATE = e.parameter.SALE_RATE;
var PUR_RATE = e.parameter.PUR_RATE;
var QTY = e.parameter.QTY;
var AMT = e.parameter.AMT;
var GST_AMT = e.parameter.GST_AMT;
var CESS_AMT = e.parameter.CESS_AMT;
var TOTAL = e.parameter.TOTAL;
sheet.appendRow([id,date,currentTime,USER_NAME,Party,Address,State,GSTIN,Mobile,EMAIL,Closing_Balance,ITEM,GST,CESS,HSN,SALE_RATE,PUR_RATE,QTY,AMT,GST_AMT,CESS_AMT,TOTAL]);
return ContentService.createTextOutput("Success").setMimeType(ContentService.MimeType.TEXT);
}
暂无答案!
目前还没有任何答案,快来回答吧!