Does the Word Automation Service or Excel Services contains API that allow us to create office document specifically in my case, an Excel document ?.

I need to create an Excel pro grammatically. I know it can be done using the COM interop

I would like to know if there are any "SharePoint Ways" to accomplish this?


Open XML API/SDK is the answer to your question..

Have a look at :

Creating and Publishing Excel 2010 Documents with Custom SharePoint 2010 Workflows
OpenXML Excel Generation - CodePlex
Writing data into excel document using openxml

And you can find many others if you search for it..

Download Open XML SDK 2.5 for Microsoft Office

  • Salam, Thanks. I've already went through that materials. As I said in my question, I'm looking for "SharePoint Ways". I was hoping the word automation services or Excel Services or any other ootb SharePoint API is available for me to accomplish my task. Thanks – Agamand The True Nov 10 '13 at 9:13
  • I didn't Open XML in your reference.. :) lets wait for other answers! – Arsalan Adam Khatri Nov 10 '13 at 11:19

If you want to stick with SharePoint programmatically, your best bet is to use the template of the document library, as that's the only way I know of to "create" a document. Essentially this code will pull from the Document Template of the SharePoint library. You, of course, need to have an Excel document as a template of the document library already in place.

using (SPSite site = new SPSite("http://sharepointsite"))
            using (SPWeb myWeb = site.OpenWeb())
               SPDocumentLibrary myLib = myWeb.Lists["Library Name"];
               SPFolder myFolder = myLib.RootFolder;
               SPFile myFile = myWeb.GetFile(myDocLib.DocumentTemplateUrl);
               myFolder.Files.Add("File name", myFile.OpenBinary(), true);

I think with this code and the OpenXML API that Arsalan Adam Khatri posted, you should be able to do what you want to with SharePoint programmatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.