Ver código fonte

1. override InsertTable(int rowCount, int columnCount) method in Table Cell because of bug.

	Cell need paragraph in the end.
2. InsertTableBeforeSelf(Table t) behaviour changed, now it returns completely new table copied from parameter table.
3. InsertParagraphAfterSelf(Paragraph p) behaviour changed, now it returns completely new paragraph copied from parameter paragraph, but only in case for this is Paragraph
4. InsertTableAfterSelf(Table t) the same as for InsertTableBeforeSelf behaviour changed, now it returns completely new table copied from parameter table.

P.S. Look please my //IMPORTANT notes in code.
master
dmitchern_cp 13 anos atrás
pai
commit
1f722091ff
9 arquivos alterados com 105 adições e 63 exclusões
  1. 1
    0
      DocX.vsmdi
  2. 4
    4
      DocX/Container.cs
  3. 3
    3
      DocX/CustomProperty.cs
  4. 20
    20
      DocX/DocX.cs
  5. 9
    3
      DocX/HelperFunctions.cs
  6. 23
    7
      DocX/Paragraph.cs
  7. 21
    13
      DocX/Table.cs
  8. 22
    11
      DocX/_BaseClasses.cs
  9. 2
    2
      Examples/Program.cs

+ 1
- 0
DocX.vsmdi Ver arquivo

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<TestLists xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
<TestList name="List1" id="5acd79f2-f7f8-4088-87d0-23aa5f6cdeae" parentListId="8c43106b-9dc1-4907-a29f-aa66a61bf5b6" />
<TestList name="Lists of Tests" id="8c43106b-9dc1-4907-a29f-aa66a61bf5b6">
<RunConfiguration id="95fe5b2d-3af6-4f81-a23a-86c45b1f95a1" name="Local" storage="local.testsettings" type="Microsoft.VisualStudio.TestTools.Common.TestRunConfiguration, Microsoft.VisualStudio.QualityTools.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</TestList>

+ 4
- 4
DocX/Container.cs Ver arquivo

