我需要将电子表格的数据发送到其他服务器,我已经尝试了这个。我没有收到错误但是它也没有用。
我尝试了许多事情,但没有快乐。
var ss = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
var menuEntries = [ {name: "Send to PLM", functionName: "email"} ];
ss.addMenu("MyMenu", menuEntries);
}
function email() {
//Browser.msgBox("Hello World");
//var url = "http://********/noetic_Data/AddDataToAras?data=";
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var columns = sheet.getDataRange();
var numRows = rows.getNumRows();
var numColumns = rows.getNumColumns();
var values = rows.getValues();
for (var i = 0; i <= numRows - 1; i++) {
for (var j = 0; j <= numColumns - 1; j++) {
var row = values[i][j];
var cell = sheet.getRange(i+1,j+1);
}
}
Logger.log(numRows+"::"+numColumns);
var excelData = "";
for(var k=0;k<values.length;k++)
{
if(excelData == "")
{
excelData = values[k];
}
else
{
excelData = excelData +"|"+ values[k];
}
}
Browser.msgBox(excelData) ;
return excelData;
//var url = "http://*****/noetic_Data/AddDataToAras?data="+excelData;
var response = UrlFetchApp.getRequest("http://******/noetic_Data/AddDataToArasdata=", excelData)
//fetch("******/noetic_Data/AddDataToAras?data=", excelData);
Logger.log(response.getContentText());
// s = s+excelData;
//return s;
}
&#13;
答案 0 :(得分:1)
var ss = SpreadsheetApp.getActiveSpreadsheet();
function onOpen() {
var sheet = SpreadsheetApp.getActiveSheet();
var rows = sheet.getDataRange();
var columns = sheet.getDataRange();
var numRows = rows.getNumRows();
var numColumns = rows.getNumColumns();
var values = rows.getValues();
for (var i = 0; i <= numRows - 1; i++) {
for (var j = 0; j <= numColumns - 1; j++) {
var row = values[i][j];
var cell = sheet.getRange(i+1,j+1);
}
}
var excelData = "";
for(var k=0;k<values.length;k++)
{
if(excelData == "")
{
excelData = values[k];
}
else
{
excelData = excelData +"|"+ values[k];
}
}
//Bowser.msgBox(excelData) ; //***to view data on browser****
var shUi = SpreadsheetApp.getUi();
var app = UiApp.createApplication().setTitle('Custom functions');
var panel = app.createVerticalPanel().add(app.createHTML('Click the button bellow to send data to PLM')
.setStyleAttribute('padding','10px'));
var grid = app.createGrid(1,2).setWidth('200');
var b1 = app.createButton("send to PLM");
var link = app.createAnchor('XXXXX',"http://***.**.*.***/noetic_Data/AddDataToAras?data="+excelData).setStyleAttributes({'zIndex':'1' , 'position':'fixed' , 'top':'45' , 'left':'20', 'color':'transparent' }).setTitle('proceed in a new tab');
var G1 = app.createVerticalPanel().add(b1).add(link);
grid.setWidget(0,0,G1);
app.add(panel).add(grid)
shUi.showSidebar(app);
}