Пример #1
0
        protected override void DoUofToOoxMainTransform(string inputFile, string outputFile, string resourceDir)
        {
            XmlUrlResolver    resourceResolver;
            XPathDocument     xslDoc;
            XmlReaderSettings xrs          = new XmlReaderSettings();
            XmlReader         source       = null;
            XmlWriter         writer       = null;
            string            mainOutput   = Path.GetDirectoryName(inputFile) + Path.AltDirectorySeparatorChar + "mainOutput.xml";
            string            equAfterMain = Path.GetDirectoryName(inputFile) + Path.AltDirectorySeparatorChar + "equAfterMain.xml";

            try
            {
                xrs.ProhibitDtd = true;
                string xslLocation = TranslatorConstants.UOFToOOX_XSL;
                if (outputFile == null)
                {
                    xslLocation = TranslatorConstants.UOFToOOX_COMPUTE_SIZE_XSL;
                }

                if (resourceDir == null)
                {
                    resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                            this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Excel.uof2oox");
                    xslDoc          = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream(xslLocation));
                    xrs.XmlResolver = resourceResolver;
                    source          = XmlReader.Create(inputFile);
                }
                else
                {
                    resourceResolver = new XmlUrlResolver();
                    xslDoc           = new XPathDocument(resourceDir + "/" + xslLocation);
                    source           = XmlReader.Create(resourceDir + "/" + TranslatorConstants.SOURCE_XML, xrs);
                }
                try
                {
                    XslCompiledTransform xslt     = new XslCompiledTransform();
                    XsltSettings         settings = new XsltSettings(true, false);
                    //Assembly ass = Assembly.Load("excel_uof2oox");
                    //Type t = ass.GetType("uof2oox");
                    // xslt.Load(t);
                    xslt.Load(xslDoc, settings, resourceResolver);
                    XsltArgumentList parameters = new XsltArgumentList();
                    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
                    //if (outputFile != null)
                    //{
                    //    parameters.AddParam("outputFile", "", outputFile);
                    //    writer = new OoxZipWriter(inputFile);
                    //}
                    //else
                    //{
                    //    writer = new XmlTextWriter(new StringWriter());
                    //}

                    //xslt.Transform(source, parameters, writer);
                    XmlTextWriter fs = new XmlTextWriter(mainOutput, Encoding.UTF8);
                    xslt.Transform(source, parameters, fs);
                    fs.Close();

                    SetDrawingTwoCellAnchorValue(mainOutput, equAfterMain);

                    // 增加对公式的互操作支持
                    // EquInter(mainOutput, equAfterMain);

                    xslLocation = TranslatorConstants.UOFToOOX_POSTTREAT_STEP1_XSL;

                    if (resourceDir == null)
                    {
                        resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                                this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Excel.uof2oox");
                        xslDoc          = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream(xslLocation));
                        xrs.XmlResolver = resourceResolver;
                        source          = XmlReader.Create(equAfterMain);
                    }
                    XslCompiledTransform xslt2     = new XslCompiledTransform();
                    XsltSettings         settings2 = new XsltSettings(true, false);
                    xslt.Load(xslDoc, settings2, resourceResolver);

                    XsltArgumentList parameters2 = new XsltArgumentList();
                    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
                    if (outputFile != null)
                    {
                        parameters2.AddParam("outputFile", "", outputFile);
                        writer = new OoxZipWriter(equAfterMain);
                    }
                    else
                    {
                        writer = new XmlTextWriter(new StringWriter());
                    }

                    xslt.Transform(source, parameters2, writer);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
                if (source != null)
                {
                    source.Close();
                }
            }
        }