@@ -420,17 +420,17 @@ namespace Novacode
return p;
}
public Table InsertTable(int rowCount, int coloumnCount)
public virtual Table InsertTable(int rowCount, int columnCount) //Dmitchern, changed to virtual, and overrided in Table.Cell
{
XElement newTable = HelperFunctions.CreateTable(rowCount, coloumnCount);
XElement newTable = HelperFunctions.CreateTable(rowCount, columnCount);
Xml.Add(newTable);
return new Table(Document, newTable);
}
public Table InsertTable(int index, int rowCount, int coloumnCount)
public Table InsertTable(int index, int rowCount, int columnCount)
{
XElement newTable = HelperFunctions.CreateTable(rowCount, coloumnCount);
XElement newTable = HelperFunctions.CreateTable(rowCount, columnCount);
Paragraph p = HelperFunctions.GetFirstParagraphEffectedByInsert(Document, index);

+ 3
- 3
DocX/CustomProperty.cs Ver arquivo

@@ -36,19 +36,19 @@ namespace Novacode
case "i4":
{
realValue = int.Parse(value);
realValue = int.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
break;
}
case "r8":
{
realValue = double.Parse(value);
realValue = Double.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
break;
}
case "filetime":
{
realValue = DateTime.Parse(value);
realValue = DateTime.Parse(value, System.Globalization.CultureInfo.InvariantCulture);
break;
}

+ 20
- 20
DocX/DocX.cs Ver arquivo

@@ -1549,22 +1549,22 @@ namespace Novacode
/// <summary>
/// Insert a new Table at the end of this document.
/// </summary>
/// <param name="coloumnCount">The number of coloumns to create.</param>
/// <param name="columnCount">The number of columns to create.</param>
/// <param name="rowCount">The number of rows to create.</param>
/// <returns>A new Table.</returns>
/// <example>
/// Insert a new Table with 2 coloumns and 3 rows, at the end of a document.
/// Insert a new Table with 2 columns and 3 rows, at the end of a document.
/// <code>
/// // Create a document.
/// using (DocX document = DocX.Create(@"C:\Example\Test.docx"))
/// {
/// // Create a new Table with 2 coloumns and 3 rows.
/// // Create a new Table with 2 columns and 3 rows.
/// Table newTable = document.InsertTable(2, 3);
///
/// // Set the design of this Table.
/// newTable.Design = TableDesign.LightShadingAccent2;
///
/// // Set the coloumn names.
/// // Set the column names.
/// newTable.Rows[0].Cells[0].Paragraph.InsertText("Ice Cream", false);
/// newTable.Rows[0].Cells[1].Paragraph.InsertText("Price", false);
///
@@ -1581,22 +1581,22 @@ namespace Novacode
/// }// Release this document from memory.
/// </code>
/// </example>
public new Table InsertTable(int rowCount, int coloumnCount)
public new Table InsertTable(int rowCount, int columnCount)
{
if (rowCount < 1 || coloumnCount < 1)
throw new ArgumentOutOfRangeException("Row and Coloumn count must be greater than zero.");
if (rowCount < 1 || columnCount < 1)
throw new ArgumentOutOfRangeException("Row and Column count must be greater than zero.");
Table t = base.InsertTable(rowCount, coloumnCount);
Table t = base.InsertTable(rowCount, columnCount);
t.mainPart = mainPart;
return t;
}
public Table AddTable(int rowCount, int coloumnCount)
public Table AddTable(int rowCount, int columnCount)
{
if (rowCount < 1 || coloumnCount < 1)
throw new ArgumentOutOfRangeException("Row and Coloumn count must be greater than zero.");
if (rowCount < 1 || columnCount < 1)
throw new ArgumentOutOfRangeException("Row and Column count must be greater than zero.");
Table t = new Table(this, HelperFunctions.CreateTable(rowCount, coloumnCount));
Table t = new Table(this, HelperFunctions.CreateTable(rowCount, columnCount));
t.mainPart = mainPart;
return t;
}
@@ -1683,23 +1683,23 @@ namespace Novacode
/// <summary>
/// Insert a new Table at the end of this document.
/// </summary>
/// <param name="coloumnCount">The number of coloumns to create.</param>
/// <param name="columnCount">The number of columns to create.</param>
/// <param name="rowCount">The number of rows to create.</param>
/// <param name="index">The index to insert this Table at.</param>
/// <returns>A new Table.</returns>
/// <example>
/// Insert a new Table with 2 coloumns and 3 rows, at index 37 in this document.
/// Insert a new Table with 2 columns and 3 rows, at index 37 in this document.
/// <code>
/// // Create a document.
/// using (DocX document = DocX.Load(@"C:\Example\Test.docx"))
/// {
/// // Create a new Table with 3 rows and 2 coloumns. Insert this Table at index 37.
/// // Create a new Table with 3 rows and 2 columns. Insert this Table at index 37.
/// Table newTable = document.InsertTable(37, 3, 2);
///
/// // Set the design of this Table.
/// newTable.Design = TableDesign.LightShadingAccent3;
///
/// // Set the coloumn names.
/// // Set the column names.
/// newTable.Rows[0].Cells[0].Paragraph.InsertText("Ice Cream", false);
/// newTable.Rows[0].Cells[1].Paragraph.InsertText("Price", false);
///
@@ -1716,12 +1716,12 @@ namespace Novacode
/// }// Release this document from memory.
/// </code>
/// </example>
public new Table InsertTable(int index, int rowCount, int coloumnCount)
public new Table InsertTable(int index, int rowCount, int columnCount)
{
if (rowCount < 1 || coloumnCount < 1)
if (rowCount < 1 || columnCount < 1)
throw new ArgumentOutOfRangeException("Row and Column count must be greater than zero.");
Table t = base.InsertTable(index, rowCount, coloumnCount);
Table t = base.InsertTable(index, rowCount, columnCount);
t.mainPart = mainPart;
return t;
}
@@ -3720,4 +3720,4 @@ namespace Novacode
#endregion
}
}
}

