GetStyleSource.cs
  1. //
  2. // This code is part of Document Solutions for Word demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System.IO;
  6. using GrapeCity.Documents.Word;
  7.  
  8. namespace DsWordWeb.Demos
  9. {
  10. // The actual formatting of a specific content object in an MS Word document
  11. // is determined by a combination of several factors, such as direct formatting
  12. // that may be applied to the object, the style associated with the object,
  13. // as well as direct formatting and styles of the containing objects.
  14. //
  15. // This sample demonstrates the use of the GcWordDocument.GetPropertyValueSource()
  16. // method that allows to find the object that provides the actual current value
  17. // of a style property (in this sample, the size of a font).
  18. //
  19. // This sample uses the document from the SampleParagraphs sample.
  20. public class GetStyleSource
  21. {
  22. public GcWordDocument CreateDocx()
  23. {
  24. GcWordDocument doc = new GcWordDocument();
  25. doc.Load(Path.Combine("Resources", "WordDocs", "SampleParagraphs.docx"));
  26.  
  27. // Find the object that provides formatting for the first text run in this document:
  28. object source = GcWordDocument.GetPropertyValueSource(() => doc.Body.Runs.First.Font.Size);
  29.  
  30. // Add the info that we found to the document:
  31. doc.Body.Paragraphs.Add($">>> The object that determines the font size of the first text run in this document is '{source}'.");
  32. // If the property source is a style, add its name:
  33. if (source is Style s)
  34. doc.Body.Paragraphs.Add($">>> The object is the style '{s.WordName}'.");
  35.  
  36. return doc;
  37. }
  38. }
  39. }
  40.