本文整理汇总了C#中System.IO.Packaging.Package.Close方法的典型用法代码示例。如果您正苦于以下问题:C# Package.Close方法的具体用法?C# Package.Close怎么用?C# Package.Close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.Packaging.Package
的用法示例。
在下文中一共展示了Package.Close方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateCodeBaseXML
public void CreateCodeBaseXML()
{
try
{
package = Package.Open(fileCodeBase);
XmlDocument sharedString = GetPartFile(OfficeFilePart.ShareString, 0);
sharedString.Save(Common.SHARED_STRING);
XmlDocument sheet = GetPartFile(OfficeFilePart.Sheet, 1);
XsltArgumentList xsltArgListSheet = new XsltArgumentList();
XsltSettings settings = new XsltSettings(true, true);
XslCompiledTransform xslTransSheet = new XslCompiledTransform();
xslTransSheet.Load(Common.XSLT_CODE_BASE, settings, new XmlUrlResolver());
xsltArgListSheet.AddParam("prmDocSharedStrings", "", sharedString.CreateNavigator());
string sOutXmlSheet = System.String.Empty;
using (FileStream fs = new FileStream(Common.XML_CODE_BASE, FileMode.Create))
{
xslTransSheet.Transform(sheet.CreateNavigator(), xsltArgListSheet, fs);
}
XslCompiledTransform xslRowSheet = new XslCompiledTransform();
xslRowSheet.Load(Common.XSLT_TO_ROW);
xslRowSheet.Transform(Common.XML_CODE_BASE, Common.XML_ROW);
}
finally
{
package.Close();
}
}
示例2: ReleasePackage
public static void ReleasePackage(Package package)
{
lock (m_Lock)
{
string key = null;
foreach (KeyValuePair<string, Package> pair in m_Packages)
{
if (pair.Value == package)
{
key = pair.Key;
break;
}
}
if (key != null)
{
package.Close();
m_Packages.Remove(key);
}
}
}
示例3: SaveDoc
protected XDocument SaveDoc(MemoryStream result, Package pkg, PackagePart part, XmlReader xmlReader, XDocument xmlMainXMLDoc, string templateBody)
{
xmlMainXMLDoc = XDocument.Parse(templateBody);
var partWrt = new StreamWriter(part.GetStream(FileMode.Open, FileAccess.ReadWrite));
xmlMainXMLDoc.Save(partWrt);
partWrt.Flush();
partWrt.Close();
pkg.Close();
result.Position = 0;
xmlReader.Close();
return xmlMainXMLDoc;
}
示例4: SignAllParts
private void SignAllParts(Package package, X509Certificate2 certificate)
{
var partsToSign = new List<Uri>();
var relationshipsToSign = new List<PackageRelationshipSelector>();
foreach (var relationship in package.GetRelationshipsByType(RtOfficeDocument))
{
AddSignableItems(relationship, partsToSign, relationshipsToSign);
}
var mgr = new PackageDigitalSignatureManager(package)
{
CertificateOption = CertificateEmbeddingOption.InSignaturePart
};
var officeObject = CreateOfficeObject(SignatureID, ManifestHashAlgorithm);
var officeObjectReference = new Reference("#" + OfficeObjectID);
mgr.Sign(partsToSign,
certificate,
relationshipsToSign,
SignatureID,
new[] { officeObject },
new[] { officeObjectReference });
package.Close();
}
示例5: PostCreation
internal static void PostCreation(Package package, DocumentTypes documentType = DocumentTypes.Document)
{
XDocument mainDoc, stylesDoc, numberingDoc;
#region MainDocumentPart
// Create the main document part for this package
PackagePart mainDocumentPart;
if (documentType == DocumentTypes.Document)
{
mainDocumentPart = package.CreatePart(new Uri("/word/document.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml");
}
else
{
mainDocumentPart = package.CreatePart(new Uri("/word/document.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.template.main+xml");
}
package.CreateRelationship(mainDocumentPart.Uri, TargetMode.Internal, "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument");
// Load the document part into a XDocument object
using (TextReader tr = new StreamReader(mainDocumentPart.GetStream(FileMode.Create, FileAccess.ReadWrite)))
{
mainDoc = XDocument.Parse
(@"<?xml version=""1.0"" encoding=""UTF-8"" standalone=""yes""?>
<w:document xmlns:ve=""http://schemas.openxmlformats.org/markup-compatibility/2006"" xmlns:o=""urn:schemas-microsoft-com:office:office"" xmlns:r=""http://schemas.openxmlformats.org/officeDocument/2006/relationships"" xmlns:m=""http://schemas.openxmlformats.org/officeDocument/2006/math"" xmlns:v=""urn:schemas-microsoft-com:vml"" xmlns:wp=""http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing"" xmlns:w10=""urn:schemas-microsoft-com:office:word"" xmlns:w=""http://schemas.openxmlformats.org/wordprocessingml/2006/main"" xmlns:wne=""http://schemas.microsoft.com/office/word/2006/wordml"" xmlns:a=""http://schemas.openxmlformats.org/drawingml/2006/main"" xmlns:c=""http://schemas.openxmlformats.org/drawingml/2006/chart"">
<w:body>
<w:sectPr w:rsidR=""003E25F4"" w:rsidSect=""00FC3028"">
<w:pgSz w:w=""11906"" w:h=""16838""/>
<w:pgMar w:top=""1440"" w:right=""1440"" w:bottom=""1440"" w:left=""1440"" w:header=""708"" w:footer=""708"" w:gutter=""0""/>
<w:cols w:space=""708""/>
<w:docGrid w:linePitch=""360""/>
</w:sectPr>
</w:body>
</w:document>"
);
}
// Save the main document
using (TextWriter tw = new StreamWriter(mainDocumentPart.GetStream(FileMode.Create, FileAccess.Write)))
mainDoc.Save(tw, SaveOptions.None);
#endregion
#region StylePart
stylesDoc = HelperFunctions.AddDefaultStylesXml(package);
#endregion
#region NumberingPart
numberingDoc = HelperFunctions.AddDefaultNumberingXml(package);
#endregion
package.Close();
}
示例6: GetObjectIds
// Methods
public List<string> GetObjectIds()
{
try
{
package = Package.Open(fileCodeBase);
XmlDocument idObjects = GetPartFile(OfficeFilePart.Sheet, 1);
XmlNamespaceManager xnm = new XmlNamespaceManager(idObjects.NameTable);
xnm.AddNamespace("def", "http://schemas.openxmlformats.org/spreadsheetml/2006/main");
List<string> listString = new List<string>();
XmlNodeList elemList = idObjects.SelectNodes("//def:row/def:c[starts-with(@r, 'C')]/def:v", xnm);
for (int i = 2; i < elemList.Count; i++)
listString.Add(elemList[i].InnerXml);
return listString.Distinct().ToList();
}
finally
{
package.Close();
}
}