Following is the one of the functionality in our product a. Once user clicks on 'update' button, reads the Excel in byte format and send it to the server(java application server which saves that byte to database)
b. After getting success response, the excel is getting closed automatically. I didn't find any exception.It's happening only in desktop version, but working fine in online version
Following is function which read the excel and makes an API call to the server
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);
}
});
}
}
Any suggestions? Thanks in advance.