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

Definition mismatch for method substituteHyperlinks - Throws runtime error #198

Open
satyajitnayk opened this issue Nov 19, 2024 · 0 comments

Comments

@satyajitnayk
Copy link

satyajitnayk commented Nov 19, 2024

In src/index.js
substituteHyperlinks(rels, substitutions) {
...
const relationships = rels.root._children;
...
}

In lib/index.ts
protected substituteHyperlinks(sheetFilename : any, substitutions : any) : void;

Definition in v1.0.0

Workbook.prototype.substituteHyperlinks = function(sheetFilename, substitutions) {
      let self = this;
      const sheetDirectory = path.dirname(sheetFilename),
        sheetName      = path.basename(sheetFilename),
        relsFilename   = sheetDirectory + "/" + '_rels' + "/" + sheetName + '.rels',
        relsFile       = self.archive.file(relsFilename);

      etree.parse(self.archive.file(self.sharedStringsPath).asText()).getroot();

      if(relsFile === null) {
        return;
      }

      const rels = etree.parse(relsFile.asText()).getroot();

      const relationships = rels._children;

      const newRelationships = [];

      relationships.forEach(function(relationship){
        newRelationships.push(relationship);

        if(relationship.attrib.Type === HYPERLINK_RELATIONSHIP) {

          let target = relationship.attrib.Target;

          //Double-decode due to excel double encoding url placeholders
          target = decodeURI(decodeURI(target));
          self.extractPlaceholders(target).forEach(function (placeholder) {
              const substitution = substitutions[placeholder.name];

              if (substitution === undefined) {
                return;
              }
              target = target.replace(placeholder.placeholder, self.stringify(substitution));

              relationship.attrib.Target = encodeURI(target);
            }
          );
        }
      });

      self.replaceChildren(rels, newRelationships);

      self.archive.file(relsFilename, etree.tostring(rels));
    };

Definition in v1.4.4

substituteHyperlinks(rels, substitutions) {
        let self = this;
        etree.parse(self.archive.file(self.sharedStringsPath).asText()).getroot();
        if (rels === null) {
            return;
        }
        const relationships = rels.root._children;
        relationships.forEach(function (relationship) {
            if (relationship.attrib.Type === HYPERLINK_RELATIONSHIP) {

                let target = relationship.attrib.Target;

                //Double-decode due to excel double encoding url placeholders
                target = decodeURI(decodeURI(target));
                self.extractPlaceholders(target).forEach(function (placeholder) {
                    const substitution = substitutions[placeholder.name];

                    if (substitution === undefined) {
                        return;
                    }
                    target = target.replace(placeholder.placeholder, self.stringify(substitution));

                    relationship.attrib.Target = encodeURI(target);
                }
                );
            }
        });
    }

Trying to migrate from v1.0.0 to v1.4.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant