public static void View(string zipFileName) { ZipReader reader = new ZipReader(zipFileName); Console.WriteLine("Archive: {0} ({1} files)", zipFileName, reader.Entries.Count); Console.WriteLine(reader.Comment); string format = "{0,8} {1,8} {2,5} {3,10} {4,5} {5}"; Console.WriteLine(format, " Length ", " Size ", "Ratio", " Date ", "Time ", "Name"); Console.WriteLine(format, "--------", "--------", "-----", "----------", "-----", "----"); foreach (ZipEntry entry in reader.Entries) { if (!entry.IsDirectory) { Console.WriteLine(format, entry.Length, entry.CompressedLength, entry.Ratio.ToString("P0"), entry.ModifiedTime.ToString("yyyy-MM-dd"), entry.ModifiedTime.ToString("hh:mm"), entry.Name); } } reader.Close(); }
protected void Dispose(bool disposing) { if (disposing) { if (archive != null) { archive.Close(); } } }
protected void Dispose(bool disposing) { if (disposing) { // Dispose managed resources if (archive != null) { archive.Close(); } } }
public static void Extract(string zipFileName) { ZipReader reader = new ZipReader(zipFileName); Console.WriteLine("Archive: {0}", zipFileName); Console.WriteLine(reader.Comment); // buffer to hold temp bytes byte[] buffer = new byte[4096]; int byteCount; // Get the zipped entries while (reader.MoveNext()) { ZipEntry entry = reader.Current; if (entry.IsDirectory) { Directory.CreateDirectory(entry.Name); } else { Console.Write(" {0}", entry.Name); // create output stream FileStream writer = File.Open(entry.Name, FileMode.Create); // write uncompressed data while ((byteCount = reader.Read(buffer, 0, buffer.Length)) > 0) { Console.Write("."); writer.Write(buffer, 0, byteCount); } writer.Close(); Console.WriteLine(); } } reader.Close(); }
public override bool transform() { //string Document_xml = "word/document.xml";//word下的doucument.xml文档 string picture_xml = "word\\media"; // string tmpFile = Path.GetTempPath() + "tmpDoc.xml"; // string tmpFile2 = Path.GetTempPath() + "sndtmpDoc.xml"; // Guid gPath = Guid.NewGuid(); // string wordPrePath = Path.GetTempPath() + gPath.ToString() + "\\"; // if (!Directory.Exists(wordPrePath)) // Directory.CreateDirectory(wordPrePath); string wordPrePath = Path.GetDirectoryName(outputFile) + "\\";//输出文档路径 string mediaPath = wordPrePath + picture_xml; string tblVtcl = wordPrePath + "tblVertical.xml"; string tmpFile = wordPrePath + "tmpDoc.xml"; string tmpFile2 = wordPrePath + "sndtmpDoc.xml"; //预处理中的中间文档 string tmpFile3 = wordPrePath + "thrtmpDoc.xml"; //预处理中的中间文档 string preOutputFileName = wordPrePath + "tempdoc.xml"; //预处理出来的中间文档 XmlReader source = null; XmlWriter writer = null; ZipReader archive = ZipFactory.OpenArchive(inputFile); archive.ExtractOfficeDocument(inputFile, wordPrePath); //archive.ExtractUOFDocument(inputFile, wordPrePath); bool isSuccess = true; try { OoxToUofTableProcessing tableProcessing2 = new OoxToUofTableProcessing(wordPrePath + "word" + Path.AltDirectorySeparatorChar + "document.xml"); tableProcessing2.Processing(tblVtcl); //找到预处理第一步的式样单pretreatmentStep1.xsl XPathDocument xpdoc = UOFTranslator.GetXPathDoc(TranslatorConstants.OOXToUOF_PRETREAT_STEP1_XSL, TranslatorConstants.OOXToUOF_WORD_LOCATION); XslCompiledTransform xslt = new XslCompiledTransform(); xslt.Load(xpdoc); // source = XmlReader.Create(archive.GetEntry(Document_xml));//解压,得到document.xml文档 source = XmlReader.Create(tblVtcl); writer = new XmlTextWriter(tmpFile, Encoding.UTF8); //tmpDoc.xml xslt.Transform(source, writer); //document.xml--经过预处理.xsl--tmpDoc.xml if (writer != null) { writer.Close(); } if (source != null) { source.Close(); } //第二步预处理 xpdoc = UOFTranslator.GetXPathDoc(TranslatorConstants.OOXToUOF_PRETREAT_STEP2_XSL, TranslatorConstants.OOXToUOF_WORD_LOCATION); xslt = new XslCompiledTransform(); xslt.Load(xpdoc); writer = new XmlTextWriter(tmpFile2, Encoding.UTF8); //sndtemDoc.xml xslt.Transform(tmpFile, writer); //tmpDoc--经过预处理2.xsl--sndtemDoc.xml if (writer != null) { writer.Close(); } //第三步预处理 xpdoc = UOFTranslator.GetXPathDoc(TranslatorConstants.OOXToUOF_PRETREAT_STEP3_XSL, TranslatorConstants.OOXToUOF_WORD_LOCATION); xslt = new XslCompiledTransform(); xslt.Load(xpdoc); // xslt.Transform(tmpFile2, outputFile); xslt.Transform(tmpFile2, tmpFile3);//经过预处理3--tempdoc.xml //2011/6/17zhaobj:阴影预处理 XmlNamespaceManager nms = null; XmlDocument xmlDoc; XmlTextWriter resultWriter = null; xmlDoc = new XmlDocument(); xmlDoc.Load(tmpFile3); nms = new XmlNamespaceManager(xmlDoc.NameTable); nms.AddNamespace("a", TranslatorConstants.XMLNS_A); nms.AddNamespace("w", TranslatorConstants.XMLNS_W); XmlNodeList shapeShadeList = xmlDoc.SelectNodes("//a:outerShdw", nms); if (shapeShadeList != null) { foreach (XmlNode shapeShade in shapeShadeList) { double dist, dir; if (((XmlElement)shapeShade).HasAttribute("dist")) { dist = Convert.ToDouble(shapeShade.Attributes.GetNamedItem("dist").Value) / 12700; } else { dist = 0.0; } if (((XmlElement)shapeShade).HasAttribute("dir")) { dir = (Convert.ToDouble(shapeShade.Attributes.GetNamedItem("dir").Value) * 3.1415) / (180 * 60000); } else { dir = 0.0; } double xValue = dist * Math.Cos(dir); double yValue = dist * Math.Sin(dir); XmlElement x = xmlDoc.CreateElement("x"); x.InnerText = Convert.ToString(xValue); shapeShade.AppendChild(x); XmlElement y = xmlDoc.CreateElement("y"); y.InnerText = Convert.ToString(yValue); shapeShade.AppendChild(y); } } resultWriter = new XmlTextWriter(preOutputFileName, System.Text.Encoding.UTF8); xmlDoc.Save(resultWriter); resultWriter.Close(); /* * * * */ OutputFilename = preOutputFileName; //图片预处理 //if (Directory.Exists(wordPrePath + picture_xml)) //{ // xmlDoc.Load(preOutputFileName); // DirectoryInfo mediaInfo = new DirectoryInfo(wordPrePath + picture_xml); // FileInfo[] medias = mediaInfo.GetFiles(); // XmlNode root = xmlDoc.SelectSingleNode("w:document", nms); // XmlElement mediaNode=xmlDoc.CreateElement("w","media",TranslatorConstants.XMLNS_W); // foreach (FileInfo media in medias) // { // XmlElement mediaFileNode = xmlDoc.CreateElement("u2opic", "picture", "urn:u2opic:xmlns:post-processings:special"); // mediaFileNode.SetAttribute("target", "urn:u2opic:xmlns:post-processings:special", media.FullName); // mediaNode.AppendChild(mediaFileNode); // } // root.AppendChild(mediaNode); // xmlDoc.Save(tmpPic); // OutputFilename = tmpPic; //} } catch (Exception e) { logger.Error("Fail in OoxToUofPreProcessorOneWord: " + e.Message); logger.Error(e.StackTrace); isSuccess = false; } finally { if (writer != null) { writer.Close(); } if (source != null) { source.Close(); } if (archive != null) { archive.Close(); } if (File.Exists(tmpFile2)) { File.Delete((tmpFile2)); } } return(isSuccess); }