Skip to content

Commit

Permalink
Merge branch 'master' into NET8
Browse files Browse the repository at this point in the history
  • Loading branch information
PrzemyslawKlys committed Feb 2, 2024
2 parents 0e2a3a5 + 43c829c commit b6218e6
Show file tree
Hide file tree
Showing 15 changed files with 839 additions and 483 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ internal static void Example_AddingImagesSample4(string folderPath, bool openWor


var paragraph3 = document.AddParagraph("Image will be in front of text");
paragraph3.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200, WrapImageText.InFrontText, "Przemek and Kulek on an image");
paragraph3.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200, WrapImageText.InFrontOfText, "Przemek and Kulek on an image");


var paragraph5 = document.AddParagraph("Image will be Square");
Expand Down
2 changes: 2 additions & 0 deletions OfficeIMO.Examples/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ static void Main(string[] args) {

WordTextBox.Example_AddingTextbox(folderPath, false);
WordTextBox.Example_AddingTextbox2(folderPath, false);
WordTextBox.Example_AddingTextbox4(folderPath, false);
WordTextBox.Example_AddingTextbox5(folderPath, false);
WordTextBox.Example_AddingTextbox3(folderPath, false);
}
}
Expand Down
6 changes: 4 additions & 2 deletions OfficeIMO.Examples/Word/Images/Images.Sample1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ internal static void Example_AddingImages(string folderPath, bool openWord) {
var paragraph1 = document.AddParagraph("This paragraph starts with some text");
paragraph1.Text = "0th This paragraph started with some other text and was overwritten and made bold.";
// lets add image to paragraph
paragraph1.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 22, 22);
//paragraph1.Image.WrapText = true; // WrapSideValues.Both;
var paragraphImage = paragraph1.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 22, 22, WrapTextImage.BehindText);

Console.WriteLine(paragraph1.Image.WrapText);
Console.WriteLine(paragraphImage.Image.WrapText);

var paragraph2 = paragraph1.AddText("and more text");
paragraph2.Bold = true;
Expand Down
2 changes: 1 addition & 1 deletion OfficeIMO.Examples/Word/Images/Images.Sample4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal static void Example_AddingImagesSample4(string folderPath, bool openWor


var paragraph3 = document.AddParagraph("Image will be in front of text");
paragraph3.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200, WrapTextImage.InFrontText, "Przemek and Kulek on an image");
paragraph3.AddImage(System.IO.Path.Combine(imagePaths, "PrzemyslawKlysAndKulkozaurr.jpg"), 200, 200, WrapTextImage.InFrontOfText, "Przemek and Kulek on an image");


var paragraph5 = document.AddParagraph("Image will be Square");
Expand Down
96 changes: 96 additions & 0 deletions OfficeIMO.Examples/Word/WordTextBox/WordTextBox.Sample4.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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;
using Text = DocumentFormat.OpenXml.Spreadsheet.Text;