+ 9
- 3
DocX/HelperFunctions.cs Ver arquivo

@@ -365,7 +365,7 @@ namespace Novacode
);
}
internal static XElement CreateTable(int rowCount, int coloumnCount)
internal static XElement CreateTable(int rowCount, int columnCount)
{
XElement newTable =
new XElement
@@ -381,7 +381,7 @@ namespace Novacode
);
XElement tableGrid = new XElement(XName.Get("tblGrid", DocX.w.NamespaceName));
for (int i = 0; i < coloumnCount; i++)
for (int i = 0; i < columnCount; i++)
tableGrid.Add(new XElement(XName.Get("gridCol", DocX.w.NamespaceName), new XAttribute(XName.Get("w", DocX.w.NamespaceName), "2310")));
newTable.Add(tableGrid);
@@ -390,7 +390,7 @@ namespace Novacode
{
XElement row = new XElement(XName.Get("tr", DocX.w.NamespaceName));
for (int j = 0; j < coloumnCount; j++)
for (int j = 0; j < columnCount; j++)
{
XElement cell = CreateTableCell();
row.Add(cell);
@@ -451,6 +451,12 @@ namespace Novacode
XElement breakRun = new XElement(DocX.w + "br");
StringBuilder sb = new StringBuilder();
if (string.IsNullOrEmpty(text))
{
return newRuns; //I dont wanna get an exception if text == null, so just return empy list
}
foreach (char c in text)
{
switch (c)

+ 23
- 7
DocX/Paragraph.cs Ver arquivo

@@ -629,7 +629,7 @@ namespace Novacode
/// Insert a new Table into this document before this Paragraph.
/// </summary>
/// <param name="rowCount">The number of rows this Table should have.</param>
/// <param name="coloumnCount">The number of coloumns this Table should have.</param>
/// <param name="columnCount">The number of columns this Table should have.</param>
/// <returns>A new Table inserted before this Paragraph.</returns>
/// <example>
/// <code>
@@ -649,9 +649,9 @@ namespace Novacode
/// }// Release this document from memory.
/// </code>
/// </example>
public override Table InsertTableBeforeSelf(int rowCount, int coloumnCount)
public override Table InsertTableBeforeSelf(int rowCount, int columnCount)
{
return base.InsertTableBeforeSelf(rowCount, coloumnCount);
return base.InsertTableBeforeSelf(rowCount, columnCount);
}
/// <summary>
@@ -697,7 +697,7 @@ namespace Novacode
/// Insert a new Table into this document after this Paragraph.
/// </summary>
/// <param name="rowCount">The number of rows this Table should have.</param>
/// <param name="coloumnCount">The number of coloumns this Table should have.</param>
/// <param name="columnCount">The number of columns this Table should have.</param>
/// <returns>A new Table inserted after this Paragraph.</returns>
/// <example>
/// <code>
@@ -717,9 +717,9 @@ namespace Novacode
/// }// Release this document from memory.
/// </code>
/// </example>
public override Table InsertTableAfterSelf(int rowCount, int coloumnCount)
public override Table InsertTableAfterSelf(int rowCount, int columnCount)
{
return base.InsertTableAfterSelf(rowCount, coloumnCount);
return base.InsertTableAfterSelf(rowCount, columnCount);
}
/// <summary>
@@ -2408,7 +2408,23 @@ namespace Novacode
rPr.SetElementValue(textFormatPropName, value);
XElement last = rPr.Elements().Last();
last.Add(content);
if (content as System.Xml.Linq.XAttribute != null)//If content is an attribute
{
if (last.Attribute(((System.Xml.Linq.XAttribute)(content)).Name) == null)
{
last.Add(content); //Add this attribute if element doesn't have it
}
else
{
last.Attribute(((System.Xml.Linq.XAttribute)(content)).Name).Value = ((System.Xml.Linq.XAttribute)(content)).Value; //Apply value only if element already has it
}
}
else
{
//IMPORTANT
//But what to do if it is not?
}
}
}

+ 21
- 13
DocX/Table.cs Ver arquivo

@@ -165,7 +165,7 @@ namespace Novacode
}
/// <summary>
/// Returns the number of coloumns in this table.
/// Returns the number of columns in this table.
/// </summary>
public Int32 ColumnCount
{
@@ -618,7 +618,7 @@ namespace Novacode
/// // Insert a new column to this right of this table.
/// table.InsertColumn();
///
/// // Set the new coloumns text to "Row no."
/// // Set the new columns text to "Row no."
/// table.Rows[0].Cells[table.ColumnCount - 1].Paragraph.InsertText("Row no.", false);
///
/// // Loop through each row in the table.
@@ -627,7 +627,7 @@ namespace Novacode
/// // The current row.
/// Row row = table.Rows[i];
///
/// // The cell in this row that belongs to the new coloumn.
/// // The cell in this row that belongs to the new column.
/// Cell cell = row.Cells[table.ColumnCount - 1];
///
/// // The first Paragraph that this cell houses.
@@ -728,9 +728,9 @@ namespace Novacode
}
/// <summary>
/// Remove a coloumn from this Table.
/// Remove a column from this Table.
/// </summary>
/// <param name="index">The coloumn to remove.</param>
/// <param name="index">The column to remove.</param>
/// <example>
/// Remove the first column from a Table.
/// <code>
@@ -854,7 +854,7 @@ namespace Novacode
/// // Insert a new column to this left of this table.
/// table.InsertColumn(0);
///
/// // Set the new coloumns text to "Row no."
/// // Set the new columns text to "Row no."
/// table.Rows[0].Cells[table.ColumnCount - 1].Paragraph.InsertText("Row no.", false);
///
/// // Loop through each row in the table.
@@ -863,7 +863,7 @@ namespace Novacode
/// // The current row.
/// Row row = table.Rows[i];
///
/// // The cell in this row that belongs to the new coloumn.
/// // The cell in this row that belongs to the new column.
/// Cell cell = row.Cells[table.ColumnCount - 1];
///
/// // The first Paragraph that this cell houses.
@@ -995,7 +995,7 @@ namespace Novacode
/// Insert a new Table into this document before this Table.
/// </summary>
/// <param name="rowCount">The number of rows this Table should have.</param>
/// <param name="coloumnCount">The number of coloumns this Table should have.</param>
/// <param name="columnCount">The number of columns this Table should have.</param>
/// <returns>A new Table inserted before this Table.</returns>
/// <example>
/// <code>
@@ -1017,9 +1017,9 @@ namespace Novacode
/// }// Release this document from memory.
/// </code>
/// </example>
public override Table InsertTableBeforeSelf(int rowCount, int coloumnCount)
public override Table InsertTableBeforeSelf(int rowCount, int columnCount)
{
return base.InsertTableBeforeSelf(rowCount, coloumnCount);
return base.InsertTableBeforeSelf(rowCount, columnCount);
}
/// <summary>
@@ -1063,7 +1063,7 @@ namespace Novacode
/// Insert a new Table into this document after this Table.
/// </summary>
/// <param name="rowCount">The number of rows this Table should have.</param>
/// <param name="coloumnCount">The number of coloumns this Table should have.</param>
/// <param name="columnCount">The number of columns this Table should have.</param>
/// <returns>A new Table inserted before this Table.</returns>
/// <example>
/// <code>
@@ -1085,9 +1085,9 @@ namespace Novacode
/// }// Release this document from memory.
/// </code>
/// </example>
public override Table InsertTableAfterSelf(int rowCount, int coloumnCount)
public override Table InsertTableAfterSelf(int rowCount, int columnCount)
{
return base.InsertTableAfterSelf(rowCount, coloumnCount);
return base.InsertTableAfterSelf(rowCount, columnCount);
}
/// <summary>
@@ -2896,5 +2896,13 @@ namespace Novacode
shd.SetAttributeValue(XName.Get("fill", DocX.w.NamespaceName), value.ToHex());
}
}
public override Table InsertTable(int rowCount, int columnCount)
{
Table table = base.InsertTable(rowCount, columnCount);
InsertParagraph(); //Dmitchern, It is necessary to put paragraph in the end of the cell, without it MS-Word will say that the document is corrupted
//IMPORTANT: It will be better to check all methods that work with adding anything to cells
return table;
}
}
}

