Browse Source

Added InsertHorizontalLine as per vodamihai submit. Added some example code for usage scenario. Cleaned up examples a bit.

master
PrzemyslawKlys 9 years ago
parent
commit
4c865999b5

+ 18
- 0
DocX/Paragraph.cs View File

return this; return this;
} }
public void InsertHorizontalLine(string lineType = "single", int size = 6, int space = 1, string color = "auto")
{
var pPr = this.GetOrCreate_pPr();
var border = pPr.Element(XName.Get("pBdr", DocX.w.NamespaceName));
if (border == null)
{
pPr.Add(new XElement(XName.Get("pBdr", DocX.w.NamespaceName)));
border = pPr.Element(XName.Get("pBdr", DocX.w.NamespaceName));
border.Add(new XElement(XName.Get("bottom", DocX.w.NamespaceName)));
var bottom = border.Element(XName.Get("bottom", DocX.w.NamespaceName));
bottom.SetAttributeValue(XName.Get("val", DocX.w.NamespaceName), lineType);
bottom.SetAttributeValue(XName.Get("sz", DocX.w.NamespaceName), size.ToString());
bottom.SetAttributeValue(XName.Get("space", DocX.w.NamespaceName), space.ToString());
bottom.SetAttributeValue(XName.Get("color", DocX.w.NamespaceName), color);
}
}
/// <summary> /// <summary>
/// Append a hyperlink to a Paragraph. /// Append a hyperlink to a Paragraph.
/// </summary> /// </summary>

BIN
DocX/bin/Debug/DocX.dll View File


BIN
DocX/bin/Release/DocX.dll View File


BIN
Documentation/Help/Documentation.chm View File


+ 3
- 3
Examples/Examples.csproj View File

</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="app.config" /> <None Include="app.config" />
<None Include="DocumentWithBookmarks.docx">
<None Include="docs\DocumentWithBookmarks.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Include="DocumentWithTemplateTable.docx">
<None Include="docs\DocumentWithTemplateTable.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
<None Include="Input.docx">
<None Include="docs\Input.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory> <CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None> </None>
</ItemGroup> </ItemGroup>

+ 38
- 3
Examples/Program.cs View File

HelloWorldAdvancedFormatting(); HelloWorldAdvancedFormatting();
HelloWorldProtectedDocument(); HelloWorldProtectedDocument();
HelloWorldAddPictureToWord(); HelloWorldAddPictureToWord();
HelloWorldInsertHorizontalLine();
RightToLeft(); RightToLeft();
Indentation(); Indentation();
HeadersAndFooters(); HeadersAndFooters();
{ {
Console.WriteLine("\tCreateTableFromTemplate()"); Console.WriteLine("\tCreateTableFromTemplate()");
using (DocX docX = DocX.Load("DocumentWithTemplateTable.docx"))
using (DocX docX = DocX.Load(@"docs\DocumentWithTemplateTable.docx"))
{ {
//look for one specific table here //look for one specific table here
Table orderTable = docX.Tables.First(t => t.TableCaption == "ORDER_TABLE"); Table orderTable = docX.Tables.First(t => t.TableCaption == "ORDER_TABLE");
{ {
Console.WriteLine("\tBookmarksReplaceTextOfBookmarkKeepingFormat()"); Console.WriteLine("\tBookmarksReplaceTextOfBookmarkKeepingFormat()");
using (DocX docX = DocX.Load("DocumentWithBookmarks.docx"))
using (DocX docX = DocX.Load(@"docs\DocumentWithBookmarks.docx"))
{ {
foreach (Bookmark bookmark in docX.Bookmarks) foreach (Bookmark bookmark in docX.Bookmarks)
Console.WriteLine("\t\tFound bookmark {0}", bookmark.Name); Console.WriteLine("\t\tFound bookmark {0}", bookmark.Name);
} }
} }
static void HelloWorldInsertHorizontalLine()
{
Console.WriteLine("\tHelloWorldInsertHorizontalLine()");
// Create a new document.
using (DocX document = DocX.Create(@"docs\HelloWorldInsertHorizontalLine.docx"))
{
// Insert a Paragraph into this document.
Paragraph p = document.InsertParagraph();
// Append some text and add formatting.
p.Append("Hello World!^011Hello World!")
.Font(new FontFamily("Times New Roman"))
.FontSize(32)
.Color(Color.Blue)
.Bold();
p.InsertHorizontalLine("double", 6, 1, "auto");
Paragraph p1 = document.InsertParagraph();
p1.InsertHorizontalLine("double", 6, 1, "red");
Paragraph p2 = document.InsertParagraph();
p2.InsertHorizontalLine("single", 6, 1, "red");
Paragraph p3 = document.InsertParagraph();
p3.InsertHorizontalLine("triple", 6, 1, "blue");
Paragraph p4 = document.InsertParagraph();
p4.InsertHorizontalLine("double", 3, 10, "red");
// Save this document to disk.
document.Save();
Console.WriteLine("\tCreated: docs\\HelloWorldInsertHorizontalLine.docx\n");
}
}
static void HelloWorldProtectedDocument() static void HelloWorldProtectedDocument()
{ {
Console.WriteLine("\tHelloWorldPasswordProtected()"); Console.WriteLine("\tHelloWorldPasswordProtected()");
const string str = "Hello World"; const string str = "Hello World";
// Open the document Input.docx. // Open the document Input.docx.
using (DocX document = DocX.Load(@"Input.docx"))
using (DocX document = DocX.Load(@"docs\Input.docx"))
{ {
// Make sure this document has at least one Image. // Make sure this document has at least one Image.
if (document.Images.Count() > 0) if (document.Images.Count() > 0)

Examples/DocumentWithBookmarks.docx → Examples/docs/DocumentWithBookmarks.docx View File


Examples/DocumentWithTemplateTable.docx → Examples/docs/DocumentWithTemplateTable.docx View File


Examples/Input.docx → Examples/docs/Input.docx View File


Loading…
Cancel
Save