officeprops
v1.1.5
Published
Manipulate MS office and Open Office metadata
Downloads
60
Maintainers
Readme
OfficeProps.js
A JavaScript library used to extract, edit or remove metadata in Microsoft Office and Open Office files.
Supports:
- docx, dotx, docm, dotm
- xlsx, xlsm, xlsb, xltm, xltx
- pptx, ppsx, ppsm, pptm, potm, potx
- ods, odt, odp
Install:
Officeprops relies on JSZip which has be included alongside this package if not using node.
Node:
npm install officeprops
Or include via cdn:
<script src='https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/[email protected]/src/officeprops.js'></script>
Usage:
The package adds a global "OFFICEPROPS" variable.
All functions take a File or Blob as parameter, or a Buffer in Node.
Get metadata:
OFFICEPROPS.getData(file).then(function(metadata){
console.log(metadata.editable);
console.log(metadata.readOnly);
}
Metadata Format:
Open office property names are translated to MS Office names. e.g. "editing-duration" becomes "totalTime".
Returns the actual value, as well as a translated one for each property.
metadata = {
editable: {
totalTime: {
value: "PT3M43S", //actual value
tvalue: "3 minutes", //translated value
xmlPath: "office:meta/meta:editing-duration"
},
creator: {
value: "Torkel Velure",
tvalue: "Torkel Velure",
xmlPath: "office:meta/meta:initial-creator"
}
//...see OFFICEPROPS.properties for full list of properties
},
readOnly: {
slideTitles: ["Slide1, slide2, slide3"],
titles: ["title1", "title2"]
worksheets: ["sheet1"]
}
}
Edit metadata:
OFFICEPROPS.getData(file).then(function(metadata){
metadata.editable.creator.value = "New author";
OFFICEPROPS.editData(file,metadata).then(function(officeFile){
console.log(officeFile) // blob/nodestream containing edited file.
}
}
Remove metadata:
OFFICEPROPS.removeData(file).then(function(officeFile){
console.log(officeFile) // blob/nodestream with metadata removed.
}