소스 검색

Fixed add/remove column

master
Michal Maciejewski 9 년 전
부모
커밋
eb58bbe23f
6개의 변경된 파일124개의 추가작업 그리고 185개의 파일을 삭제
  1. 63
    8
      DocX/Table.cs
  2. 0
    13
      DocX/XMLFile1.xml
  3. 0
    128
      DocX/XMLFile2.xml
  4. 0
    10
      DocX/XMLFile3.xml
  5. BIN
      DocX/bin/Debug/DocX.dll
  6. 61
    26
      UnitTests/DocXUnitTests.cs

+ 63
- 8
DocX/Table.cs 파일 보기

@@ -1413,12 +1413,67 @@ namespace Novacode
/// </code>
/// </example>
public void RemoveColumn(int index)
{
{
if (index < 0 || index > ColumnCount - 1)
throw new IndexOutOfRangeException();
foreach (Row r in Rows)
r.Cells[index].Xml.Remove();
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);
}
}
}
// 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;
}
}
// checks to see if the index is within its lowest and highest cell value
if ((index - gridAfterVal) >= actualPosition
&& (index - gridAfterVal) <= (actualPosition + gridSpanVal))
{
r.Cells[positionIndex].Xml.Remove();
break;
}
positionIndex += 1;
actualPosition += gridSpanVal + 1;
}
}
else
{
r.Cells[index].Xml.Remove();
}
_cachedColCount = -1;
}
@@ -1561,7 +1616,6 @@ namespace Novacode
// insert cell
// checks if it is in bounds of index
// TODO: Check for gridspan of cells in row to check if merged cells
if (r.Cells.Count < columnCount)
{
if (index >= columnCount)
@@ -1574,7 +1628,7 @@ namespace Novacode
var positionIndex = 1;
var actualPosition = 1;
var gridAfterVal = 0;
// checks to see if here is a deleted cell
// checks to see if there is a deleted cell
XElement trPr = r.Xml.Element(XName.Get("trPr", DocX.w.NamespaceName));
if (trPr != null)
{
@@ -1591,6 +1645,7 @@ namespace Novacode
// 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)
@@ -1606,9 +1661,9 @@ namespace Novacode
gridSpanVal = value -1;
}
}
// Sees if the cell has gridSpan and if the index is within its lowest and highest cell value
// checks to see if the index is within its lowest and highest cell value
if ((index - gridAfterVal) >= actualPosition
&& (index - gridAfterVal) <= (actualPosition + gridSpanVal))
{
@@ -1677,7 +1732,7 @@ namespace Novacode
var val = gridAfter.Attribute(XName.Get("val", DocX.w.NamespaceName));
if (val != null)
{
val.Value = int.Parse(val.Value + 1).ToString();
val.Value = (int.Parse(val.Value) + 1).ToString();
}
else
{

+ 0
- 13
DocX/XMLFile1.xml 파일 보기

@@ -1,13 +0,0 @@
<w:tr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:trPr>
<w:gridAfter w:val="1" />
</w:trPr>
<w:tc>
<w:tcPr>
<w:tcW w:w="2310" w:type="dxa" />
</w:tcPr>
<w:p>
<w:pPr />
</w:p>
</w:tc>
</w:tr>

+ 0
- 128
DocX/XMLFile2.xml 파일 보기

@@ -1,128 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<w:document xmlns:ve="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:m="http://schemas.openxmlformats.org/officeDocument/2006/math" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main" xmlns:wne="http://schemas.microsoft.com/office/word/2006/wordml">
<w:body>
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid"/>
<w:tblW w:w="0" w:type="auto"/>
<w:tblLook w:val="04A0"/>
</w:tblPr>
<w:tblGrid>
<w:gridCol w:w="2319"/>
<w:gridCol w:w="2319"/>
<w:gridCol w:w="2315"/>
<w:gridCol w:w="2289"/>
</w:tblGrid>
<w:tr w:rsidR="00D73752" w:rsidTr="00D73752">
<w:trPr>
<w:gridAfter w:val="1"/>
<w:wAfter w:w="2289" w:type="dxa"/>
<w:trHeight w:val="1408"/>
</w:trPr>
<w:tc>
<w:tcPr>
<w:tcW w:w="6953" w:type="dxa"/>
<w:gridSpan w:val="3"/>
<w:vMerge w:val="restart"/>
</w:tcPr>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752">
<w:r>
<w:t>a</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752">
<w:r>
<w:t>c</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752">
<w:r>
<w:t>g</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752">
<w:r>
<w:t>d</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752">
<w:r>
<w:t>d</w:t>
</w:r>
</w:p>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752" w:rsidP="00E942FF">
<w:r>
<w:t>F</w:t>
</w:r>
</w:p>
</w:tc>
</w:tr>
<w:tr w:rsidR="00D73752" w:rsidTr="00D73752">
<w:trPr>
<w:trHeight w:val="273"/>
</w:trPr>
<w:tc>
<w:tcPr>
<w:tcW w:w="6953" w:type="dxa"/>
<w:gridSpan w:val="3"/>
<w:vMerge/>
</w:tcPr>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752"/>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="2289" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="00D73752" w:rsidRDefault="00D73752"/>
</w:tc>
</w:tr>
<w:tr w:rsidR="0072257A" w:rsidTr="0072257A">
<w:tc>
<w:tcPr>
<w:tcW w:w="2319" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="0072257A" w:rsidRDefault="0072257A">
<w:r>
<w:t>g</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="2319" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="0072257A" w:rsidRDefault="0072257A">
<w:r>
<w:t>h</w:t>
</w:r>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="2315" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="0072257A" w:rsidRDefault="0072257A">
<w:proofErr w:type="spellStart"/>
<w:r>
<w:t>i</w:t>
</w:r>
<w:proofErr w:type="spellEnd"/>
</w:p>
</w:tc>
<w:tc>
<w:tcPr>
<w:tcW w:w="2289" w:type="dxa"/>
</w:tcPr>
<w:p w:rsidR="0072257A" w:rsidRDefault="0072257A"/>
</w:tc>
</w:tr>
</w:tbl>
<w:p w:rsidR="00FB5292" w:rsidRDefault="00FB5292"/>
<w:sectPr w:rsidR="00FB5292" w:rsidSect="00FB5292">
<w:pgSz w:w="11906" w:h="16838"/>
<w:pgMar w:top="1440" w:right="1440" w:bottom="1440" w:left="1440" w:header="708" w:footer="708" w:gutter="0"/>
<w:cols w:space="708"/>
<w:docGrid w:linePitch="360"/>
</w:sectPr>
</w:body>
</w:document>

+ 0
- 10
DocX/XMLFile3.xml 파일 보기

@@ -1,10 +0,0 @@
<w:tr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:tc>
<w:tcPr>
<w:tcW w:w="2310" w:type="dxa" />
</w:tcPr>
<w:p>
<w:pPr />
</w:p>
</w:tc>
</w:tr>

BIN
DocX/bin/Debug/DocX.dll 파일 보기


+ 61
- 26
UnitTests/DocXUnitTests.cs 파일 보기

@@ -1400,6 +1400,58 @@ namespace UnitTests
}
}
[Test]
public void Test_Table_RemoveColumnWithMergedCells()
{
using (DocX document = DocX.Create(Path.Combine(_directoryDocuments, "Tables3.docx")))
{
//Add A table
Table t = document.AddTable(2, 3);
t.Design = TableDesign.TableGrid;
Table t1 = document.InsertTable(t);
t1.Rows[0].MergeCells(1, 2);
t1.RemoveColumn();
document.Save();
}
}
[Test]
public void Test_Table_MergeRowMergedCellsWithColumnMergedCells()
{
using (DocX document = DocX.Create(Path.Combine(_directoryDocuments, "Tables3.docx")))
{
//Add A table
Table t = document.AddTable(3, 3);
t.Design = TableDesign.TableGrid;
Table t1 = document.InsertTable(t);
t1.Rows[0].MergeCells(0, 1);
t1.Rows[1].MergeCells(0, 1);
t1.MergeCellsInColumn(0, 0, 1);
document.SaveAs(@"C:\\Meh\\ThisTest.docx");
}
}
[Test]
public void Test_Table_RemoveRowWithMergedCells()
{
using (DocX document = DocX.Create(Path.Combine(_directoryDocuments, "Tables3.docx")))
{
//Add A table
Table t = document.AddTable(3, 4);
t.Design = TableDesign.TableGrid;
Table t1 = document.InsertTable(t);
t1.Rows[0].MergeCells(1, 2);
t1.RemoveRow();
t1.MergeCellsInColumn(0, 0, 1);
t1.InsertRow();
t1.RemoveRow(1);
document.Save();
}
}
[Test]
public void Test_Table_InsertRow()
{
@@ -1414,7 +1466,7 @@ namespace UnitTests
t1.InsertRow();
t1.Rows[2].MergeCells(1, 3);
t1.InsertRow(3);
document.SaveAs(@"C:\\Meh\\ThisTest.docx");
document.Save();
}
}
@@ -1430,11 +1482,14 @@ namespace UnitTests
Table t1 = document.InsertTable(t);
t1.DeleteAndShiftCellsLeft(0, 1);
// 4 columns
t1.InsertColumn();
t1.DeleteAndShiftCellsLeft(0, 1);
// 5 columns
t1.InsertColumn();
document.Save();
document.SaveAs(@"C:\\Meh\\ThisTest.docx");
t1.DeleteAndShiftCellsLeft(0, 1);
document.Save();
}
}
@@ -1451,7 +1506,7 @@ namespace UnitTests
t1.DeleteAndShiftCellsLeft(0, 1);
document.Save();
document.SaveAs(@"C:\\Meh\\ThisTest.docx");
document.Save();
}
}
@@ -1482,17 +1537,13 @@ namespace UnitTests
c.Paragraphs[0].InsertText("Hello");
}
}
t1.InsertColumn(6, false);
Assert.AreEqual(t1.ColumnCount, 7);
Assert.IsTrue(String.IsNullOrEmpty(t1.Rows[0].Cells[2].Paragraphs[0].Text));
//Assert.IsTrue(String.IsNullOrEmpty(t1.Rows[1].Cells[6].Paragraphs[0].Text));
t1.InsertColumn(6, false);
t1.InsertColumn();
t1.InsertColumn(3, true);
t1.InsertColumn(6, true);
t1.InsertColumn(6, true);
t1.InsertColumn(5, true);
//Assert.AreEqual(t1.ColumnCount, 8);
document.SaveAs(@"C:\\Meh\\ThisTest.docx");
document.Save();
}
}
@@ -1521,22 +1572,6 @@ namespace UnitTests
document.Save();
}
using (DocX document = DocX.Create(Path.Combine(_directoryDocuments, "Tables3.docx")))
{
//Add A table
Table t = document.AddTable(2, 1);
t.Design = TableDesign.TableGrid;
Table t1 = document.InsertTable(t);
foreach (Row r in t1.Rows)
{
foreach (Cell c in r.Cells)
{
c.Paragraphs[0].InsertText("Hello");
}
}
}
// Check table
using (DocX document = DocX.Load(Path.Combine(_directoryDocuments, "Tables2.docx")))
{

Loading…
취소
저장