Skip to content

Instantly share code, notes, and snippets.

@engalar
Created January 5, 2018 06:39
Show Gist options
  • Save engalar/02aef290034fb180d866d721bbac9658 to your computer and use it in GitHub Desktop.
Save engalar/02aef290034fb180d866d721bbac9658 to your computer and use it in GitHub Desktop.
const jszip = require('xlsx/jszip');
const fs = require('fs');
const XmlDocument = require('xmldoc').XmlDocument;
function get_rels_path(file) {
var n = file.lastIndexOf("/");
return file.substr(0,n+1) + '_rels/' + file.substr(n+1) + ".rels";
}
const filename = 'C:\\Users\\Administrator\\Desktop\\Book1.xlsx';
const zip = new jszip(fs.readFileSync(filename));
const xmlDocumentSheet = new XmlDocument(zip.files["xl/worksheets/sheet1.xml"].asBinary());
const xmlDocumentRel = new XmlDocument(zip.files[get_rels_path("xl/worksheets/sheet1.xml")].asBinary());
const attr = xmlDocumentSheet.childNamed('drawing').attr["r:id"];
const attr2 = xmlDocumentRel.childNamed('Relationship').attr["Id"];
const attr3 = xmlDocumentRel.childNamed('Relationship').attr["Target"];
const xmlDocumentDraw = new XmlDocument(zip.files[attr3.replace('..','xl')].asBinary());
const map = xmlDocumentDraw.children.map(v=>v.childNamed('xdr:from').childNamed('xdr:row').val);
console.log(map);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment