Accessing Spreadsheets using the Open XML SDK for JavaScript
Return to the
Open XML SDK for JavaScript
Developer CenterShows how to navigate to the workbook part, and then navigate to the appropriate worksheet part using the Open XML SDK for JavaScript.
Once you have an open workbook, first you need to get the workbook part:
var workbookPart = openedSpreadsheet.workbookPart(); var wbXDoc = workbookPart.getXDocument();
You can then find the relevant sheet element based on the name:
var sheetElement = wbXDoc.root .element(S.sheets) .elements(S.sheet) .firstOrDefault(function (sh) { return sh.attribute("name").value === 'Sheet1'; });
Once you have the sheet element, you can get the relationship id of the sheet:
var id = sheetElement.attribute(R.id).value; var worksheetPart = workbookPart.getPartById(id);
You can then get the XDocument for the worksheet, and then query it or make modifications to it:
var wsXDoc = worksheetPart.getXDocument(); var firstCell = wsXDoc.descendants(S.c).firstOrDefault(); if (firstCell) { var newFirstCell = new XElement(S.c, firstCell.attribute("r"), new XElement(S.v, "1000")); firstCell.replaceWith(newFirstCell); }
Here is the entire example:
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Shows opening a workbook / worksheet and making a mod to the upper left cell.</title> </head> <body> <form> <div style="margin-top: 1em; margin-bottom: 1em;"> <input id="btnSave" type="button" onclick="saveDocument()" value="Save" style="height: 30px; width: 100px; background-color: rgb(212,208,200); border: thin solid black;" /> </div> <p>If you are targeting down-level browsers that do not support HTML5, see <b>examp01-load-save-via-flash.html</b>.</p> </form> <pre> <script type="text/javascript" src="linq.js"></script> <script type="text/javascript" src="ltxml.js"></script> <script type="text/javascript" src="ltxml-extensions.js"></script> <script type="text/javascript" src="jszip.js"></script> <script type="text/javascript" src="jszip-load.js"></script> <script type="text/javascript" src="jszip-inflate.js"></script> <script type="text/javascript" src="jszip-deflate.js"></script> <script type="text/javascript" src="FileSaver.js"></script> <script type="text/javascript" src="openxml.js"></script> <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> /*************************************************************************** Copyright (c) Microsoft Corporation 2013. This code is licensed using the Microsoft Public License (Ms-PL). You can find the text of the license here: http://www.microsoft.com/resources/sharedsource/licensingbasics/publiclicense.mspx Published at http://OpenXmlDeveloper.org Resource Center and Documentation: http://openxmldeveloper.org/wiki/w/wiki/open-xml-sdk-for-javascript.aspx Developer: Eric White Blog: http://www.ericwhite.com Twitter: @EricWhiteDev Email: eric@ericwhite.com ***************************************************************************/ var saveSpreadsheet; var spreadsheetToSave; (function (root) { // root = global "use strict"; var XAttribute = Ltxml.XAttribute; var XCData = Ltxml.XCData; var XComment = Ltxml.XComment; var XContainer = Ltxml.XContainer; var XDeclaration = Ltxml.XDeclaration; var XDocument = Ltxml.XDocument; var XElement = Ltxml.XElement; var XName = Ltxml.XName; var XNamespace = Ltxml.XNamespace; var XNode = Ltxml.XNode; var XObject = Ltxml.XObject; var XProcessingInstruction = Ltxml.XProcessingInstruction; var XText = Ltxml.XText; var XEntity = Ltxml.XEntity; var cast = Ltxml.cast; var castInt = Ltxml.castInt; var S = openXml.S; var R = openXml.R; var templateSpreadsheet = "UEsDBBQABgAIAAAAIQD21qXvWgEAABgFAAATAAgCW0NvbnRlbnRfVHlwZXNdLnhtbCCiBAIooAAC" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAALwKAAB4bC90aGVtZS90aGVtZTEueG1sUEsBAi0AFAAGAAgAAAAhAH7BiuVg" + "AQAAdAIAABgAAAAAAAAAAAAAAAAAehEAAHhsL3dvcmtzaGVldHMvc2hlZXQyLnhtbFBLAQItABQA" + "BgAIAAAAIQB+wYrlYAEAAHQCAAAYAAAAAAAAAAAAAAAAABATAAB4bC93b3Jrc2hlZXRzL3NoZWV0" + "My54bWxQSwECLQAUAAYACAAAACEA4tgWRrcBAAB+AwAAGAAAAAAAAAAAAAAAAACmFAAAeGwvd29y" + "a3NoZWV0cy9zaGVldDEueG1sUEsBAi0AFAAGAAgAAAAhAIvQXzKGAgAAsQUAAA0AAAAAAAAAAAAA" + "AAAAkxYAAHhsL3N0eWxlcy54bWxQSwECLQAUAAYACAAAACEAFAWpyz0BAABRAgAAEQAAAAAAAAAA" + "AAAAAABEGQAAZG9jUHJvcHMvY29yZS54bWxQSwECLQAUAAYACAAAACEAaS/Zj5QBAABHAwAAEAAA" + "AAAAAAAAAAAAAAC4GwAAZG9jUHJvcHMvYXBwLnhtbFBLBQYAAAAACwALAMoCAACCHgAAAAA="; var xlsx = new openXml.OpenXmlPackage(); xlsx.openFromBase64Async(templateSpreadsheet, function (openedSpreadsheet) { var workbookPart = openedSpreadsheet.workbookPart(); var wbXDoc = workbookPart.getXDocument(); var sheetElement = wbXDoc.root .element(S.sheets) .elements(S.sheet) .firstOrDefault(function (sh) { return sh.attribute("name").value === 'Sheet1'; }); if (sheetElement) { var id = sheetElement.attribute(R.id).value; var worksheetPart = workbookPart.getPartById(id); var wsXDoc = worksheetPart.getXDocument(); var firstCell = wsXDoc.descendants(S.c).firstOrDefault(); if (firstCell) { var newFirstCell = new XElement(S.c, firstCell.attribute("r"), new XElement(S.v, "1000")); firstCell.replaceWith(newFirstCell); } } openedSpreadsheet.saveToBlobAsync(function (blob) { spreadsheetToSave = blob; }); }); root.saveDocument = function () { if (spreadsheetToSave === null) { alert("Spreadsheet is not open"); } else { saveAs(spreadsheetToSave, "SavedSpreadsheet.xlsx"); } } }(this)); </script> </pre> <div id="testContent"></div> </body> </html>
Cheers, Eric