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

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 15 лет назад
Родитель
Сommit
eb656ba719
2 измененных файлов: 10 добавлений и 2 удалений
  1. 9
    0
      DocX/DocX.cs
  2. 1
    2
      DocX/Table.cs

+ 9
- 0
DocX/DocX.cs Просмотреть файл

/// </example> /// </example>
public Table InsertTable(int coloumnCount, int rowCount) 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); Table t = base.InsertTable(coloumnCount, rowCount);
t.mainPart = mainPart; t.mainPart = mainPart;
return t; return t;
public Table AddTable(int rowCount, int coloumnCount) 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))); return (new Table(this, HelperFunctions.CreateTable(rowCount, coloumnCount)));
} }
/// </example> /// </example>
public Table InsertTable(int index, int coloumnCount, int rowCount) 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); Table t = InsertTable(index, coloumnCount, rowCount);
t.mainPart = mainPart; t.mainPart = mainPart;
return t; return t;

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

throw new IndexOutOfRangeException(); throw new IndexOutOfRangeException();
List<XElement> content = new List<XElement>(); 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)))); 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); XElement e = new XElement(XName.Get("tr", DocX.w.NamespaceName), content);

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