+ 22
- 11
DocX/_BaseClasses.cs Ver arquivo

@@ -104,8 +104,16 @@ namespace Novacode
Xml.AddAfterSelf(p.Xml);
XElement newlyInserted = Xml.ElementsAfterSelf().First();
p.Xml = newlyInserted;
return p;
//Dmitchern
if (this as Paragraph != null)
{
return new Paragraph(Document, newlyInserted, (this as Paragraph).endIndex);
}
else
{
p.Xml = newlyInserted; //IMPORTANT: I think we have return new paragraph in any case, but I dont know what to put as startIndex parameter into Paragraph constructor
return p;
}
}
public virtual Paragraph InsertParagraphBeforeSelf(string text)
@@ -164,9 +172,9 @@ namespace Novacode
return p;
}
public virtual Table InsertTableAfterSelf(int rowCount, int coloumnCount)
public virtual Table InsertTableAfterSelf(int rowCount, int columnCount)
{
XElement newTable = HelperFunctions.CreateTable(rowCount, coloumnCount);
XElement newTable = HelperFunctions.CreateTable(rowCount, columnCount);
Xml.AddAfterSelf(newTable);
XElement newlyInserted = Xml.ElementsAfterSelf().First();
@@ -177,15 +185,16 @@ namespace Novacode
{
Xml.AddAfterSelf(t.Xml);
XElement newlyInserted = Xml.ElementsAfterSelf().First();
//Dmitchern
return new Table(Document, newlyInserted); //return new table, dont affect parameter table
t.Xml = newlyInserted;
return t;
//t.Xml = newlyInserted;
//return t;
}
public virtual Table InsertTableBeforeSelf(int rowCount, int coloumnCount)
public virtual Table InsertTableBeforeSelf(int rowCount, int columnCount)
{
XElement newTable = HelperFunctions.CreateTable(rowCount, coloumnCount);
XElement newTable = HelperFunctions.CreateTable(rowCount, columnCount);
Xml.AddBeforeSelf(newTable);
XElement newlyInserted = Xml.ElementsBeforeSelf().Last();
@@ -197,9 +206,11 @@ namespace Novacode
Xml.AddBeforeSelf(t.Xml);
XElement newlyInserted = Xml.ElementsBeforeSelf().Last();
t.Xml = newlyInserted;
//Dmitchern
return new Table(Document, newlyInserted); //return new table, dont affect parameter table
return t;
//t.Xml = newlyInserted;
//return t;
}
}
}

+ 2
- 2
Examples/Program.cs Ver arquivo

@@ -651,7 +651,7 @@ namespace Examples
}
}
// We want to fill in the total by suming the values from the amount coloumn.
// We want to fill in the total by suming the values from the amount column.
Row total = invoice_table.InsertRow();
total.Cells[0].Paragraphs[0].InsertText("Total:", false);
Paragraph total_paragraph = total.Cells[invoice_table.ColumnCount - 1].Paragraphs[0];
@@ -679,7 +679,7 @@ namespace Examples
// Insert the total calculated above using LINQ into the total Paragraph.
total_paragraph.InsertText(string.Format("€{0}", totalCost), false);
// Let the tables coloumns expand to fit its contents.
// Let the tables columns expand to fit its contents.
invoice_table.AutoFit = AutoFit.Contents;
// Center the Table

Carregando…
Cancelar
Salvar