以下是我们产品中的功能之一 一种。用户单击“更新”按钮后,以字节格式读取Excel并将其发送到服务器(将字节存储到数据库的Java应用服务器)
b。获得成功响应后,excel将自动关闭。我没有发现任何异常。它仅在台式机版本中发生,但在在线版本中工作正常
以下是读取Excel并向服务器进行API调用的功能
function saveInput(){
Office.context.document.getFileAsync("compressed",
{ sliceSize: 100000 },
function (result) {
updateStatus(result.status);
if (result.status == Office.AsyncResultStatus.Succeeded) {
// Get the File object from the result.
var myFile = result.value;
var state = {
file: myFile,
counter: 0,
sliceCount: myFile.sliceCount
};
//updateStatus("Getting file of " + myFile.size + " bytes");
getSlice(state);
}
else {
// updateStatus("Please re-open the add-on and save the input");
}
});
}
function getSlice(state) {
state.file.getSliceAsync(state.counter, function (result) {
if (result.status == Office.AsyncResultStatus.Succeeded) {
//updateStatus("Sending piece " + (state.counter + 1) + " of " + state.sliceCount);
sendSlice(result.value, state);
}
else {
updateStatus(result.status);
}
state.file.closeAsync();
});
}
function sendSlice(slice, state) {
var data = slice.data;
// If the slice contains data, create an HTTP request.
if (data) {
var selectedCompany = $('#company-container').val();
var selectedScenario = $('#forecast-container').val();
var selectedUICompany = $('#company-container').data(selectedCompany);
var supportUIScenarios = $('#forecast-container').data(selectedScenario);
var sessionId = $('body').data('sessionId');
var companyId = selectedUICompany.uiCompany.dbId;
var companyVersion = selectedUICompany.uiCompany.version;
var companyUniqueId = selectedUICompany.uiCompany.companyId;
var companyDivisionName = selectedUICompany.uiCompany.uiCompanyDivisions[0].name;
var serviceProviderId = selectedUICompany.serviceProviderId;
var scenarioId = supportUIScenarios.docId;
var response=$('body').data('login-response');
var uiUser=response.uiUser;
var userId=uiUser.dbId;
var emailAddress = uiUser.emailAddress;
var dataR = {
'userId' : userId,
'emailAddress' : 'emailAddress',
'sessionId' : sessionId,
'companyId' : companyId,
'companyUniqueId' : companyUniqueId,
'companyVersion' : companyVersion,
'companyDivisionName' : companyDivisionName,
'serviceProviderId' : serviceProviderId,
'scenarioId' : scenarioId,
'excelStream' : data
};
$.ajax({
url: "https://example.com?&operationId=UPDATE_EXCEL_INPUT",
type: "POST",
crossDomain: true,
crossOrigin: true,
contentType: "application/json",
dataType: "json",
data: JSON.stringify(dataR),
headers: {
'sessionId': sessionId
},
success: function (response, status, xhr) {
var status = response.status;
if(status != 'success')
{
updateStatus(response.msg);
}else{
updateStatus("Update successful");
}
},
error: function (request, error) {
updateStatus(error);
}
});
}
}
有什么建议吗? 预先感谢。