Parcourir la source

Added a check to stop the creation of a Table with 0 columns or rows.

Word dose not let you do this and DocX aims to create documents that Word can open.
master
coffeycathal_cp il y a 15 ans
Parent
révision
eb656ba719
2 fichiers modifiés avec 10 ajouts et 2 suppressions
  1. 9
    0
      DocX/DocX.cs
  2. 1
    2
      DocX/Table.cs

+ 9
- 0
DocX/DocX.cs Voir le fichier

@@ -930,6 +930,9 @@ namespace Novacode
/// </example>
public Table InsertTable(int coloumnCount, int rowCount)
{
if (rowCount < 1 || coloumnCount < 1)
throw new ArgumentOutOfRangeException("Row and Coloumn count must be greater than zero.");
Table t = base.InsertTable(coloumnCount, rowCount);
t.mainPart = mainPart;
return t;
@@ -937,6 +940,9 @@ namespace Novacode
public Table AddTable(int rowCount, int coloumnCount)
{
if (rowCount < 1 || coloumnCount < 1)
throw new ArgumentOutOfRangeException("Row and Coloumn count must be greater than zero.");
return (new Table(this, HelperFunctions.CreateTable(rowCount, coloumnCount)));
}
@@ -1056,6 +1062,9 @@ namespace Novacode
/// </example>
public Table InsertTable(int index, int coloumnCount, int rowCount)
{
if (rowCount < 1 || coloumnCount < 1)
throw new ArgumentOutOfRangeException("Row and Coloumn count must be greater than zero.");
Table t = InsertTable(index, coloumnCount, rowCount);
t.mainPart = mainPart;
return t;

+ 1
- 2
DocX/Table.cs Voir le fichier

@@ -771,8 +771,7 @@ namespace Novacode
throw new IndexOutOfRangeException();
List<XElement> content = new List<XElement>();
foreach (Cell c in Rows[0].Cells)
for (int i = 0; i < columnCount; i++ )
content.Add(new XElement(XName.Get("tc", DocX.w.NamespaceName), new XElement(XName.Get("p", DocX.w.NamespaceName))));
XElement e = new XElement(XName.Get("tr", DocX.w.NamespaceName), content);

Chargement…
Annuler
Enregistrer