8
votes

I have an application that needs to create simple OpenXML documents (in particular PowerPoint presentations) using JavaScript.

Can anyone suggest how to get started on this please (or even if it is possible)? I've used the Microsoft OpenXML SDK for doing something similar using C#, and was wondering whether there were any JavaScript libraries with similar functionality.

Essentially the problem is how to create the individual OpenXML documents that make up an unzipped PowerPoint document, then zip them together to create the PowerPoint (.pptx) file, which someone can then save to their disk.

Any ideas welcome!

3
Why do you need to do it client-side? It's almost impossible and very uncomfortable, while doing it server-side is a breeze in almost any language.Viruzzo
I agree with Viruzzo, you should consider implementing it server-side. If it's acceptable, you can publish it as a web service and call its methods from java script by using AJAX calls.Lukasz M
Yes I agree that doing it client-side would be much easier (& is what I did on a previous project). But in this case the client wants something that will run stand-alone and with cross-browser compatibility.Appetere
for great cross-browser compatibility, implement it server-side. What does your client mean by "stand-alone", in this case?Michael Paulukonis
Maybe you can try to manually create an empty OpenXML file (i.e. an empty pptx) as a base template and then try to work on it as an XML with java script code. It could be much easier than creating the file with java script, however, it still seems like a lot of work to do.Lukasz M

3 Answers

0
votes

Obviously, operations such as Zipping/unZipping a document or saving a document cannot be done client-side and with pure javascript.

However, if you want to do such things, I do believe that there are Linux packages out there that accept strings as input and give you a ready to use Office document as output.

If you're not convenient with Linux packages, assuming you want to save this as a word 2007 document:

<?xml version="1.0" encoding="utf-8"?> 
<w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"> 
    <w:body> 
        <w:p> 
            <w:pPr> 
            <w:pStyle w:val="MyHeading1" /> 
            </w:pPr> 
            <w:r> 
            <w:t>This is Heading</w:t> 
            </w:r> 
        </w:p> 
    </w:body> 
</w:document>

You can build this string, client-side. then send it to server through AJAX and let your server deal with it. specifically I have used these APIs myself multiple times. let PHP handle it. save the result somewhere, or force client's browser to download it (stream results)

0
votes

USE OPEN XML SDK. You can run it on node and in 32 seconds it creates 2000 documents. Or you can run it on the browser.