namespace OfficeIMO.Examples.Word {
internal static partial class WordTextBox {
internal static void Example_AddingTextbox4(string folderPath, bool openWord) {
Console.WriteLine("[*] Creating standard document with some textbox");

var filePath = System.IO.Path.Combine(folderPath, "BasicDocumentWithTextBox4.docx");

using (WordDocument document = WordDocument.Create(filePath)) {
var paragraph = document.AddParagraph("Adding paragraph with some text");

document.AddHeadersAndFooters();

var textBox = document.Header.Default.AddTextBox("My textbox in header");

Console.WriteLine("Textbox (header) wraptext: " + textBox.WrapText);

textBox.WrapText = WrapTextImage.Square;

Console.WriteLine("Textbox (header) wraptext: " + textBox.WrapText);

//var textBox1 = document.AddTextBox("My textbox 1 left - InLineWithText", WrapTextImage.InLineWithText);
//textBox1.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
//textBox1.HorizontalAlignment = HorizontalAlignmentValues.Left;
//textBox1.VerticalPositionOffsetCentimeters = 6;

//Console.WriteLine("Textbox1 (body) wraptext (InLineWithText): " + textBox1.WrapText);

var textBox2 = document.AddTextBox("My textbox 2 right - square", WrapTextImage.Square);
textBox2.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox2.HorizontalAlignment = HorizontalAlignmentValues.Right;
textBox2.VerticalPositionOffsetCentimeters = 6;

Console.WriteLine("Textbox2 (body) wraptext (Square): " + textBox2.WrapText);

var textBox3 = document.AddTextBox("My textbox 3 center - tight", WrapTextImage.Tight);
textBox3.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox3.HorizontalAlignment = HorizontalAlignmentValues.Center;
textBox3.VerticalPositionOffsetCentimeters = 6;

Console.WriteLine("Textbox3 (body) wraptext (Tight): " + textBox3.WrapText);

var textBox4 = document.AddTextBox("My textbox 4 left - behind text", WrapTextImage.BehindText);
textBox4.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox4.HorizontalAlignment = HorizontalAlignmentValues.Left;
textBox4.VerticalPositionOffsetCentimeters = 9;

Console.WriteLine("Textbox4 (body) wraptext (BehindText): " + textBox4.WrapText);

var textBox5 = document.AddTextBox("My textbox 5 right - in front of text", WrapTextImage.InFrontOfText);
textBox5.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox5.HorizontalAlignment = HorizontalAlignmentValues.Right;
textBox5.VerticalPositionOffsetCentimeters = 9;

Console.WriteLine("Textbox5 (body) wraptext (InFrontOfText): " + textBox5.WrapText);

var textBox6 = document.AddTextBox("My textbox 6 left - top and bottom", WrapTextImage.TopAndBottom);
textBox6.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox6.HorizontalAlignment = HorizontalAlignmentValues.Left;
textBox6.VerticalPositionOffsetCentimeters = 12;

Console.WriteLine("Textbox6 (body) wraptext (TopAndBottom): " + textBox6.WrapText);

var textBox7 = document.AddTextBox("My textbox 7 right - through", WrapTextImage.Through);
textBox7.HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Page;
textBox7.HorizontalAlignment = HorizontalAlignmentValues.Right;
textBox7.VerticalPositionOffsetCentimeters = 12;

Console.WriteLine("Textbox7 (body) wraptext (Through): " + textBox7.WrapText);

document.AddPageBreak();

document.Sections[0].AddTextBox("My textbox 8 center - Square", WrapTextImage.Square);
document.Sections[0].TextBoxes[0].HorizontalPositionRelativeFrom = HorizontalRelativePositionValues.Margin;
document.Sections[0].TextBoxes[0].VerticalPositionOffsetCentimeters = 10;

//document.AddPageBreak();

document.AddSection();

var wordTextbox = document.Sections[1].AddTextBox("My textbox 9 center - Square", WrapTextImage.Square);
wordTextbox.VerticalPositionOffsetCentimeters = 10;

document.Save(openWord);
}
}
}
}
30 changes: 30 additions & 0 deletions OfficeIMO.Examples/Word/WordTextBox/WordTextBox.Sample5.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using OfficeIMO.Word;

