소스 검색

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

master
PrzemyslawKlys 9 년 전
부모
커밋
4c865999b5

+ 18
- 0
DocX/Paragraph.cs 파일 보기

@@ -2225,6 +2225,24 @@ namespace Novacode
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>
/// Append a hyperlink to a Paragraph.
/// </summary>

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


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


BIN
Documentation/Help/Documentation.chm 파일 보기


+ 3
- 3
Examples/Examples.csproj 파일 보기

@@ -67,13 +67,13 @@
</ItemGroup>
<ItemGroup>
<None Include="app.config" />
<None Include="DocumentWithBookmarks.docx">
<None Include="docs\DocumentWithBookmarks.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="DocumentWithTemplateTable.docx">
<None Include="docs\DocumentWithTemplateTable.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="Input.docx">
<None Include="docs\Input.docx">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

+ 38
- 3
Examples/Program.cs 파일 보기

@@ -31,6 +31,7 @@ namespace Examples
HelloWorldAdvancedFormatting();
HelloWorldProtectedDocument();
HelloWorldAddPictureToWord();
HelloWorldInsertHorizontalLine();
RightToLeft();
Indentation();
HeadersAndFooters();
@@ -313,7 +314,7 @@ namespace Examples
{
Console.WriteLine("\tCreateTableFromTemplate()");
using (DocX docX = DocX.Load("DocumentWithTemplateTable.docx"))
using (DocX docX = DocX.Load(@"docs\DocumentWithTemplateTable.docx"))
{
//look for one specific table here
Table orderTable = docX.Tables.First(t => t.TableCaption == "ORDER_TABLE");
@@ -379,7 +380,7 @@ namespace Examples
{
Console.WriteLine("\tBookmarksReplaceTextOfBookmarkKeepingFormat()");
using (DocX docX = DocX.Load("DocumentWithBookmarks.docx"))
using (DocX docX = DocX.Load(@"docs\DocumentWithBookmarks.docx"))
{
foreach (Bookmark bookmark in docX.Bookmarks)
Console.WriteLine("\t\tFound bookmark {0}", bookmark.Name);
@@ -1573,6 +1574,40 @@ namespace Examples
}
}
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()
{
Console.WriteLine("\tHelloWorldPasswordProtected()");
@@ -1677,7 +1712,7 @@ namespace Examples
const string str = "Hello World";
// 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.
if (document.Images.Count() > 0)

Examples/DocumentWithBookmarks.docx → Examples/docs/DocumentWithBookmarks.docx 파일 보기


Examples/DocumentWithTemplateTable.docx → Examples/docs/DocumentWithTemplateTable.docx 파일 보기


Examples/Input.docx → Examples/docs/Input.docx 파일 보기


Loading…
취소
저장