Пример #2
0
        protected override void DoOoxToUofMainTransform(string originalFile, string inputFile, string outputFile, string resourceDir)
        {
            // 图片预处理
            XmlDocument xmlDoc      = new XmlDocument();
            string      wordPrePath = Path.GetDirectoryName(inputFile) + Path.DirectorySeparatorChar;
            string      picture_xml = "XLSX\\xl\\media";
            string      tmpPic      = wordPrePath + "tmpPic.xml";

            if (Directory.Exists(wordPrePath + picture_xml))
            {
                XmlNamespaceManager nms = new XmlNamespaceManager(xmlDoc.NameTable);
                nms.AddNamespace("ws", TranslatorConstants.XMLNS_WS);
                nms.AddNamespace("w", TranslatorConstants.XMLNS_W);
                xmlDoc.Load(inputFile);
                xmlDoc = PicPretreatment(xmlDoc, "ws:spreadsheets", wordPrePath + picture_xml, nms);
                xmlDoc.Save(tmpPic);
                inputFile = tmpPic;
            }


            // add by linyaohu new function the smartArt 2013-03-05
            XmlDocument doc = new XmlDocument();

            doc.Load(inputFile);
            string tmpSmartArtFile = wordPrePath + "tmpSmartArt.xml";
            XmlNamespaceManager nm = new XmlNamespaceManager(doc.NameTable);

            nm.AddNamespace("ws", TranslatorConstants.XMLNS_WS);
            nm.AddNamespace("xdr", TranslatorConstants.XMLNS_XDR);
            nm.AddNamespace("r", TranslatorConstants.XMLNS_PR);
            nm.AddNamespace("dsp", TranslatorConstants.XMLNS_DSP);

            XmlNodeList workSheets = doc.SelectNodes("//ws:spreadsheet", nm);

            for (int i = 1; i < workSheets.Count + 1; i++)
            {
                XmlNode smartArtRel = doc.SelectSingleNode("//ws:spreadsheet[" + i + "]/ws:Drawings/xdr:wsDr//r:Relationships", nm);
                if (smartArtRel != null)
                {
                    XmlNodeList smartArtRelDrawings = smartArtRel.SelectNodes("r:Relationship[@Type='http://schemas.microsoft.com/office/2007/relationships/diagramDrawing']", nm);
                    foreach (XmlNode smartArtRelDr in smartArtRelDrawings)
                    {
                        string target     = smartArtRelDr.Attributes["Target"].InnerText;
                        string targetFile = wordPrePath + "XLSX\\XL\\" + target.Substring(3);

                        XmlDocument smartArtDrawing = new XmlDocument();
                        smartArtDrawing.Load(targetFile);

                        // add the drawing file
                        XmlNode      drawingFile     = doc.CreateElement("dsp", "drawing", TranslatorConstants.XMLNS_DSP);
                        XmlAttribute drawingFileName = doc.CreateAttribute("id");

                        // target="../diagrams/xxx.xml", get the xxx.xml
                        drawingFileName.Value = target.Substring(12);
                        drawingFile.Attributes.Append(drawingFileName);
                        drawingFile.InnerXml = smartArtDrawing.SelectSingleNode("dsp:drawing", nm).InnerXml;
                        smartArtRel.ParentNode.AppendChild(drawingFile);
                    }
                }
            }
            doc.Save(tmpSmartArtFile);
            inputFile = tmpSmartArtFile;


            // main transform
            XmlUrlResolver resourceResolver = null;

            try
            {
                resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                        this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Excel.oox2uof");
                MainTransform(TranslatorConstants.OOXToUOF_XSL, resourceResolver, originalFile, inputFile, outputFile);
            }
            catch (Exception ex)
            {
                logger.Warn(ex.Message);
            }
        }
Пример #3
0
        protected override void DoUofToOoxMainTransform(string inputFile, string outputFile, string resourceDir)
        {
            XmlUrlResolver    resourceResolver;
            XPathDocument     xslDoc;
            XmlReaderSettings xrs    = new XmlReaderSettings();
            XmlReader         source = null;
            XmlWriter         writer = null;

            try
            {
                // xrs.ProhibitDtd = true;
                string xslLocation = TranslatorConstants.UOFToOOX_XSL;
                if (outputFile == null)
                {
                    xslLocation = TranslatorConstants.UOFToOOX_COMPUTE_SIZE_XSL;
                }

                if (resourceDir == null)
                {
                    resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                            this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Powerpoint.uof2oox");
                    xslDoc          = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream(xslLocation));
                    xrs.XmlResolver = resourceResolver;
                    source          = XmlReader.Create(inputFile);
                }
                else
                {
                    resourceResolver = new XmlUrlResolver();
                    xslDoc           = new XPathDocument(resourceDir + "/" + xslLocation);
                    source           = XmlReader.Create(resourceDir + "/" + TranslatorConstants.SOURCE_XML, xrs);
                }
                try
                {
                    XslCompiledTransform xslt     = new XslCompiledTransform();
                    XsltSettings         settings = new XsltSettings(true, false);
                    xslt.Load(xslDoc, settings, resourceResolver);
                    //Assembly ass = Assembly.Load("ppt_uof2oox");
                    //Type t = ass.GetType("uof2oox");
                    //xslt.Load(t);
                    XsltArgumentList parameters = new XsltArgumentList();
                    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);
                    if (outputFile != null)
                    {
                        parameters.AddParam("outputFile", "", outputFile);
                        parameters.AddParam("FileType", "", "Prsentation");
                        writer = new OoxZipWriter(inputFile);
                    }
                    else
                    {
                        writer = new XmlTextWriter(new StringWriter());
                    }
                    xslt.Transform(source, parameters, writer);
                }
                catch (Exception ex)
                {
                    logger.Error("Fail in the main translator of Presentation", ex);
                }
            }
            finally
            {
                if (writer != null)
                {
                    writer.Close();
                }
                if (source != null)
                {
                    source.Close();
                }
            }
        }
