Giter Site home page Giter Site logo

dom2docx's Introduction

dom2docx.js

Tool for creating Microsoft Word docx (OpenXML) document in the Browser. Pass a dom element to produce a .docx file of your dom elements. A default style is defined but this can be customised by passing in a custom styles.xml file. (See Customizing Styles section below)

Currently supported Dom elements: Paragraph (p), Bold (b), Strong (strong), Italic (i), Emphasis (em), Underline (u), Inserted (ins), Small (small), Strikethough (strike), Deleted (del), Superscript (sup), Subscript (sub), Highlighted (mark), Headings (h1-h6), Line Break (br) Unordered List (ul), List Item (li) Description List (dl), Description Term (dt), Description Description (dd)

Usage

See http://davestevens.github.io/dom2docx/ for example

Convert dom element to .docx File

// Include dom2docx.js
<script src="dist/dom2docx.min.js"></script>

// #input element in dom contains data which is to be converted to .docx
input = document.getElementById("input")

// Create instance on Dom2Docx
dom2docx = new Dom2Docx(input)

// Creates the dom to a File Blob object
docx = dom2docx.create()

// you can use `URL.createObjectURL` to create
link = document.createElement("a")
link.href = (window.URL || window.webkitURL).createObjectURL(docx)
link.download = "example.docx"
link.textContent = "Download File"
document.body.appendChild(link)

// Using FileSaver (see vendor/FileSaver.js)
// include FileSave.js
saveAs(docx, "example.docx")

Customizing Styles

TODO

Development

npm install

make all to generate all .js files

make watch-all to watch all .coffee files and convert to .js when changed

You can then use require("src/dom2docx") or build a js file to include in a page (see Compilation section)

TODO

  • Styles
  • Tables
  • Forms
  • Example Usage
  • gh-pages
  • How to Replace Styles

Compilation

node run build-js Create a minified javascript file: dist/dom2docx.min.js

node run build-js-dev Create a javascript file: dist/dom2docx.js

Tests

Command Line

npm test Runs tests with mocha-phantomjs

Browser

node run test-server Go to http://0.0.0.0:8081/test in a browser

dom2docx's People

Stargazers

Montisan avatar

Watchers

苏滋文 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.