Kaynağa Gözat

Added gridspan and afterspan properties

master
Michal Maciejewski 9 yıl önce
ebeveyn
işleme
29c3b5cae7
4 değiştirilmiş dosya ile 68 ekleme ve 95 silme
  1. 0
    7
      DocX/DocX.csproj
  2. 67
    87
      DocX/Table.cs
  3. BIN
      DocX/bin/Debug/DocX.dll
  4. 1
    1
      UnitTests/DocXUnitTests.cs

+ 0
- 7
DocX/DocX.csproj Dosyayı Görüntüle

@@ -136,13 +136,6 @@
</ItemGroup>
<ItemGroup>
<Content Include="License\License.html" />
<Content Include="XMLFile1.xml">
<SubType>Designer</SubType>
</Content>
<Content Include="XMLFile2.xml">
<SubType>Designer</SubType>
</Content>
<Content Include="XMLFile3.xml" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\default_styles.xml.gz" />

+ 67
- 87
DocX/Table.cs Dosyayı Görüntüle

@@ -1413,51 +1413,30 @@ namespace Novacode
/// </code>
/// </example>
public void RemoveColumn(int index)
{
{
if (index < 0 || index > ColumnCount - 1)
throw new IndexOutOfRangeException();
foreach (Row r in Rows)
if(r.Cells.Count < ColumnCount)
if (r.Cells.Count < ColumnCount)
{
var positionIndex = 0;
var actualPosition = 0;
var gridAfterVal = 0;
// checks to see if there is a deleted cell
XElement trPr = r.Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
if (trPr != null)
{
XElement gridAfter = trPr.Element(XName.Get("gridAfter", DocX.w.NamespaceName));
if (gridAfter != null)
{
XAttribute val = gridAfter.Attribute(XName.Get("val", DocX.w.NamespaceName));
if (val != null)
{
gridAfterVal = int.Parse(val.Value);
}
}
}
// checks to see if there is a deleted cell
gridAfterVal = r.gridAfter;
// goes through iteration of cells to find the one the that contains the index number
foreach (Cell rowCell in r.Cells)
{
// checks if the cell has a gridspan
var gridSpanVal = 0;
XElement tcPr = rowCell.Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
if (tcPr != null)
{
XElement gridSpan = tcPr.Element(XName.Get("gridSpan", DocX.w.NamespaceName));
if (gridSpan != null)
{
XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName));
int value = 0;
if (val != null)
if (int.TryParse(val.Value, out value))
gridSpanVal = value - 1;
}
if (rowCell.GridSpan != 0)
{
gridSpanVal = rowCell.GridSpan - 1;
}
// checks to see if the index is within its lowest and highest cell value
if ((index - gridAfterVal) >= actualPosition
&& (index - gridAfterVal) <= (actualPosition + gridSpanVal))
@@ -1473,7 +1452,7 @@ namespace Novacode
{
r.Cells[index].Xml.Remove();
}
_cachedColCount = -1;
}
@@ -1619,7 +1598,7 @@ namespace Novacode
if (r.Cells.Count < columnCount)
{
if (index >= columnCount)
{
{
AddCellToRow(r, cell, r.Cells.Count, direction);
}
else
@@ -1629,40 +1608,20 @@ namespace Novacode
var actualPosition = 1;
var gridAfterVal = 0;
// checks to see if there is a deleted cell
XElement trPr = r.Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
if (trPr != null)
{
XElement gridAfter = trPr.Element(XName.Get("gridAfter", DocX.w.NamespaceName));
if (gridAfter != null)
{
XAttribute val = gridAfter.Attribute(XName.Get("val", DocX.w.NamespaceName));
if (val != null)
{
gridAfterVal = int.Parse(val.Value);
}
}
}
gridAfterVal = r.gridAfter;
// goes through iteration of cells to find the one the that contains the index number
foreach (Cell rowCell in r.Cells)
{
// checks if the cell has a gridspan
var gridSpanVal = 0;
XElement tcPr = rowCell.Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
if (tcPr != null)
{
XElement gridSpan = tcPr.Element(XName.Get("gridSpan", DocX.w.NamespaceName));
if (gridSpan != null)
{
XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName));
int value = 0;
if (val != null)
if (int.TryParse(val.Value, out value))
gridSpanVal = value -1;
}
if (rowCell.GridSpan != 0)
{
gridSpanVal = rowCell.GridSpan - 1;
}
// checks to see if the index is within its lowest and highest cell value
if ((index - gridAfterVal) >= actualPosition
&& (index - gridAfterVal) <= (actualPosition + gridSpanVal))
@@ -1721,7 +1680,7 @@ namespace Novacode
public void DeleteAndShiftCellsLeft(int rowIndex, int celIndex)
{
XAttribute gridAfterVal = new XAttribute(XName.Get("val", DocX.w.NamespaceName), 0);
var trPr = Rows[rowIndex].Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
if (trPr != null)
@@ -1748,8 +1707,8 @@ namespace Novacode
}
else
{
XElement trPrXElement = new XElement(XName.Get("trPr",DocX.w.NamespaceName));
XElement gridAfterElement = new XElement(XName.Get("gridAfter", DocX.w.NamespaceName));
XElement trPrXElement = new XElement(XName.Get("trPr", DocX.w.NamespaceName));
XElement gridAfterElement = new XElement(XName.Get("gridAfter", DocX.w.NamespaceName));
XAttribute gridAfterValAttribute = new XAttribute(XName.Get("val", DocX.w.NamespaceName), 1);
gridAfterElement.Add(gridAfterValAttribute);
trPrXElement.Add(gridAfterElement);
@@ -2458,40 +2417,45 @@ namespace Novacode
get
{
int gridSpanSum = 0;
var trPr = Xml.Element(XName.Get("trPr",DocX.w.NamespaceName));
if(trPr !=null)
gridSpanSum += gridAfter;
// Foreach each Cell between startIndex and endIndex inclusive.
foreach (Cell c in Cells)
{
var gridAfter = trPr.Element(XName.Get("gridAfter", DocX.w.NamespaceName));
if(gridAfter != null)
if (c.GridSpan != 0)
{
var val = gridAfter.Attribute(XName.Get("val", DocX.w.NamespaceName));
if(val != null)
{
gridSpanSum += int.Parse(val.Value);
}
gridSpanSum += c.GridSpan - 1;
}
}
// Foreach each Cell between startIndex and endIndex inclusive.
foreach (Cell c in Cells)
// return cells count + count of spanned cells
return Cells.Count + gridSpanSum;
}
}
/// <summary>
/// Returns the GridAfter of a row ie. The amount of cells that are deleted
/// </summary>
public int gridAfter
{
get
{
var gridAfterValue = 0;
var trPr = Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
if (trPr != null)
{
XElement tcPr = c.Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
if (tcPr != null)
var gridAfter = trPr.Element(XName.Get("gridAfter", DocX.w.NamespaceName));
if (gridAfter != null)
{
XElement gridSpan = tcPr.Element(XName.Get("gridSpan", DocX.w.NamespaceName));
if (gridSpan != null)
var val = gridAfter.Attribute(XName.Get("val", DocX.w.NamespaceName));
if (val != null)
{
XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName));
int value = 0;
if (val != null)
if (int.TryParse(val.Value, out value))
gridSpanSum += value - 1;
gridAfterValue += int.Parse(val.Value);
}
}
}
// return cells count + count of spanned cells
return Cells.Count + gridSpanSum;
return gridAfterValue;
}
}
@@ -2854,13 +2818,29 @@ namespace Novacode
return paragraphs;
}
}
/// <summary>
/// Returns the GridSpan of a specific Cell ie. How many cells are merged
/// </summary>
public int GridSpan
{
get
{
var somethin = int.Parse(this.Xml.Element(XName.Get("gridSpan", DocX.w.NamespaceName)).Attribute(XName.Get("Value", DocX.w.NamespaceName)).Value);
return somethin;
var gridSpanVal = 0;
XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
if (tcPr != null)
{
XElement gridSpan = tcPr.Element(XName.Get("gridSpan", DocX.w.NamespaceName));
if (gridSpan != null)
{
XAttribute val = gridSpan.Attribute(XName.Get("val", DocX.w.NamespaceName));
int value = 0;
if (val != null)
if (int.TryParse(val.Value, out value))
gridSpanVal = value;
}
}
return gridSpanVal;
}
}

BIN
DocX/bin/Debug/DocX.dll Dosyayı Görüntüle


+ 1
- 1
UnitTests/DocXUnitTests.cs Dosyayı Görüntüle

@@ -1543,7 +1543,7 @@ namespace UnitTests
t1.InsertColumn(6, true);
t1.InsertColumn(6, true);
t1.InsertColumn(5, true);
document.Save();
document.SaveAs(@"C:\\Meh\\ThisTest.docx");
}
}

Loading…
İptal
Kaydet