Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve textboxes to allow multiple Runs/Paragraphs **Breaking Changes** #225

Merged
merged 5 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions OfficeIMO.Examples/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.IO;

using OfficeIMO.Examples.Excel;
using OfficeIMO.Examples.Word;

Expand Down
39 changes: 26 additions & 13 deletions OfficeIMO.Examples/Word/WordTextBox/WordTextBox.Sample1.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;

using DocumentFormat.OpenXml.Drawing.Wordprocessing;

using OfficeIMO.Word;

using Color = SixLabors.ImageSharp.Color;
using HorizontalAlignmentValues = DocumentFormat.OpenXml.Drawing.Wordprocessing.HorizontalAlignmentValues;

Expand All @@ -16,19 +19,19 @@ internal static void Example_AddingTextbox(string folderPath, bool openWord) {

var textBox = document.AddTextBox("[Grab your reader’s attention with a great quote from the document or use this space to emphasize a key point. To place this text box anywhere on the page, just drag it.]");

Console.WriteLine("TextBox Text: " + textBox.Text);
Console.WriteLine("TextBox Text: " + textBox.Paragraphs[0].Text);

textBox.Text = "We can then modify the text box text";
textBox.Paragraphs[0].Text = "We can then modify the text box text";

Console.WriteLine("TextBox Text: " + textBox.WordParagraph.Text);
Console.WriteLine("TextBox Text: " + textBox.Paragraphs[0].Text);

Console.WriteLine("TextBoc Color: " + textBox.WordParagraph.Color.ToString());
Console.WriteLine("TextBoc Color: " + textBox.Paragraphs[0].Color.ToString());

textBox.WordParagraph.Text = "This is a text box 1";
textBox.Paragraphs[0].Text = "This is a text box 1";

Console.WriteLine("TextBox Text: " + textBox.WordParagraph.Text);
Console.WriteLine("TextBox Text: " + textBox.Paragraphs[0].Text);

textBox.WordParagraph.Color = Color.Red;
textBox.Paragraphs[0].Color = Color.Red;


textBox.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
Expand Down Expand Up @@ -64,22 +67,32 @@ internal static void Example_AddingTextbox(string folderPath, bool openWord) {

document.TextBoxes[1].VerticalPositionOffsetCentimeters = 15;

Console.WriteLine("Color Bottom Border: " + document.TextBoxes[1].WordParagraph.Borders.BottomColor);
Console.WriteLine("Color Bottom Border: " + document.TextBoxes[1].Paragraphs[0].Borders.BottomColor);

document.TextBoxes[1].WordParagraph.Borders.BottomColor = Color.Red;
document.TextBoxes[1].WordParagraph.Borders.BottomStyle = DocumentFormat.OpenXml.Wordprocessing.BorderValues.DashDotStroked;
document.TextBoxes[1].Paragraphs[0].Borders.BottomColor = Color.Red;
document.TextBoxes[1].Paragraphs[0].Borders.BottomStyle = DocumentFormat.OpenXml.Wordprocessing.BorderValues.DashDotStroked;

Console.WriteLine("Color Bottom Border: " + document.TextBoxes[1].WordParagraph.Borders.BottomColor);
Console.WriteLine("Color Bottom Border: " + document.TextBoxes[1].Paragraphs[0].Borders.BottomColor);

document.TextBoxes[1].WordParagraph.Borders.BottomThemeColor = null;
document.TextBoxes[1].Paragraphs[0].Borders.BottomThemeColor = null;

document.TextBoxes[1].RelativeWidthPercentage = 0;
document.TextBoxes[1].RelativeHeightPercentage = 0;

document.TextBoxes[1].WidthCentimeters = 7;
document.TextBoxes[1].HeightCentimeters = 2.5;

document.TextBoxes[0].WordParagraph.Borders.Type = WordBorder.None;
document.TextBoxes[0].Paragraphs[0].Borders.Type = WordBorder.None;

document.TextBoxes[1].Paragraphs[0].AddParagraph("This is a new paragraph in the text box");
Console.WriteLine(document.TextBoxes[1].Paragraphs.Count);
Console.WriteLine(document.TextBoxes[1].Paragraphs[0].Text);
Console.WriteLine(document.TextBoxes[1].Paragraphs[1].Text);

document.TextBoxes[1].Paragraphs[1].Text = "New text";
Console.WriteLine(document.TextBoxes[1].Paragraphs[1].Text);

Console.WriteLine(document.TextBoxes[1].Paragraphs[1].Text);

document.Save(openWord);
}
Expand Down
23 changes: 13 additions & 10 deletions OfficeIMO.Examples/Word/WordTextBox/WordTextBox.Sample2.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System;

using DocumentFormat.OpenXml.Drawing.Wordprocessing;
using DocumentFormat.OpenXml.Spreadsheet;
using DocumentFormat.OpenXml.Wordprocessing;

using OfficeIMO.Word;

using Color = SixLabors.ImageSharp.Color;
using HorizontalAlignmentValues = DocumentFormat.OpenXml.Drawing.Wordprocessing.HorizontalAlignmentValues;

Expand All @@ -25,7 +28,7 @@ internal static void Example_AddingTextbox2(string folderPath, bool openWord) {

var textBox2 = document.AddTextBox("My textbox on the right");
textBox2.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox2.WordParagraph.ParagraphAlignment = JustificationValues.Right;
textBox2.Paragraphs[0].ParagraphAlignment = JustificationValues.Right;
// horizontal alignment overwrites the horizontal position offset so only one will work
textBox2.HorizontalAlignment = HorizontalAlignmentValues.Right;
textBox2.VerticalPositionOffsetCentimeters = 3;
Expand All @@ -40,15 +43,15 @@ internal static void Example_AddingTextbox2(string folderPath, bool openWord) {
textBox3.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox3.HorizontalAlignment = HorizontalAlignmentValues.Center;
textBox3.VerticalPositionOffsetCentimeters = 10;
textBox3.WordParagraph.Borders.BottomStyle = BorderValues.BasicWideOutline;
textBox3.WordParagraph.Borders.BottomSize = 10;
textBox3.WordParagraph.Borders.BottomColor = Color.Red;
textBox3.WordParagraph.Borders.BottomShadow = false;
textBox3.WordParagraph.Borders.TopStyle = BorderValues.BasicWideOutline;
textBox3.WordParagraph.Borders.LeftStyle = BorderValues.BasicWideOutline;
textBox3.WordParagraph.Borders.RightStyle = BorderValues.BasicWideOutline;

textBox3.WordParagraph.Borders.SetBorder(WordParagraphBorderType.Left, BorderValues.BasicWideOutline, Color.Red, 10, false);
textBox3.Paragraphs[0].Borders.BottomStyle = BorderValues.BasicWideOutline;
textBox3.Paragraphs[0].Borders.BottomSize = 10;
textBox3.Paragraphs[0].Borders.BottomColor = Color.Red;
textBox3.Paragraphs[0].Borders.BottomShadow = false;
textBox3.Paragraphs[0].Borders.TopStyle = BorderValues.BasicWideOutline;
textBox3.Paragraphs[0].Borders.LeftStyle = BorderValues.BasicWideOutline;
textBox3.Paragraphs[0].Borders.RightStyle = BorderValues.BasicWideOutline;

textBox3.Paragraphs[0].Borders.SetBorder(WordParagraphBorderType.Left, BorderValues.BasicWideOutline, Color.Red, 10, false);

// remove the textbox
textBox2.Remove();
Expand Down
Loading