Пример #4
0
        public override bool transform()
        {
            //XmlUrlResolver resourceResolver = null;

            //try
            //{

            //    resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
            //        this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Powerpoint.oox2uof");
            //    MainTransform(TranslatorConstants.OOXToUOF_XSL, resourceResolver, originalFile, grpTmp, outputFile);

            //}
            //catch (Exception ex)
            //{
            //    logger.Warn(ex.Message);
            //}


            string numberRefTmp = Path.GetDirectoryName(originalFile) + "\\" + "numberRefTmp.xml";
            //  NumberRef(inputFile, numberRefTmp);
            //   deleteLayoutAnchors(inputFile);
            bool result = true;

            //  XmlTextWriter resultWriter = null;


            #region change the IDs in the UOF file to fix a bug
            //更改输出文件的ID值,以使从UOF转化为OPENXML时,Layout的id能正常转换
            //added by SYBASE 2009.07.08
            XmlDocument doc = new XmlDocument();
            //doc.Load(@"C:\Users\v-xipia\Desktop\test.xml");
            //  doc.Load(outputFile);
            doc.Load(inputFile);

            XmlTextWriter tw = null;

            // Create an XmlNamespaceManager to resolve the default namespace.
            XmlNamespaceManager nmgr = new XmlNamespaceManager(doc.NameTable);
            //nsmgr.AddNamespace("bk", "urn:newbooks-schema");
            nmgr.AddNamespace("字", TranslatorConstants.XMLNS_UOFWORDPROC);
            nmgr.AddNamespace("uof", TranslatorConstants.XMLNS_UOF);
            nmgr.AddNamespace("图", TranslatorConstants.XMLNS_UOFGRAPH);
            nmgr.AddNamespace("表", TranslatorConstants.XMLNS_UOFSPREADSHEET);
            nmgr.AddNamespace("演", TranslatorConstants.XMLNS_UOFPRESENTATION);
            nmgr.AddNamespace("a", TranslatorConstants.XMLNS_A);
            nmgr.AddNamespace("app", TranslatorConstants.XMLNS_APP);
            nmgr.AddNamespace("cp", TranslatorConstants.XMLNS_CP);
            nmgr.AddNamespace("dc", TranslatorConstants.XMLNS_DC);
            nmgr.AddNamespace("dcmitype", TranslatorConstants.XMLNS_DCMITYPE);
            nmgr.AddNamespace("dcterms", TranslatorConstants.XMLNS_DCTERMS);
            nmgr.AddNamespace("fo", TranslatorConstants.XMLNS_FO);
            nmgr.AddNamespace("p", TranslatorConstants.XMLNS_P);
            nmgr.AddNamespace("r", TranslatorConstants.XMLNS_R);
            nmgr.AddNamespace("rel", TranslatorConstants.XMLNS_REL);
            nmgr.AddNamespace("元", TranslatorConstants.XMLNS_METADATA);
            nmgr.AddNamespace("对象", TranslatorConstants.XMLNS_UOFOBJECTS);
            nmgr.AddNamespace("式样", TranslatorConstants.XMLNS_UOFSTYLES);
            nmgr.AddNamespace("pzip", "urn:u2o:xmlns:post-processings:special");
            nmgr.AddNamespace("图形", TranslatorConstants.XMLNS_UOFGRAPHICS);
            nmgr.AddNamespace("规则", TranslatorConstants.XMLNS_UOFRULES);
            //// Select and display all book titles.
            //XmlNodeList nodeList;
            XmlElement rootOutput = doc.DocumentElement;

            //2010-12-15 罗文甜,增加段落式样的标识符替换
            XmlNodeList paraStyleList = rootOutput.SelectNodes("//式样:段落式样_9912|//式样:段落式样_9905", nmgr);
            string      currentParaID = "";
            string      tempParaID    = "";
            int         inum          = 1;
            foreach (XmlNode paraStyle in paraStyleList)
            {
                currentParaID = paraStyle.Attributes.GetNamedItem("标识符_4100").Value;
                if (inum < 10)
                {
                    // tempParaID = "tyleAttrId" + "0000" + inum;
                    tempParaID = "tyleAttrId" + "0000" + inum;
                }
                else if (inum < 100)
                {
                    tempParaID = "tyleAttrId" + "000" + inum;
                }
                else if (inum < 1000)
                {
                    tempParaID = "tyleAttrId" + "00" + inum;
                }
                else if (inum < 10000)
                {
                    tempParaID = "tyleAttrId" + "0" + inum;
                }
                else if (inum < 100000)
                {
                    tempParaID = "tyleAttrId" + inum;
                }
                else
                {
                    throw new Exception("Too many paragraphs id");
                }
                paraStyle.Attributes.GetNamedItem("标识符_4100").Value = tempParaID;
                foreach (XmlNode paraStyleTwo in paraStyleList)
                {
                    if (((XmlElement)paraStyleTwo).HasAttribute("基式样引用_4104"))
                    {
                        if (paraStyleTwo.Attributes.GetNamedItem("基式样引用_4104").Value == currentParaID)
                        {
                            paraStyleTwo.Attributes.GetNamedItem("基式样引用_4104").Value = tempParaID;
                        }
                    }
                }

                XmlNodeList paraAttrs = rootOutput.SelectNodes("//字:段落属性_419B", nmgr);
                foreach (XmlNode paraAttr in paraAttrs)
                {
                    if (((XmlElement)paraAttr).HasAttribute("式样引用_419C") && paraAttr.Attributes.GetNamedItem("式样引用_419C").Value == currentParaID)
                    {
                        paraAttr.Attributes.GetNamedItem("式样引用_419C").Value = tempParaID;
                    }
                }

                inum++;
            }

            XmlNodeList animiationSequenceList = doc.SelectNodes("//演:序列_6B1B", nmgr);
            //2010-12-08 罗文甜:增加连接线始端和终端的图形引用
            XmlNodeList curveShapList = doc.SelectNodes("//图:连接线规则_8027", nmgr);

            XmlNodeList anchorNodeList;
            anchorNodeList = rootOutput.SelectNodes("//uof:锚点_C644", nmgr);

            //当前的GraphicsID
            string currentGraphicsID = "";
            //替换掉的GraphicsID
            //OBJ00003
            string tempGraphicsID = "";
            //tempGraphicsID = "OBJ";
            //对当前处理的图像编号计数
            int i = 1;

            foreach (XmlNode anchorNode in anchorNodeList)
            {
                //Console.WriteLine(anchorNode.Name);
                //存储当前GraphicsID,并替换掉
                currentGraphicsID = anchorNode.Attributes.GetNamedItem("图形引用_C62E").Value;
                //Console.WriteLine(currentGraphicsID + "\r\n");

                if (i < 10)
                {
                    tempGraphicsID = "Obj" + "000" + i;
                }
                else if (i < 100)
                {
                    tempGraphicsID = "Obj" + "00" + i;
                }
                else if (i < 1000)
                {
                    tempGraphicsID = "Obj" + "0" + i;
                }
                else if (i < 10000)
                {
                    tempGraphicsID = "Obj" + i;
                }
                else
                {
                    throw new Exception("Too many Graphics id");
                }


                anchorNode.Attributes.GetNamedItem("图形引用_C62E").Value = tempGraphicsID;
                //Console.WriteLine(tempGraphicsID);


                XmlNodeList graphicsNodeList;
                //XmlElement root = doc.DocumentElement;
                graphicsNodeList = rootOutput.SelectNodes("//图:图形_8062", nmgr);


                foreach (XmlNode graphicsNode in graphicsNodeList)
                {
                    if (graphicsNode.Attributes.GetNamedItem("标识符_804B").Value == currentGraphicsID)
                    {
                        //Console.WriteLine(graphicsNode.Name);
                        //Console.WriteLine(graphicsNode.Attributes.GetNamedItem("图:标识符").Value + "\r\n");
                        graphicsNode.Attributes.GetNamedItem("标识符_804B").Value = tempGraphicsID;
                        //Console.WriteLine(currentGraphicsID);
                        //Console.WriteLine();

                        // 动画引用
                        foreach (XmlNode animiationSequence in animiationSequenceList)
                        {
                            if (animiationSequence.Attributes.GetNamedItem("对象引用_6C28").Value == currentGraphicsID)
                            {
                                animiationSequence.Attributes.GetNamedItem("对象引用_6C28").Value = tempGraphicsID;
                            }
                            //2010-11-15 罗文甜:增加触发器的图形引用
                            XmlNode    tgtObject    = animiationSequence.SelectSingleNode("演:定时_6B2E", nmgr);
                            XmlElement tgtObjectEle = (XmlElement)tgtObject;

                            if (tgtObjectEle.HasAttribute("触发对象引用_6B34"))
                            {
                                if (tgtObjectEle.Attributes.GetNamedItem("触发对象引用_6B34").Value == currentGraphicsID)
                                {
                                    tgtObjectEle.Attributes.GetNamedItem("触发对象引用_6B34").Value = tempGraphicsID;
                                }
                            }
                        }
                        //2010-12-08 罗文甜:增加连接线始端和终端的图形引用
                        foreach (XmlNode curveShap in curveShapList)
                        {
                            if (curveShap.Attributes.GetNamedItem("连接线引用_8028").Value == currentGraphicsID)
                            {
                                curveShap.Attributes.GetNamedItem("连接线引用_8028").Value = tempGraphicsID;
                            }
                            if (((XmlElement)curveShap).HasAttribute("始端对象引用_8029") && curveShap.Attributes.GetNamedItem("始端对象引用_8029").Value == currentGraphicsID)
                            {
                                curveShap.Attributes.GetNamedItem("始端对象引用_8029").Value = tempGraphicsID;
                            }
                            if (((XmlElement)curveShap).HasAttribute("终端对象引用_802A") && curveShap.Attributes.GetNamedItem("终端对象引用_802A").Value == currentGraphicsID)
                            {
                                curveShap.Attributes.GetNamedItem("终端对象引用_802A").Value = tempGraphicsID;
                            }
                        }
                    }


                    //Console.WriteLine();
                }

                i++;
                //Console.WriteLine(nodeList1.Count);
            }


            XmlNodeList groupShapes = doc.SelectNodes("//pzip:archive//图形:图形集_7C00/图:图形_8062[@组合列表_8064]", nmgr);
            XmlNodeList shapes      = doc.SelectNodes("//pzip:archive//图形:图形集_7C00/图:图形_8062", nmgr);
            foreach (XmlNode shape in shapes)
            {
                currentGraphicsID = shape.Attributes.GetNamedItem("标识符_804B").Value;

                // only change group shapes
                if (!currentGraphicsID.Contains("Obj"))
                {
                    if (i < 10)
                    {
                        tempGraphicsID = "Obj" + "000" + i;
                    }
                    else if (i < 100)
                    {
                        tempGraphicsID = "Obj" + "00" + i;
                    }
                    else if (i < 1000)
                    {
                        tempGraphicsID = "Obj" + "0" + i;
                    }
                    else if (i < 10000)
                    {
                        tempGraphicsID = "Obj" + i;
                    }
                    else
                    {
                        throw new Exception("Too many Graphics id");
                    }

                    shape.Attributes.GetNamedItem("标识符_804B").Value = tempGraphicsID;

                    string newGroupIDString = string.Empty;

                    foreach (XmlNode groupShape in groupShapes)
                    {
                        string   groupID    = groupShape.Attributes.GetNamedItem("组合列表_8064").Value;
                        string[] graphicIDs = groupID.Split(new char[1] {
                            ' '
                        });

                        for (int j = 0; j < graphicIDs.Length; j++)
                        {
                            if (graphicIDs[j] == currentGraphicsID)
                            {
                                graphicIDs[j] = tempGraphicsID;
                            }
                        }

                        for (int k = 0; k < graphicIDs.Length; k++)
                        {
                            newGroupIDString += graphicIDs[k] + " ";
                        }
                        groupShape.Attributes.GetNamedItem("组合列表_8064").Value = newGroupIDString.Substring(0, newGroupIDString.Length - 1);
                        newGroupIDString = string.Empty;

                        /*
                         * if (groupID.Contains(currentGraphicsID))
                         * {
                         *  groupShape.Attributes.GetNamedItem("图:组合列表").Value = groupID.Replace(currentGraphicsID, tempGraphicsID);
                         * }
                         *
                         */
                    }

                    i++;
                }
            }



            int lastID = 0;

            XmlNodeList slideLayouts    = doc.SelectNodes("/pzip:archive/pzip:entry[@pzip:target='rules.xml']/规则:公用处理规则_B665/规则:演示文稿_B66D/规则:页面版式集_B651/规则:页面版式_B652", nmgr);
            XmlNodeList refSlideLayouts = doc.SelectNodes("/pzip:archive/pzip:entry[@pzip:target='content.xml']/演:演示文稿文档_6C10/演:幻灯片集_6C0E/演:幻灯片_6C0F", nmgr);
            //  XmlNodeList refSlideLayouts = doc.SelectNodes("uof:UOF/uof:演示文稿//@演:页面版式引用", nmgr);
            lastID = AddjustID(doc, slideLayouts, refSlideLayouts, "标识符_6B0D", "页面版式引用_6B27", "ID", 1);


            //<!--注销这部分内容李娟 2012 03,26·····································-->
            //String uofns = nmgr.LookupNamespace("uof");
            //XmlNode docroot = doc.SelectSingleNode("uof:UOF", nmgr);
            //XmlNode kzq = docroot.SelectSingleNode("/uof:UOF/uof:扩展区",nmgr);

            //if (kzq == null)
            //{
            //    kzq = doc.CreateElement("uof:扩展区",uofns);
            //    docroot.AppendChild(kzq);
            //}
            //XmlElement kz = doc.CreateElement("uof:扩展", uofns);
            //kz.SetAttribute("locID", "http://schemas.uof.org/cn/2003/uof", "u0051");

            //2010-11-19罗文甜:增加软件名称和软件版本
            //XmlElement rjmc = doc.CreateElement("uof:软件名称", uofns);
            //rjmc.SetAttribute("locID", "http://schemas.uof.org/cn/2003/uof", "u0052");
            //rjmc.InnerText = "EIOffice";
            //XmlElement rjbb = doc.CreateElement("uof:软件版本", uofns);
            //rjbb.SetAttribute("locID", "http://schemas.uof.org/cn/2003/uof", "u0053");
            //rjbb.InnerText = "v1.33";
            //XmlElement kznr = doc.CreateElement("uof:扩展内容", uofns);
            //kznr.SetAttribute("locID", "http://schemas.uof.org/cn/2003/uof", "u0054");

            //XmlElement path = doc.CreateElement("uof:路径", uofns);
            //XmlElement nr = doc.CreateElement("uof:内容", uofns);
            //path.SetAttribute("locID", "http://schemas.uof.org/cn/2003/uof", "u0065");
            //nr.SetAttribute("locID", "http://schemas.uof.org/cn/2003/uof", "u0056");
            //path.InnerText = "演示文稿";
            XmlNodeList masters = doc.SelectNodes("//演:母版_6C0D", nmgr);
            foreach (XmlNode master in masters)
            {
                XmlNodeList list = master.SelectNodes("uof:锚点_C644[uof:占位符_C626/@类型_C627='date' or uof:占位符_C626/@类型_C627='number' or uof:占位符_C626/@类型_C627='header' or uof:占位符_C626/@类型_C627='footer']", nmgr);
                foreach (XmlNode node in list)
                {
                    XmlElement jsx    = doc.CreateElement("uof:句属性", TranslatorConstants.XMLNS_UOF);
                    XmlElement ymyjlx = doc.CreateElement("uof:页眉页脚类型", TranslatorConstants.XMLNS_UOF);
                    XmlNode    para   = doc.SelectSingleNode("//图:图形_8062[@标识符_804B='" + node.Attributes["图形引用_C62E"].Value + "']/图:文本_803C/图:内容_8043/字:段落_416B", nmgr);
                    String     type   = string.Empty;
                    if (para != null)
                    {
                        String  refid     = para.Attributes["标识符_4169"].Value;
                        XmlNode childNode = node.SelectSingleNode("uof:占位符_C626", nmgr);
                        switch (childNode.Attributes["类型_C627"].Value)
                        {
                        case "date":
                            type = "datetime";
                            break;

                        case "number":
                            type = "slidenumber";
                            break;

                        case "header":
                            type = "header";
                            break;

                        case "footer":
                            type = "footer";
                            break;
                        }
                    }
                    //注销这块 李娟 2012.03.26····················································
                    //jsx.SetAttribute("locID", uofns, "w0027");
                    //jsx.SetAttribute("attrList", uofns, "引用 序号");
                    //String num;
                    //if (para.Attributes["序号"] == null)
                    //    num = "1";
                    //else
                    //    num = para.Attributes["序号"].Value;
                    //jsx.SetAttribute("序号", uofns, num);
                    //jsx.SetAttribute("引用", uofns, refid);
                    //ymyjlx.SetAttribute("locID", uofns, "w0031");
                    //ymyjlx.SetAttribute("attrList", uofns, "类型");
                    //ymyjlx.SetAttribute("类型", uofns, type);
                    //jsx.AppendChild(ymyjlx);
                    //nr.AppendChild(jsx);
                }
            }
            //注销这块 李娟2012.03.26
            //kznr.AppendChild(path);
            //kznr.AppendChild(nr);
            ////2010-11-19罗文甜
            //kz.AppendChild(rjmc);
            //kz.AppendChild(rjbb);

            //kz.AppendChild(kznr);
            //kzq.AppendChild(kz);
            //09.11.19 马有旭 添加↑
            //10.03.09 马有旭 添加 修改幻灯片段落ID 原:ID12E3C 改为:shp0graphc0
            //2010-11-24-罗文甜-修改
            XmlNodeList anchors = doc.SelectNodes("//pzip:archive/pzip:entry[@pzip:target='content.xml']/演:演示文稿文档_6C10/演:幻灯片集_6C0E/演:幻灯片_6C0F/uof:锚点_C644 | //pzip:archive/pzip:entry[@pzip:target='content.xml']/演:演示文稿文档_6C10/演:母版集_6C0C/演:母版_6C0D[@类型_6BEA='slide']/uof:锚点_C644[uof:占位符_C626/@类型_C627!='date' and uof:占位符_C626/@类型_C627!='footer' and uof:占位符_C626/@类型_C627!='number']", nmgr);
            //XmlNodeList anchors = doc.SelectNodes("/uof:UOF/uof:演示文稿/演:主体//uof:锚点", nmgr);
            int graphicCount = 0;
            int paraCount    = 0;
            foreach (XmlNode anchor in anchors)
            {
                XmlNode graphic = doc.SelectSingleNode("//pzip:archive/pzip:entry[@pzip:target='graphics.xml']/图形:图形集_7C00/图:图形_8062[@标识符_804B='" + anchor.Attributes["图形引用_C62E"].Value + "']", nmgr);
                if (graphic != null)
                {
                    ++graphicCount;
                    paraCount = 0;
                    String      newId      = "shp" + graphicCount + "graphc";
                    XmlNodeList paragraphs = graphic.SelectNodes("图:文本_803C/图:内容_8043/字:段落_416B", nmgr);
                    foreach (XmlNode para in paragraphs)
                    {
                        XmlAttribute attr = para.Attributes["标识符_4169"];
                        if (attr != null)
                        {
                            String oldId = attr.Value;
                            attr.Value = newId + paraCount;
                            XmlNodeList refs = doc.SelectNodes("//*[@段落引用_6C27='" + oldId + "']", nmgr);
                            foreach (XmlNode refNode in refs)
                            {
                                refNode.Attributes["段落引用_6C27"].Value = newId + paraCount;
                            }
                            ++paraCount;
                        }
                    }
                }
            }
            //注销这部分 李娟 ········································· 2012.03.36
            //删除@序号
            //XmlNodeList paraList = doc.SelectNodes("//字:段落[@序号]",nmgr);
            //foreach (XmlNode para in paraList)
            //{
            //    para.Attributes.Remove(para.Attributes["序号"]);
            //}
            try
            {
                string tmpAdjustID = Path.GetDirectoryName(inputFile) + Path.AltDirectorySeparatorChar + "tmpAdjustID.xml";
                tw = new XmlTextWriter(tmpAdjustID, Encoding.UTF8);
                doc.Save(tw);

                tw.Close();

                XPathDocument     xslDoc;
                XmlReaderSettings xrs              = new XmlReaderSettings();
                XmlReader         source           = null;
                XmlWriter         writer           = null;
                OoxZipResolver    zipResolver      = null;
                XmlUrlResolver    resourceResolver = null;
                try
                {
                    //xrs.ProhibitDtd = true;

                    resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                            this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + "Powerpoint.oox2uof");

                    xslDoc          = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream("post-processing.xslt"));
                    xrs.XmlResolver = resourceResolver;
                    source          = XmlReader.Create(tmpAdjustID);

                    XslCompiledTransform xslt     = new XslCompiledTransform();
                    XsltSettings         settings = new XsltSettings(true, false);
                    xslt.Load(xslDoc, settings, resourceResolver);

                    //if (!originalFile.Equals(string.Empty))
                    //{
                    //    zipResolver = new OoxZipResolver(originalFile, resourceResolver);
                    //}
                    XsltArgumentList parameters = new XsltArgumentList();
                    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);

                    // zip format
                    parameters.AddParam("outputFile", "", outputFile);
                    // writer = new OoxZipWriter(inputFile);
                    writer = new UofZipWriter(outputFile);

                    if (zipResolver != null)
                    {
                        xslt.Transform(source, parameters, writer, zipResolver);
                    }
                    else
                    {
                        xslt.Transform(source, parameters, writer);
                    }
                }
                finally
                {
                    if (writer != null)
                    {
                        writer.Close();
                    }
                    if (source != null)
                    {
                        source.Close();
                    }
                }
            }
            catch
            {
                throw new Exception("Fail in ajust ids");
            }
            finally
            {
                if (tw != null)
                {
                    tw.Close();
                }
            }

            #endregion

            return(result);
        }
