Parcourir la source

Huge improvement to InsertDocument() efficienty. Using set operations to find the missing refs.

master
coffeycathal_cp il y a 13 ans
Parent
révision
1a76e6e44d
4 fichiers modifiés avec 11 ajouts et 11 suppressions
  1. 1
    1
      DocX/Container.cs
  2. 4
    4
      DocX/HelperFunctions.cs
  3. 4
    4
      DocX/Paragraph.cs
  4. 2
    2
      DocX/Properties/AssemblyInfo.cs

+ 1
- 1
DocX/Container.cs Voir le fichier

Uri style_package_uri = new Uri("/word/styles.xml", UriKind.Relative); Uri style_package_uri = new Uri("/word/styles.xml", UriKind.Relative);
if (!Document.package.PartExists(style_package_uri)) if (!Document.package.PartExists(style_package_uri))
{ {
PackagePart style_package = Document.package.CreatePart(style_package_uri, "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml");
PackagePart style_package = Document.package.CreatePart(style_package_uri, "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", CompressionOption.Maximum);
using (TextWriter tw = new StreamWriter(style_package.GetStream())) using (TextWriter tw = new StreamWriter(style_package.GetStream()))
{ {
style_document = new XDocument style_document = new XDocument

+ 4
- 4
DocX/HelperFunctions.cs Voir le fichier

{ {
internal static void CreateRelsPackagePart(DocX Document, Uri uri) internal static void CreateRelsPackagePart(DocX Document, Uri uri)
{ {
PackagePart pp = Document.package.CreatePart(uri, "application/vnd.openxmlformats-package.relationships+xml");
PackagePart pp = Document.package.CreatePart(uri, "application/vnd.openxmlformats-package.relationships+xml", CompressionOption.Maximum);
using (TextWriter tw = new StreamWriter(pp.GetStream())) using (TextWriter tw = new StreamWriter(pp.GetStream()))
{ {
XDocument d = new XDocument XDocument d = new XDocument
Uri settingsUri = new Uri("/word/settings.xml", UriKind.Relative); Uri settingsUri = new Uri("/word/settings.xml", UriKind.Relative);
if (!package.PartExists(settingsUri)) if (!package.PartExists(settingsUri))
{ {
settingsPart = package.CreatePart(settingsUri, "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml");
settingsPart = package.CreatePart(settingsUri, "application/vnd.openxmlformats-officedocument.wordprocessingml.settings+xml", CompressionOption.Maximum);
PackagePart mainDocumentPart = package.GetParts().Where PackagePart mainDocumentPart = package.GetParts().Where
( (
internal static void CreateCustomPropertiesPart(DocX document) internal static void CreateCustomPropertiesPart(DocX document)
{ {
PackagePart customPropertiesPart = document.package.CreatePart(new Uri("/docProps/custom.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.custom-properties+xml");
PackagePart customPropertiesPart = document.package.CreatePart(new Uri("/docProps/custom.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.custom-properties+xml", CompressionOption.Maximum);
XDocument customPropDoc = new XDocument XDocument customPropDoc = new XDocument
( (
{ {
XDocument stylesDoc; XDocument stylesDoc;
// Create the main document part for this package // Create the main document part for this package
PackagePart word_styles = package.CreatePart(new Uri("/word/styles.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml");
PackagePart word_styles = package.CreatePart(new Uri("/word/styles.xml", UriKind.Relative), "application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", CompressionOption.Maximum);
stylesDoc = HelperFunctions.DecompressXMLResource("Novacode.Resources.default_styles.xml.gz"); stylesDoc = HelperFunctions.DecompressXMLResource("Novacode.Resources.default_styles.xml.gz");
XElement lang = stylesDoc.Root.Element(XName.Get("docDefaults", DocX.w.NamespaceName)).Element(XName.Get("rPrDefault", DocX.w.NamespaceName)).Element(XName.Get("rPr", DocX.w.NamespaceName)).Element(XName.Get("lang", DocX.w.NamespaceName)); XElement lang = stylesDoc.Root.Element(XName.Get("docDefaults", DocX.w.NamespaceName)).Element(XName.Get("rPrDefault", DocX.w.NamespaceName)).Element(XName.Get("rPr", DocX.w.NamespaceName)).Element(XName.Get("lang", DocX.w.NamespaceName));

+ 4
- 4
DocX/Paragraph.cs Voir le fichier

this.startIndex = startIndex; this.startIndex = startIndex;
this.endIndex = startIndex + GetElementTextLength(xml); this.endIndex = startIndex + GetElementTextLength(xml);
RebuildDocProperties();
RebuildDocProperties();
#region It's possible that a Paragraph may have pStyle references #region It's possible that a Paragraph may have pStyle references
// Check if this Paragraph references any pStyle elements. // Check if this Paragraph references any pStyle elements.
{ {
Uri style_package_uri = new Uri("/word/styles.xml", UriKind.Relative); Uri style_package_uri = new Uri("/word/styles.xml", UriKind.Relative);
PackagePart styles_document = document.package.GetPart(style_package_uri); PackagePart styles_document = document.package.GetPart(style_package_uri);
using (TextReader tr = new StreamReader(styles_document.GetStream())) using (TextReader tr = new StreamReader(styles_document.GetStream()))
{ {
XDocument style_document = XDocument.Load(tr); XDocument style_document = XDocument.Load(tr);
XElement styles_element = style_document.Element(XName.Get("styles", DocX.w.NamespaceName)); XElement styles_element = style_document.Element(XName.Get("styles", DocX.w.NamespaceName));
var styles_element_ids = stylesElements.Select(e => e.Attribute(XName.Get("val", DocX.w.NamespaceName)).Value); var styles_element_ids = stylesElements.Select(e => e.Attribute(XName.Get("val", DocX.w.NamespaceName)).Value);
//foreach(string id in styles_element_ids) //foreach(string id in styles_element_ids)
//{ //{
// var style = // var style =
// styles.Add(style); // styles.Add(style);
//} //}
} }
}
}
#endregion #endregion
this.runs = Xml.Elements(XName.Get("r", DocX.w.NamespaceName)).ToList(); this.runs = Xml.Elements(XName.Get("r", DocX.w.NamespaceName)).ToList();

+ 2
- 2
DocX/Properties/AssemblyInfo.cs Voir le fichier

// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.1.12")]
[assembly: AssemblyFileVersion("1.0.1.12")]
[assembly: AssemblyVersion("1.0.1.13")]
[assembly: AssemblyFileVersion("1.0.1.13")]

Chargement…
Annuler
Enregistrer