Skip to content

Instantly share code, notes, and snippets.

@kkamegawa kkamegawa/xslxNamespace.cs
Last active Aug 29, 2015

What would you like to do?
Create OpenXML Spreadsheet's xml namespace in LINQ to XML.
using System.Xml.Linq;
namespace XslxNameSpaceSample
class Program
static void XNamespaceSample()
const string openXmlMarkupSchema = "";
const string spreadSheetSchema = "";
const string relationshipSchema = "";
var sheetDocument = new XDocument();
sheetDocument.Declaration = new XDeclaration("1.0", "utf-8", "yes");
XNamespace xlsns = openXmlMarkupSchema;
XName mcIgnorableName = XName.Get("Ignorable", openXmlMarkupSchema);
XNamespace mcNameSpace = "mc";
XNamespace rNameSpace = "r";
XNamespace x14acNameSpace = "x14ac";
new XElement("worksheet",
new XAttribute(XNamespace.Xmlns + "r", relationshipSchema),
new XAttribute(XNamespace.Xmlns + "x14ac", spreadSheetSchema)));
var x14acPrefix = sheetDocument.Document.Root.GetPrefixOfNamespace(XNamespace.Get(spreadSheetSchema));
var rPrefix = sheetDocument.Document.Root.GetPrefixOfNamespace(XNamespace.Get(relationshipSchema));
var rNamePrefix = sheetDocument.Document.Root.GetNamespaceOfPrefix("r");
var x14acNamePrefix = sheetDocument.Document.Root.GetNamespaceOfPrefix("x14ac");
sheetDocument.Document.Root.Add(new XAttribute(XNamespace.Xmlns + "mc", mcIgnorableName.NamespaceName));
sheetDocument.Document.Root.Add(new XAttribute(mcIgnorableName, x14acPrefix));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.