Beispiel #1
0
        public XDocument GetDocument()
        {
            var w        = _ns.NamespaceMain;
            var workbook = new XElement(w.GetName("workbook"));

            workbook.Add(new XElement(w.GetName("sheets"),
                                      Worksheets.Select(ws => new XElement(w.GetName("sheet"),
                                                                           new XAttribute("name", ws.Name),
                                                                           new XAttribute(_ns.NamespaceRel.GetName("id"), ws.RelId),
                                                                           new XAttribute("sheetId", ws.Id)))));

            return(new XDocument(_ns.DefaultDeclaration, workbook));
        }
Beispiel #2
0
 public IEnumerable <string> GetAllSheetNames()
 {
     return(Worksheets.Select(i => i.Name));
 }
Beispiel #3
0
        private void GenerateExtendedFilePropertiesPartContent(ExtendedFilePropertiesPart extendedFilePropertiesPart)
        {
            if (extendedFilePropertiesPart.Properties == null)
            {
                extendedFilePropertiesPart.Properties = new DocumentFormat.OpenXml.ExtendedProperties.Properties();
            }

            var properties = extendedFilePropertiesPart.Properties;

            if (
                !properties.NamespaceDeclarations.Contains(new KeyValuePair <string, string>("vt",
                                                                                             "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes")))
            {
                properties.AddNamespaceDeclaration("vt",
                                                   "http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes");
            }

            if (properties.Application == null)
            {
                properties.AppendChild(new Application {
                    Text = "Microsoft Excel"
                });
            }

            if (properties.DocumentSecurity == null)
            {
                properties.AppendChild(new DocumentSecurity {
                    Text = "0"
                });
            }

            if (properties.ScaleCrop == null)
            {
                properties.AppendChild(new ScaleCrop {
                    Text = "false"
                });
            }

            if (properties.HeadingPairs == null)
            {
                properties.HeadingPairs = new HeadingPairs();
            }

            if (properties.TitlesOfParts == null)
            {
                properties.TitlesOfParts = new TitlesOfParts();
            }

            properties.HeadingPairs.VTVector = new VTVector {
                BaseType = VectorBaseValues.Variant
            };

            properties.TitlesOfParts.VTVector = new VTVector {
                BaseType = VectorBaseValues.Lpstr
            };

            var vTVectorOne = properties.HeadingPairs.VTVector;

            var vTVectorTwo = properties.TitlesOfParts.VTVector;

            var modifiedWorksheets =
                Worksheets.Select(w => new { w.Name, Order = w.Position }).ToList();
            var modifiedWorksheetsCount = modifiedWorksheets.Count;

            InsertOnVtVector(vTVectorOne, "Worksheets", 0, modifiedWorksheetsCount.ToString());

            vTVectorTwo.Size = (UInt32)(modifiedWorksheetsCount);

            foreach (var vTlpstr3 in modifiedWorksheets.OrderBy(w => w.Order).Select(w => new VTLPSTR {
                Text = w.Name
            }))
            {
                vTVectorTwo.AppendChild(vTlpstr3);
            }
        }