コード例 #1
0
        private static string GetTextFromFileData(byte[] fileDate, Constants.FileFormats format)
        {
            string textFull = string.Empty;

            switch (format)
            {
            case Constants.FileFormats.doc:
            {
                textFull = GetTextFromXmlDocument(OldDocReader.GetXMLContent(fileDate));
                break;
            }

            case Constants.FileFormats.docx:
            {
                textFull = GetTextFromDocx(fileDate);
                break;
            }

            case Constants.FileFormats.txt:
            {
                textFull = GetContentFromTxt(fileDate);
                break;
            }
            }
            return(textFull);
        }
コード例 #2
0
        private static string[] GetTextFromStyledData(byte[] fileDate, Constants.FileFormats format)
        {
            switch (format)
            {
            case Constants.FileFormats.doc:
                return(GetTextFromStyledXmlDocument(OldDocReader.GetXMLContent(fileDate)));

            case Constants.FileFormats.docx:
                return(GetTextFromStyledDocx(fileDate));

            default:
                return(null);
            }
        }
コード例 #3
0
        private static bool IsStyledSource(byte[] fileDate, Constants.FileFormats format)
        {
            switch (format)
            {
            case Constants.FileFormats.doc:
            {
                XmlDocument         xdoc          = OldDocReader.GetXMLContent(fileDate);
                const string        wordNamespace = "http://schemas.openxmlformats.org/wordprocessingml/2006/main";
                NameTable           nt            = new NameTable();
                XmlNamespaceManager nsManager     = new XmlNamespaceManager(nt);
                nsManager.AddNamespace("w", wordNamespace);

                XmlNodeList parNodes = xdoc.SelectNodes("//w:p", nsManager);

                foreach (XmlNode parNode in parNodes)
                {
                    if (parNode.OuterXml.Contains("Heading3"))
                    {
                        return(true);
                    }
                }
                break;
            }

            case Constants.FileFormats.docx:
            {
                using (Stream stream = new MemoryStream(fileDate))
                {
                    try
                    {
                        using (WordprocessingDocument wDocument = WordprocessingDocument.Open(stream, false))
                        {
                            Body body = wDocument.MainDocumentPart.Document.Body;
                            return(body.Descendants <ParagraphStyleId>().Any(psId => psId.Val == "3"));
                        }
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Неверная структура docx документа - " + ex.Message);
                    }
                }
            }

            case Constants.FileFormats.txt:
                return(false);
            }
            return(false);
        }