Kaynağa Gözat

Added Text orientation in table - provided by mbdijs

master
MadBoy_cp 11 yıl önce
ebeveyn
işleme
8f7dfa2081
3 değiştirilmiş dosya ile 95 ekleme ve 0 silme
  1. 61
    0
      DocX/Table.cs
  2. 5
    0
      DocX/_Enumerations.cs
  3. 29
    0
      Examples/Program.cs

+ 61
- 0
DocX/Table.cs Dosyayı Görüntüle

@@ -2014,6 +2014,7 @@ namespace Novacode
}
return b;
}
}
/// <summary>
@@ -3469,8 +3470,67 @@ namespace Novacode
//IMPORTANT: It will be better to check all methods that work with adding anything to cells
return table;
}
public TextDirection TextDirection
{
get
{
XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
// If tcPr is null, this cell contains no width information.
if (tcPr == null)
return TextDirection.right;
XElement textDirection = tcPr.Element(XName.Get("textDirection", DocX.w.NamespaceName));
if (textDirection == null)
return TextDirection.right;
XAttribute val = textDirection.Attribute(XName.Get("val", DocX.w.NamespaceName));
if (val == null)
return TextDirection.right;
// If val is not a VerticalAlign enum, something is wrong with this attributes value, so remove it and return VerticalAlignment.Center;
try
{
return (TextDirection)Enum.Parse(typeof(TextDirection), val.Value, true);
}
catch
{
val.Remove();
return TextDirection.right;
}
}
set
{
/*
* Get the tcPr (table cell properties) element for this Cell,
* null will be return if no such element exists.
*/
XElement tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
if (tcPr == null)
{
Xml.SetElementValue(XName.Get("tcPr", DocX.w.NamespaceName), string.Empty);
tcPr = Xml.Element(XName.Get("tcPr", DocX.w.NamespaceName));
}
/*
* Get the vAlign (table cell vertical alignment) element for this Cell,
* null will be return if no such element exists.
*/
XElement textDirection = tcPr.Element(XName.Get("textDirection", DocX.w.NamespaceName));
if (textDirection == null)
{
tcPr.SetElementValue(XName.Get("textDirection", DocX.w.NamespaceName), string.Empty);
textDirection = tcPr.Element(XName.Get("textDirection", DocX.w.NamespaceName));
}
// Set the VerticalAlignment in 'val'
textDirection.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), value.ToString());
}
}
}
public class TableLook
{
public bool FirstRow { get; set; }
@@ -3480,4 +3540,5 @@ namespace Novacode
public bool NoHorizontalBanding { get; set; }
public bool NoVerticalBanding { get; set; }
}
}

+ 5
- 0
DocX/_Enumerations.cs Dosyayı Görüntüle

@@ -737,5 +737,10 @@ namespace Novacode
}
public enum TextDirection
{
btLr,
right
};
}

+ 29
- 0
Examples/Program.cs Dosyayı Görüntüle

@@ -38,6 +38,7 @@ namespace Examples
LineChart();
Chart3D();
DocumentMargins();
CreateTableWithTextDirection();
// Intermediate
Console.WriteLine("\nRunning Intermediate Examples");
@@ -1060,6 +1061,34 @@ namespace Examples
CreateInvoice();
}
}
private static void CreateTableWithTextDirection()
{
Console.WriteLine("\tCreateTableWithTextDirection()");
// Create a document.
using (DocX document = DocX.Create(@"docs\\CeateTableWithTextDirection.docx"))
{
// Add a Table to this document.
Table t = document.AddTable(2, 3);
// Specify some properties for this Table.
t.Alignment = Alignment.center;
t.Design = TableDesign.MediumGrid1Accent2;
// Add content to this Table.
t.Rows[0].Cells[0].Paragraphs.First().Append("A");
t.Rows[0].Cells[0].TextDirection = TextDirection.btLr;
t.Rows[0].Cells[1].Paragraphs.First().Append("B");
t.Rows[0].Cells[1].TextDirection = TextDirection.btLr;
t.Rows[0].Cells[2].Paragraphs.First().Append("C");
t.Rows[0].Cells[2].TextDirection = TextDirection.btLr;
t.Rows[1].Cells[0].Paragraphs.First().Append("D");
t.Rows[1].Cells[1].Paragraphs.First().Append("E");
t.Rows[1].Cells[2].Paragraphs.First().Append("F");
// Insert the Table into the document.
document.InsertTable(t);
document.Save();
}// Release this document from memory.
Console.WriteLine("\tCreated: docs\\CreateTableWithTextDirection.docx");
}
// Create an invoice for a factitious company called "The Happy Builder".
private static DocX CreateInvoiceFromTemplate(DocX template)

Loading…
İptal
Kaydet