Пример #5
0
        protected override void DoOoxToUofMainTransform(string originalFile, string inputFile, string outputFile, string resourceDir)
        {
            XmlUrlResolver resourceResolver = null;
            string         picture_xml      = "word\\media";
            string         wordPrePath      = Path.GetDirectoryName(inputFile) + "\\"; //输出文档路径
            string         mediaPath        = wordPrePath + picture_xml;
            string         tmpPic           = wordPrePath + "tmpPic.xml";              //增加对图片的处理
            XmlDocument    xmlDoc           = new XmlDocument();

            try
            {
                // chart转换成图片
                string charts_xml = wordPrePath + "word\\charts";
                if (Directory.Exists(charts_xml))
                {
                    string[] charts = Directory.GetFiles(charts_xml, "chart*");
                    if (charts.Length > 0)
                    {
                        if (!Directory.Exists(mediaPath))
                        {
                            Directory.CreateDirectory(mediaPath);
                        }
                    }
                    try
                    {
                        foreach (string chartXMLFile in charts)
                        {
                            SaveChartAsPic(chartXMLFile, mediaPath + Path.AltDirectorySeparatorChar + Path.GetFileName(chartXMLFile) + ".jpg", System.Windows.Forms.DataVisualization.Charting.ChartImageFormat.Jpeg);
                        }
                    }
                    catch (Exception ex)
                    {
                        logger.Warn("Save chart occured an error!" + ex.Message);
                    }
                }

                if (Directory.Exists(mediaPath))
                {
                    xmlDoc.Load(inputFile);
                    XmlNamespaceManager nms = new XmlNamespaceManager(xmlDoc.NameTable);

                    nms.AddNamespace("w", TranslatorConstants.XMLNS_W);
                    xmlDoc = PicPretreatment(xmlDoc, "w:document", mediaPath, nms);
                    xmlDoc.Save(tmpPic);
                    inputFile = tmpPic;
                }

                resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
                                                        this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + TranslatorConstants.OOXToUOF_WORD_LOCATION);//resources.word.oox2uof

                MainTransform(TranslatorConstants.OOXToUOF_XSL, resourceResolver, originalFile, inputFile, outputFile);
            }
            catch (Exception ex)
            {
                logger.Warn(ex.Message);
            }

            //XmlUrlResolver resourceResolver = null;
            //XPathDocument xslDoc = null;
            //XmlReaderSettings xrs = new XmlReaderSettings();
            //XmlReader source = null;
            //XmlWriter writer = null;
            //OoxZipResolver zipResolver = null;

            //try
            //{
            //    xrs.ProhibitDtd = true;//禁用DTD

            //    string xslLocation = TranslatorConstants.OOXToUOF_XSL;//oox2uof.xsl
            //    if (outputFile == null)
            //    {
            //        xslLocation = TranslatorConstants.OOXToUOF_COMPUTE_SIZE_XSL;//oox2uof-compute-size.xsl
            //    }
            //    if (resourceDir == null)//程序中resourceDir为null
            //    {
            //        //Assembly获得当前程序集。this.GetType().Namespace是指UofTranslatorLib。"."代表"/"
            //        resourceResolver = new ResourceResolver(Assembly.GetExecutingAssembly(),
            //            this.GetType().Namespace + "." + TranslatorConstants.RESOURCE_LOCATION + "." + TranslatorConstants.OOXToUOF_WORD_LOCATION);//resources.word.oox2uof
            //        xslDoc = new XPathDocument(((ResourceResolver)resourceResolver).GetInnerStream(xslLocation));//从程序集中加载指定的请单资源,oox2uof.xsl

            //        source = XmlReader.Create(inputFile);//预处理的中间文档
            //    }
            //    else
            //    {
            //        resourceResolver = new XmlUrlResolver();
            //        xslDoc = new XPathDocument(resourceDir + "/" + xslLocation);
            //        source = XmlReader.Create(resourceDir + "/" + TranslatorConstants.SOURCE_XML, xrs);//source.xml
            //    }
            //    XslCompiledTransform xslt = new XslCompiledTransform();
            //    XsltSettings settings = new XsltSettings(true, false);//XsltSettings指定执行 XSLT 样式表时要支持的 XSLT 功能
            //    xslt.Load(xslDoc, settings, resourceResolver);//oox2uof.xsl,settings,程序集中的位置
            //    zipResolver = new OoxZipResolver(originalFile, resourceResolver);//把源程序解压
            //    XsltArgumentList parameters = new XsltArgumentList();//包含数目可变的参数(这些参数是 XSLT 参数,或者是扩展对象)。
            //    parameters.XsltMessageEncountered += new XsltMessageEncounteredEventHandler(MessageCallBack);


            //    if (outputFile != null)
            //    {
            //        parameters.AddParam("outputFile", "", outputFile);
            //      //  writer = new OoxZipWriter(inputFile);
            //    //  writer = new UofWriter(zipResolver, outputFile);
            //      writer = new UofZipWriter();

            //     mainOutput = outputFile;

            //    }
            //    else
            //    {
            //        writer = XmlWriter.Create(Path.GetDirectoryName(inputFile) + "\\" + "temp.uof");
            //    }
            //  //  xslt.Transform(source, parameters, writer);
            //    xslt.Transform(source, parameters, writer, zipResolver);//读预处理的中间文档,参数,写到输出文件,zip
            //}
            //finally
            //{
            //    if (writer != null)
            //        writer.Close();
            //    if (source != null)
            //        source.Close();
            //    if (zipResolver != null)
            //        zipResolver.Dispose();
            //}
        }