Просмотр исходного кода

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

master
coffeycathal_cp 13 лет назад
Родитель
Сommit
19e393223f
1 измененных файлов: 41 добавлений и 6 удалений
  1. 41
    6
      DocX/Table.cs

+ 41
- 6
DocX/Table.cs Просмотреть файл

/// <summary> /// <summary>
/// Auto size this table according to some rule. /// Auto size this table according to some rule.
/// </summary> /// </summary>
/// <remarks>Added by Roger Saele, April 2012. Thank you for your contribution Roger.</remarks>
public AutoFit AutoFit public AutoFit AutoFit
{ {
get { return autofit; } get { return autofit; }
set set
{ {
string attributeValue = string.Empty;
string tableAttributeValue = string.Empty;
string columnAttributeValue = string.Empty;
switch (value) switch (value)
{ {
case AutoFit.ColumnWidth: 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; break;
} }
case AutoFit.Contents: case AutoFit.Contents:
{ {
attributeValue = "auto";
tableAttributeValue = columnAttributeValue = "auto";
break; break;
} }
case AutoFit.Window: case AutoFit.Window:
{ {
attributeValue = "pct";
tableAttributeValue = columnAttributeValue = "pct";
break; break;
} }
} }
// Set table attributes
var query = from d in Xml.Descendants() var query = from d in Xml.Descendants()
let type = d.Attribute(XName.Get("type", DocX.w.NamespaceName)) 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; select type;
foreach (XAttribute type in query) 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; autofit = value;
} }

Загрузка…
Отмена
Сохранить