浏览代码

Added: AutoFit fix by Roger Saele. Thank you for your contribution Roger.

master
coffeycathal_cp 13 年前
父节点
当前提交
19e393223f
共有 1 个文件被更改,包括 41 次插入6 次删除
  1. 41
    6
      DocX/Table.cs

+ 41
- 6
DocX/Table.cs 查看文件

@@ -282,41 +282,76 @@ namespace Novacode
/// <summary>
/// Auto size this table according to some rule.
/// </summary>
/// <remarks>Added by Roger Saele, April 2012. Thank you for your contribution Roger.</remarks>
public AutoFit AutoFit
{
get { return autofit; }
set
{
string attributeValue = string.Empty;
string tableAttributeValue = string.Empty;
string columnAttributeValue = string.Empty;
switch (value)
{
case AutoFit.ColumnWidth:
{
attributeValue = "dxa";
tableAttributeValue = "auto";
columnAttributeValue = "dxa";
// Disable "Automatically resize to fit contents" option
XElement tblPr = Xml.Element(XName.Get("tblPr", DocX.w.NamespaceName));
if (tblPr != null)
{
XElement layout = tblPr.Element(XName.Get("tblLayout", DocX.w.NamespaceName));
if (layout == null)
{
tblPr.Add(new XElement(XName.Get("tblLayout", DocX.w.NamespaceName)));
layout = tblPr.Element(XName.Get("tblLayout", DocX.w.NamespaceName));
}
XAttribute type = layout.Attribute(XName.Get("type", DocX.w.NamespaceName));
if (type == null)
{
layout.Add(new XAttribute(XName.Get("type", DocX.w.NamespaceName), String.Empty));
type = layout.Attribute(XName.Get("type", DocX.w.NamespaceName));
}
type.Value = "fixed";
}
break;
}
case AutoFit.Contents:
{
attributeValue = "auto";
tableAttributeValue = columnAttributeValue = "auto";
break;
}
case AutoFit.Window:
{
attributeValue = "pct";
tableAttributeValue = columnAttributeValue = "pct";
break;
}
}
// Set table attributes
var query = from d in Xml.Descendants()
let type = d.Attribute(XName.Get("type", DocX.w.NamespaceName))
where (d.Name.LocalName == "tcW" || d.Name.LocalName == "tblW") && type != null
where (d.Name.LocalName == "tblW") && type != null
select type;
foreach (XAttribute type in query)
type.Value = attributeValue;
type.Value = tableAttributeValue;
// Set column attributes
query = from d in Xml.Descendants()
let type = d.Attribute(XName.Get("type", DocX.w.NamespaceName))
where (d.Name.LocalName == "tcW") && type != null
select type;
foreach (XAttribute type in query)
type.Value = columnAttributeValue;
autofit = value;
}

正在加载...
取消
保存