Skip to content

teresagarcia/officeprops2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OfficeProps.js

Updated fork of 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 to be included alongside this package if not using node.

Node:

npm install officeprops

Or include via cdn:

<script src='https://cdn.jsdelivr.net/npm/jszip@3.10.1/dist/jszip.min.js'></script>
<script src='https://cdn.jsdelivr.net/npm/officeprops2@1.0.0/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.
})

For more, see Examples or Tests

About

Manipulate MS office and Open Office metadata

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 91.7%
  • HTML 8.3%