소스 검색

Added a patch provided by ArtFeel. By default the document language use to be English (Ireland). DocX now uses CurrentCulture to infer the correct language. You can know also specify a specific language.

Thank you for this patch ArtFeel. Also thanks to MadBoy for reminding me about it, without you this might have been lost in the discussions section of codeplex. Sorry about the delay Madboy.
master
coffeycathal_cp 14 년 전
부모
커밋
c9469689b6
2개의 변경된 파일78개의 추가작업 그리고 0개의 파일을 삭제
  1. 25
    0
      DocX/Formatting.cs
  2. 53
    0
      DocX/Paragraph.cs

+ 25
- 0
DocX/Formatting.cs 파일 보기

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.Drawing;
using System.Globalization;
namespace Novacode
{
/// <summary>
@@ -30,6 +31,8 @@ namespace Novacode
private int? position;
private double? spacing;
private CultureInfo language;
/// <summary>
/// A text formatting.
/// </summary>
@@ -42,15 +45,37 @@ namespace Novacode
underlineStyle = UnderlineStyle.none;
misc = Misc.none;
// Use current culture by default
language = CultureInfo.CurrentCulture;
rPr = new XElement(XName.Get("rPr", DocX.w.NamespaceName));
}
/// <summary>
/// Text language
/// </summary>
public CultureInfo Language
{
get
{
return language;
}
set
{
language = value;
}
}
internal XElement Xml
{
get
{
rPr = new XElement(XName.Get("rPr", DocX.w.NamespaceName));
if (language != null)
rPr.Add(new XElement(XName.Get("lang", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), language.Name)));
if(spacing.HasValue)
rPr.Add(new XElement(XName.Get("spacing", DocX.w.NamespaceName), new XAttribute(XName.Get("val", DocX.w.NamespaceName), spacing.Value * 20)));

+ 53
- 0
DocX/Paragraph.cs 파일 보기

@@ -9,6 +9,7 @@ using System.Collections;
using System.IO.Packaging;
using System.IO;
using System.Drawing;
using System.Globalization;
namespace Novacode
{
@@ -1851,6 +1852,58 @@ namespace Novacode
HelperFunctions.RenumberIDs(Document);
}
/// <summary>
/// For use with Append() and AppendLine()
/// </summary>
/// <returns>This Paragraph in curent culture</returns>
/// <example>
/// Add a new Paragraph with russian text to this document and then set language of text to local culture.
/// <code>
/// // Load a document.
/// using (DocX document = DocX.Create(@"Test.docx"))
/// {
/// // Insert a new Paragraph with russian text and set curent local culture to it.
/// Paragraph p = document.InsertParagraph("Привет мир!").CurentCulture();
///
/// // Save this document.
/// document.Save();
/// }
/// </code>
/// </example>
public Paragraph CurentCulture()
{
ApplyTextFormattingProperty(XName.Get("lang", DocX.w.NamespaceName),
string.Empty,
new XAttribute(XName.Get("val", DocX.w.NamespaceName), CultureInfo.CurrentCulture.Name));
return this;
}
/// <summary>
/// For use with Append() and AppendLine()
/// </summary>
/// <param name="culture">The CultureInfo for text</param>
/// <returns>This Paragraph in curent culture</returns>
/// <example>
/// Add a new Paragraph with russian text to this document and then set language of text to local culture.
/// <code>
/// // Load a document.
/// using (DocX document = DocX.Create(@"Test.docx"))
/// {
/// // Insert a new Paragraph with russian text and set specific culture to it.
/// Paragraph p = document.InsertParagraph("Привет мир").Culture(CultureInfo.CreateSpecificCulture("ru-RU"));
///
/// // Save this document.
/// document.Save();
/// }
/// </code>
/// </example>
public Paragraph Culture(CultureInfo culture)
{
ApplyTextFormattingProperty(XName.Get("lang", DocX.w.NamespaceName), string.Empty,
new XAttribute(XName.Get("val", DocX.w.NamespaceName), culture.Name));
return this;
}
/// <summary>
/// Append text to this Paragraph.
/// </summary>

Loading…
취소
저장