namespace OfficeIMO.Examples.Word {
internal static partial class WordTextBox {
internal static void Example_AddingTextbox5(string folderPath, bool openWord) {
Console.WriteLine("[*] Creating standard document with inline textbox");

var filePath = System.IO.Path.Combine(folderPath, "BasicDocumentWithTextBox5.docx");

using (WordDocument document = WordDocument.Create(filePath)) {
var paragraph = document.AddParagraph("Adding paragraph with some text");

var textBox = document.AddTextBox("My textbox right - inline", WrapTextImage.InLineWithText);

Console.WriteLine("[i] TextBox2 (inline): " + textBox.WrapText);

textBox.WrapText = WrapTextImage.Square;

Console.WriteLine("[i] TextBox2 (square): " + textBox.WrapText);

textBox.WrapText = WrapTextImage.InLineWithText;

Console.WriteLine("[i] TextBox2 (square): " + textBox.WrapText);

document.Save(true);
}
}
}
}
54 changes: 50 additions & 4 deletions OfficeIMO.Tests/Word.Images.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.IO;
using DocumentFormat.OpenXml.Drawing;
using DocumentFormat.OpenXml.Drawing.Wordprocessing;
Expand All @@ -22,7 +23,15 @@ public void Test_CreatingWordDocumentWithImages() {

// lets add image to paragraph
paragraph.AddImage(Path.Combine(_directoryWithImages, "PrzemyslawKlysAndKulkozaurr.jpg"), 22, 22);
//paragraph.Image.WrapText = true; // WrapSideValues.Both;
Assert.True(paragraph.Image.WrapText == WrapTextImage.InLineWithText);

paragraph.Image.WrapText = WrapTextImage.BehindText;

Assert.True(paragraph.Image.WrapText == WrapTextImage.BehindText);

paragraph.Image.WrapText = WrapTextImage.InLineWithText;

Assert.True(paragraph.Image.WrapText == WrapTextImage.InLineWithText);

var paragraph5 = paragraph.AddText("and more text");
paragraph5.Bold = true;
Expand Down Expand Up @@ -79,6 +88,8 @@ public void Test_CreatingWordDocumentWithImages() {
Assert.Equal(4, document.Images.Count);
Assert.Equal(4, document.Sections[0].Images.Count);
document.Save(false);

Assert.True(HasUnexpectedElements(document) == false, "Document has unexpected elements. Order of elements matters!");
}


Expand Down Expand Up @@ -174,7 +185,7 @@ public void Test_LoadingWordDocumentWithImages() {

Assert.True(document.Images[0].WrapText == WrapTextImage.InLineWithText);
Assert.True(document.Images[1].WrapText == WrapTextImage.Square);
Assert.True(document.Images[2].WrapText == WrapTextImage.InFrontText);
Assert.True(document.Images[2].WrapText == WrapTextImage.InFrontOfText);
Assert.True(document.Images[3].WrapText == WrapTextImage.BehindText);
Assert.True(document.Header.Default.Images[0].WrapText == WrapTextImage.InLineWithText);

Expand Down Expand Up @@ -206,7 +217,7 @@ public void Test_CreatingWordDocumentWithImagesWraps() {
paragraph2.AddImage(filePathImage, 100, 100, WrapTextImage.BehindText);

var paragraph3 = document.AddParagraph("This is a test document with images wraps");
paragraph3.AddImage(filePathImage, 100, 100, WrapTextImage.InFrontText);
paragraph3.AddImage(filePathImage, 100, 100, WrapTextImage.InFrontOfText);

var paragraph4 = document.AddParagraph("This is a test document with images wraps");
paragraph4.AddImage(filePathImage, 100, 100, WrapTextImage.TopAndBottom);
Expand All @@ -223,13 +234,15 @@ public void Test_CreatingWordDocumentWithImagesWraps() {
Assert.True(document.Paragraphs.Count == 7);
Assert.True(document.Paragraphs[0].Image.WrapText == WrapTextImage.InLineWithText);
Assert.True(document.Paragraphs[1].Image.WrapText == WrapTextImage.BehindText);
Assert.True(document.Paragraphs[2].Image.WrapText == WrapTextImage.InFrontText);
Assert.True(document.Paragraphs[2].Image.WrapText == WrapTextImage.InFrontOfText);
Assert.True(document.Paragraphs[3].Image.WrapText == WrapTextImage.TopAndBottom);
Assert.True(document.Paragraphs[4].Image.WrapText == WrapTextImage.Square);
Assert.True(document.Paragraphs[5].Image.WrapText == WrapTextImage.Tight);
Assert.True(document.Paragraphs[6].Image.WrapText == WrapTextImage.Through);

document.Save(false);

Assert.True(HasUnexpectedElements(document) == false, "Document has unexpected elements. Order of elements matters!");
}

[Fact]
Expand Down Expand Up @@ -290,6 +303,8 @@ public void Test_CreatingWordDocumentWithFixedImages() {
Assert.NotEqual(vRelativeFromFail, document.Paragraphs[1].Image.verticalPosition.RelativeFrom.Value);

document.Save(false);

Assert.True(HasUnexpectedElements(document) == false, "Document has unexpected elements. Order of elements matters!");
}

[Fact]
Expand Down Expand Up @@ -324,7 +339,38 @@ public void Test_CreatingWordDocumentWithImagesInTable() {
Assert.True(document.Header.Default.Tables.Count == 1);

document.Save(false);

Assert.True(HasUnexpectedElements(document) == false, "Document has unexpected elements. Order of elements matters!");
}

[Fact]
public void Test_CreatingWordDocumentWithImagesInline() {
var filePath = Path.Combine(_directoryWithFiles, "CreatedDocumentWithImagesInline.docx");
using var document = WordDocument.Create(filePath);

var paragraph = document.AddParagraph("This paragraph starts with some text");
paragraph.Text = "0th This paragraph started with some other text and was overwritten and made bold.";

// lets add image to paragraph
var imageParagraph = paragraph.AddImage(Path.Combine(_directoryWithImages, "PrzemyslawKlysAndKulkozaurr.jpg"), 22, 22, WrapTextImage.InLineWithText);

Assert.True(document.Images[0].WrapText == WrapTextImage.InLineWithText);

Assert.True(imageParagraph.Image.WrapText == WrapTextImage.InLineWithText);

imageParagraph.Image.WrapText = WrapTextImage.Square;

Assert.True(imageParagraph.Image.WrapText == WrapTextImage.Square);

var paragraph5 = paragraph.AddText("and more text");
paragraph5.Bold = true;


document.Save(false);

Assert.True(HasUnexpectedElements(document) == false, "Document has unexpected elements. Order of elements matters!");
}

}

}
Loading

0 comments on commit b6218e6

Please sign in to comment.