示例#1
0
        public void OpenAndSearchDocument(string docxFilePath, string xmlFilePath)
        {
            //split XML Read
            var   xml = File.ReadAllText(xmlFilePath);
            Split splitXml;

            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(xml)))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Split));
                splitXml = (Split)serializer.Deserialize(stream);
            }

            // Open a WordprocessingDocument for editing using the filepath.
            WordprocessingDocument wordprocessingDocument =
                WordprocessingDocument.Open(docxFilePath, true);

            // Assign a reference to the existing document body.
            Body             body    = wordprocessingDocument.MainDocumentPart.Document.Body;
            MarkerWordMapper mapping = new MarkerWordMapper(DocumentName, splitXml, body);

            DocumentElements = mapping.Run();

            // Close the handle explicitly.
            wordprocessingDocument.Close();
        }
示例#2
0
        public void OpenAndSearchDocument(Stream docxFile, Stream xmlFile)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(Split));
            Split         splitXml   = (Split)serializer.Deserialize(xmlFile);

            byte[] byteArray = StreamTools.ReadFully(docxFile);
            using (MemoryStream mem = new MemoryStream())
            {
                mem.Write(byteArray, 0, byteArray.Length);
                using (WordprocessingDocument wordDoc =
                           WordprocessingDocument.Open(mem, true))
                {
                    Body body = wordDoc.MainDocumentPart.Document.Body;
                    IMarkerMapper <OpenXmlElement> mapping = new MarkerWordMapper(DocumentName, splitXml, body);
                    DocumentElements = mapping.Run();
                }
            }
        }