瀏覽代碼

Added Margin support in the form of

document.MarginTop
document.MarginBottom
document.MarginLeft
document.MarginRight
master
coffeycathal_cp 14 年之前
父節點
當前提交
d0196f43e6
共有 2 個檔案被更改,包括 95 行新增2 行删除
  1. 94
    2
      DocX/DocX.cs
  2. 1
    0
      DocX/PageLayout.cs

+ 94
- 2
DocX/DocX.cs 查看文件

@@ -32,6 +32,98 @@ namespace Novacode
static internal XNamespace c = "http://schemas.openxmlformats.org/drawingml/2006/chart";
#endregion
internal float getMarginAttribute(XName name)
{
XElement body = mainDoc.Root.Element(XName.Get("body", DocX.w.NamespaceName));
XElement sectPr = body.Element(XName.Get("sectPr", DocX.w.NamespaceName));
if (sectPr != null)
{
XElement pgMar = sectPr.Element(XName.Get("pgMar", DocX.w.NamespaceName));
if (pgMar != null)
{
XAttribute top = pgMar.Attribute(name);
if (top != null)
{
float f;
if (float.TryParse(top.Value, out f))
return (int)(f / 15.0f);
}
}
}
return 0;
}
internal void setMarginAttribute(XName xName, float value)
{
XElement body = mainDoc.Root.Element(XName.Get("body", DocX.w.NamespaceName));
XElement sectPr = body.Element(XName.Get("sectPr", DocX.w.NamespaceName));
if (sectPr != null)
{
XElement pgMar = sectPr.Element(XName.Get("pgMar", DocX.w.NamespaceName));
if (pgMar != null)
{
XAttribute top = pgMar.Attribute(xName);
if (top != null)
{
top.SetValue(value * 15);
}
}
}
}
public float MarginTop
{
get
{
return getMarginAttribute(XName.Get("top", DocX.w.NamespaceName));
}
set
{
setMarginAttribute(XName.Get("top", DocX.w.NamespaceName), value);
}
}
public float MarginBottom
{
get
{
return getMarginAttribute(XName.Get("bottom", DocX.w.NamespaceName));
}
set
{
setMarginAttribute(XName.Get("bottom", DocX.w.NamespaceName), value);
}
}
public float MarginLeft
{
get
{
return getMarginAttribute(XName.Get("left", DocX.w.NamespaceName));
}
set
{
setMarginAttribute(XName.Get("left", DocX.w.NamespaceName), value);
}
}
public float MarginRight
{
get
{
return getMarginAttribute(XName.Get("right", DocX.w.NamespaceName));
}
set
{
setMarginAttribute(XName.Get("right", DocX.w.NamespaceName), value);
}
}
public float PageWidth
{
get
@@ -71,7 +163,7 @@ namespace Novacode
if (pgSz != null)
{
pgSz.SetAttributeValue(XName.Get("w", DocX.w.NamespaceName), value);
pgSz.SetAttributeValue(XName.Get("w", DocX.w.NamespaceName), value * 15);
}
}
}
@@ -117,7 +209,7 @@ namespace Novacode
if (pgSz != null)
{
pgSz.SetAttributeValue(XName.Get("h", DocX.w.NamespaceName), value);
pgSz.SetAttributeValue(XName.Get("h", DocX.w.NamespaceName), value*15);
}
}
}

+ 1
- 0
DocX/PageLayout.cs 查看文件

@@ -13,6 +13,7 @@ namespace Novacode
}
public Orientation Orientation
{
get

Loading…
取消
儲存