public void Open(string fileName) { if (_zipOutputStream != null || _delegateWriter != null) { this.Close(); } _zipOutputStream = ZipFactory.CreateArchive(fileName); }
// TODO: throw an exception if "target" attribute not set public override void WriteString(string text) { Node elt = (Node)elements.Peek(); if (!elt.Ns.Equals(ZIP_POST_PROCESS_NAMESPACE) && !elt.Ns.Equals(PIC_POST_PROCESS_NAMESPACE) && !elt.Ns.Equals(OLE_POST_PROCESS_NAMESPACE)) { if (delegateWriter != null) { delegateWriter.WriteString(text); } } else { // Pick up the target attribute if (attributes.Count > 0) { Node attr = (Node)attributes.Peek(); if (attr.Ns.Equals(ZIP_POST_PROCESS_NAMESPACE) || attr.Ns.Equals(PIC_POST_PROCESS_NAMESPACE) || attr.Ns.Equals(OLE_POST_PROCESS_NAMESPACE)) { switch (elt.Name) { case ARCHIVE_ELEMENT: //archive // Prevent nested archive creation if (processingState == ProcessingState.None && attr.Name.Equals("target")) { logger.Info("creating archive : " + text); // 输出包的路径放在式样单中间文档元素<archive Target="包路径名">中了, // 从中提取即可,当然也可以直接传递过来 zipOutputStream = ZipFactory.CreateArchive(text); processingState = ProcessingState.EntryWaiting; } break; case PART_ELEMENT: //entry // Prevent nested entry creation if (processingState == ProcessingState.EntryWaiting && attr.Name.Equals("target")) { logger.Info("creating new part : " + text); //此处的text是entry的target属性的值,也就是文件的路径 zipOutputStream.AddEntry(text); delegateWriter = XmlWriter.Create(zipOutputStream, delegateSettings); processingState = ProcessingState.EntryStarted; delegateWriter.WriteStartDocument(); } break; case OLE_DRAW: case OLE_DRAWRELS: case OLE_EMBEDDING: //ole case PIC_ELEMENT: //picture if (processingState != ProcessingState.None) { if (attr.Name.Equals("target")) { binarySource += text; logger.Info("picture: target=" + binarySource); } } break; } } } } }
// TODO: throw an exception if "target" attribute not set public override void WriteString(string text) { Node elt = (Node)elements.Peek(); if (!elt.Ns.Equals(ZIP_POST_PROCESS_NAMESPACE)) { if (delegateWriter != null) { delegateWriter.WriteString(text); } } else { // Pick up the target attribute if (attributes.Count > 0) { Node attr = (Node)attributes.Peek(); if (attr.Ns.Equals(ZIP_POST_PROCESS_NAMESPACE)) { switch (elt.Name) { case ARCHIVE_ELEMENT: // Prevent nested archive creation if (processingState == ProcessingState.None && attr.Name.Equals("target")) { Debug.WriteLine("creating archive : " + text); // 输出包的路径放在式样单中间文档元素<archive Target="包路径名">中了, // 从中提取即可,当然也可以直接传递过来 zipOutputStream = ZipFactory.CreateArchive(text); processingState = ProcessingState.EntryWaiting; binaries = new Hashtable(); } break; case PART_ELEMENT: // Prevent nested entry creation if (processingState == ProcessingState.EntryWaiting && attr.Name.Equals("target")) { Debug.WriteLine("creating new part : " + text); //此处的text是entry的target属性的值,也就是文件的路径 zipOutputStream.AddEntry(text); delegateWriter = XmlWriter.Create(zipOutputStream, delegateSettings); processingState = ProcessingState.EntryStarted; delegateWriter.WriteStartDocument(); } break; case COPY_ELEMENT: if (processingState != ProcessingState.None) { if (attr.Name.Equals("source")) { // binarySource是存放base64数据的标识符值 // <uof:其他对象 uof:locID="u0036" // uof:attrList="标识符 内嵌 公共类型 私有类型" // uof:标识符="OBJ00002" uof:内嵌="false" uof:公共类型="png"> // 即OBJ00002,该标识符唯一确定一个其他对象,进而得到其中的base64数据 binarySource += text; Debug.WriteLine("copy source=" + binarySource); } if (attr.Name.Equals("target")) { // binaryTarget存放二进制图片在OOX包中的位置 binaryTarget += text; Debug.WriteLine("copy target=" + binaryTarget); } } break; } } } } }