Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/external reference read #3130

Merged
merged 3 commits into from
Nov 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 79 additions & 39 deletions cell/model/Serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@
SlicerCachesExt: 19,
SlicerCache: 20,
WorkbookProtection: 21,
OleSize: 22
OleSize: 22,
ExternalFileId: 23,
ExternalPortalName: 24
};
/** @enum */
var c_oSerWorkbookPrTypes =
Expand Down Expand Up @@ -3480,28 +3482,46 @@
};
this.WriteExternalReferences = function() {
var oThis = this;
for (var i = 0; i < this.wb.externalReferences.length; i++) {
var externalReference = this.wb.externalReferences[i];
switch (externalReference.Type) {
case 0:
this.bs.WriteItem(c_oSerWorkbookTypes.ExternalBook, function() {
oThis.WriteExternalReference(externalReference);
});
break;
case 1:
this.bs.WriteItem(c_oSerWorkbookTypes.OleLink, function() {
oThis.memory.WriteBuffer(externalReference.Buffer, 0, externalReference.Buffer.length);
});
break;
case 2:
this.bs.WriteItem(c_oSerWorkbookTypes.DdeLink, function() {
oThis.memory.WriteBuffer(externalReference.Buffer, 0, externalReference.Buffer.length);
});
break;
}
}

for(var i = 0, length = this.wb.externalReferences.length; i < length; ++i) {
this.bs.WriteItem( c_oSerWorkbookTypes.ExternalReference, function(){oThis.WriteExternalReference(oThis.wb.externalReferences[i]);});
}
};
this.WriteExternalReference = function(externalReference) {
this.WriteExternalReference = function(externalReference) {
var oThis = this;

if (externalReference.referenceData) {
if (externalReference.referenceData["fileId"]) {
oThis.memory.WriteByte(c_oSerWorkbookTypes.ExternalFileId);
oThis.memory.WriteByte(c_oSerPropLenType.Variable);
oThis.memory.WriteString2(externalReference.referenceData["fileId"].replaceAll('\"',"'"));
}
if (externalReference.referenceData["portalName"]) {
oThis.memory.WriteByte(c_oSerWorkbookTypes.ExternalPortalName);
oThis.memory.WriteByte(c_oSerPropLenType.Variable);
oThis.memory.WriteString2(externalReference.referenceData["portalName"]);
}
}

switch (externalReference.Type) {
case 0:
this.memory.WriteByte(c_oSerWorkbookTypes.ExternalBook);
this.memory.WriteByte(c_oSerPropLenType.Variable);
this.bs.WriteItemWithLength(function(){oThis.WriteExternalBook(externalReference);});
break;
case 1:
this.memory.WriteByte(c_oSerWorkbookTypes.OleLink);
this.memory.WriteByte(c_oSerPropLenType.Variable);
this.bs.WriteItemWithLength(function(){oThis.memory.WriteBuffer(externalReference.Buffer, 0, externalReference.Buffer.length);});
break;
case 2:
this.memory.WriteByte(c_oSerWorkbookTypes.OleLink);
this.memory.WriteByte(c_oSerPropLenType.Variable);
this.bs.WriteItemWithLength(function(){oThis.memory.WriteBuffer(externalReference.Buffer, 0, externalReference.Buffer.length);});
break;
}
};
this.WriteExternalBook = function(externalReference) {
var oThis = this;
if (null != externalReference.Id) {
oThis.memory.WriteByte(c_oSer_ExternalLinkTypes.Id);
Expand Down Expand Up @@ -7340,7 +7360,7 @@
}
else if ( c_oSerWorkbookTypes.ExternalReferences === type )
{
res = this.bcr.Read1(length, function(t,l){
res = this.bcr.Read1(length, function(t,l){
return oThis.ReadExternalReferences(t,l);
});
}
Expand Down Expand Up @@ -7567,23 +7587,43 @@
return res;
};
this.ReadExternalReferences = function(type, length) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerWorkbookTypes.ExternalBook == type) {
var externalBook = new AscCommonExcel.ExternalReference();
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadExternalBook(t, l, externalBook);
});
this.oWorkbook.externalReferences.push(externalBook);
} else if (c_oSerWorkbookTypes.OleLink == type) {
this.oWorkbook.externalReferences.push({Type: 1, Buffer: this.stream.GetBuffer(length)});
} else if (c_oSerWorkbookTypes.DdeLink == type) {
this.oWorkbook.externalReferences.push({Type: 2, Buffer: this.stream.GetBuffer(length)});
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
var oThis = this;
var res = c_oSerConstants.ReadOk;
if (c_oSerWorkbookTypes.ExternalReference === type) {
var externalReferenceExt = {};
res = this.bcr.Read1(length, function (t, l) {
return oThis.ReadExternalReference(t, l, externalReferenceExt);
});
if (externalReferenceExt.externalReference && externalReferenceExt.externalFileId && externalReferenceExt.externalPortalName) {
externalReferenceExt.externalReference.setReferenceData(externalReferenceExt.externalFileId.replaceAll("'", "\""), externalReferenceExt.externalPortalName);
}
} else
res = c_oSerConstants.ReadUnknown;
return res;
};
this.ReadExternalReference = function(type, length, externalReferenceExt) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
if (c_oSerWorkbookTypes.ExternalBook === type) {
var externalBook = new AscCommonExcel.ExternalReference();
res = this.bcr.Read1(length, function(t, l) {
return oThis.ReadExternalBook(t, l, externalBook);
});
externalReferenceExt.externalReference = externalBook;
this.oWorkbook.externalReferences.push(externalBook);
} else if (c_oSerWorkbookTypes.OleLink === type) {
this.oWorkbook.externalReferences.push({Type: 1, Buffer: this.stream.GetBuffer(length)});
} else if (c_oSerWorkbookTypes.DdeLink === type) {
this.oWorkbook.externalReferences.push({Type: 2, Buffer: this.stream.GetBuffer(length)});
} else if (c_oSerWorkbookTypes.ExternalFileId === type) {
externalReferenceExt.externalFileId = this.stream.GetString2LE(length);
} else if (c_oSerWorkbookTypes.ExternalPortalName === type) {
externalReferenceExt.externalPortalName = this.stream.GetString2LE(length);
} else {
res = c_oSerConstants.ReadUnknown;
}
return res;
};
this.ReadExternalBook = function(type, length, externalBook) {
var res = c_oSerConstants.ReadOk;
var oThis = this;
Expand Down
11 changes: 11 additions & 0 deletions cell/model/WorkbookElems.js
Original file line number Diff line number Diff line change
Expand Up @@ -14406,6 +14406,17 @@ QueryTableField.prototype.clone = function() {
}
};

ExternalReference.prototype.setReferenceData = function (fileId, portalName) {
if (!fileId || !portalName) {
return;
}
if (!this.referenceData) {
this.referenceData = {};
}
this.referenceData["portalName"] = portalName;
this.referenceData["fileId"] = fileId;
};

function asc_CExternalReference() {
this.type = null;
this.data = null;
Expand Down