public void FindSlides() { const string file = "../../files/GetNotes.pptx"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(4, nbSlides); { IEnumerable<PptxSlide> slides = pptx.FindSlides("{{comment1}}"); Assert.AreEqual(1, slides.Count()); } { IEnumerable<PptxSlide> slides = pptx.FindSlides("{{comment2}}"); Assert.AreEqual(1, slides.Count()); } { IEnumerable<PptxSlide> slides = pptx.FindSlides("{{comment3}}"); Assert.AreEqual(1, slides.Count()); } pptx.Close(); }
public void EmptyPowerPoint() { const string file = "../../files/EmptyPowerPoint.pptx"; const string thumbnail_empty_png = "../../files/thumbnail_empty.png"; const string thumbnail_empty_output_png = "../../files/thumbnail_empty_output.png"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(0, nbSlides); byte[] thumbnail_empty_output = pptx.GetThumbnail(); File.WriteAllBytes(thumbnail_empty_output_png, thumbnail_empty_output); byte[] thumbnail_empty = File.ReadAllBytes(thumbnail_empty_png); CollectionAssert.AreEqual(thumbnail_empty, thumbnail_empty_output); pptx.Close(); }
public void GetNotes() { const string file = "../../files/GetNotes.pptx"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(4, nbSlides); Assert.AreEqual(string.Empty, pptx.GetSlide(0).GetTitle()); Assert.AreEqual(string.Empty, pptx.GetSlide(1).GetTitle()); Assert.AreEqual(string.Empty, pptx.GetSlide(2).GetTitle()); Assert.AreEqual(string.Empty, pptx.GetSlide(3).GetTitle()); var slidesNotes = new Dictionary<int, string[]>(); for (int i = 0; i < nbSlides; i++) { PptxSlide slide = pptx.GetSlide(i); IEnumerable<string> notes = slide.GetNotes(); slidesNotes.Add(i, notes.ToArray()); } string[] expected = { "Bonjour", "{{comment1}}", "Hello", "1" }; CollectionAssert.AreEqual(expected, slidesNotes[0]); expected = new string[] { "{{comment2}}", "2" }; CollectionAssert.AreEqual(expected, slidesNotes[1]); expected = new string[] { }; CollectionAssert.AreEqual(expected, slidesNotes[2]); // TODO Why "Comment çava ?" instead of "Comment ça va ?" expected = new string[] { "Bonjour {{comment3}} Hello", "Comment çava ?", string.Empty, string.Empty, "Hola!", string.Empty, "4" }; CollectionAssert.AreEqual(expected, slidesNotes[3]); pptx.Close(); }
private void AssertPptxEquals(string file, int nbSlides, string expected) { Pptx pptx = new Pptx(file, FileAccess.Read); Assert.AreEqual(nbSlides, pptx.SlidesCount()); StringBuilder result = new StringBuilder(); for (int i = 0; i < nbSlides; i++) { PptxSlide slide = pptx.GetSlide(i); IEnumerable<string> texts = slide.GetTexts(); result.Append(string.Join(" ", texts)); result.Append(" "); } pptx.Close(); Assert.AreEqual(expected, result.ToString()); }
public void TableColumnTitles() { const string file = "../../files/TableColumnTitles.pptx"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(1, nbSlides); Assert.AreEqual(string.Empty, pptx.GetSlide(0).GetTitle()); var slidesTables = new Dictionary<int, PptxTable[]>(); for (int i = 0; i < nbSlides; i++) { PptxSlide slide = pptx.GetSlide(i); IEnumerable<PptxTable> tables = slide.GetTables(); slidesTables.Add(i, tables.ToArray()); } string[] expected = { "1 Multiple lines", "2", "3", "4", "5" }; CollectionAssert.AreEqual(expected, slidesTables[0][0].ColumnTitles().ToArray()); pptx.Close(); }
public void ReplaceTags() { const string srcFileName = "../../files/ReplaceTags.pptx"; const string dstFileName = "../../files/ReplaceTags_output.pptx"; File.Delete(dstFileName); File.Copy(srcFileName, dstFileName); Pptx pptx = new Pptx(dstFileName, FileAccess.ReadWrite); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(3, nbSlides); // First slide { PptxSlide slide = pptx.GetSlide(0); slide.ReplaceTag("{{hello}}", "HELLO HOW ARE YOU?", PptxSlide.ReplacementType.Global); slide.ReplaceTag("{{bonjour}}", "BONJOUR TOUT LE MONDE", PptxSlide.ReplacementType.Global); slide.ReplaceTag("{{hola}}", "HOLA MAMA QUE TAL?", PptxSlide.ReplacementType.Global); } // Second slide { PptxSlide slide = pptx.GetSlide(1); slide.ReplaceTag("{{hello}}", "H", PptxSlide.ReplacementType.Global); slide.ReplaceTag("{{bonjour}}", "B", PptxSlide.ReplacementType.Global); slide.ReplaceTag("{{hola}}", "H", PptxSlide.ReplacementType.Global); } // Third slide { PptxSlide slide = pptx.GetSlide(2); slide.ReplaceTag("{{hello}}", string.Empty, PptxSlide.ReplacementType.Global); slide.ReplaceTag("{{bonjour}}", string.Empty, PptxSlide.ReplacementType.Global); slide.ReplaceTag("{{hola}}", null, PptxSlide.ReplacementType.Global); slide.ReplaceTag(null, string.Empty, PptxSlide.ReplacementType.Global); slide.ReplaceTag(null, null, PptxSlide.ReplacementType.Global); } pptx.Close(); this.AssertPptxEquals(dstFileName, 3, "words HELLO HOW ARE YOU?|HELLO HOW ARE YOU?|HOLA MAMA QUE TAL?, world! A tag {{hoHOLA MAMA QUE TAL?la}} inside a sentence BONJOUR TOUT LE MONDE A tag BONJOUR TOUT LE MONDEHOLA MAMA QUE TAL?BONJOUR TOUT LE MONDE inside a sentence HELLO HOW ARE YOU?, world! words H|H|H, world! A tag {{hoHla}} inside a sentence B A tag BHB inside a sentence H, world! words ||, world! A tag inside a sentence A tag inside a sentence , world! "); }
public void ReplacePictures() { const string srcFileName = "../../files/ReplacePictures.pptx"; const string dstFileName = "../../files/ReplacePictures_output.pptx"; File.Delete(dstFileName); File.Copy(srcFileName, dstFileName); Pptx pptx = new Pptx(dstFileName, FileAccess.ReadWrite); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(2, nbSlides); Assert.AreEqual(string.Empty, pptx.GetSlide(0).GetTitle()); Assert.AreEqual(string.Empty, pptx.GetSlide(1).GetTitle()); { PptxSlide slide = pptx.GetSlide(0); slide.ReplaceTag("{{hello}}", "HELLO!", PptxSlide.ReplacementType.Global); } const string picture1_replace_png = "../../files/picture1_replace.png"; const string picture1_replace_png_contentType = "image/png"; const string picture1_replace_bmp = "../../files/picture1_replace.bmp"; const string picture1_replace_bmp_contentType = "image/bmp"; const string picture1_replace_jpeg = "../../files/picture1_replace.jpeg"; const string picture1_replace_jpeg_contentType = "image/jpeg"; byte[] picture1_replace_empty = new byte[] { }; for (int i = 0; i < nbSlides; i++) { PptxSlide slide = pptx.GetSlide(i); slide.ReplacePicture("{{picture1png}}", picture1_replace_png, picture1_replace_png_contentType); slide.ReplacePicture("{{picture1bmp}}", picture1_replace_bmp, picture1_replace_bmp_contentType); slide.ReplacePicture("{{picture1jpeg}}", picture1_replace_jpeg, picture1_replace_jpeg_contentType); slide.ReplacePicture(null, picture1_replace_png, picture1_replace_png_contentType); slide.ReplacePicture("{{picture1null}}", picture1_replace_empty, picture1_replace_png_contentType); slide.ReplacePicture("{{picture1null}}", picture1_replace_png, null); slide.ReplacePicture("{{picture1null}}", picture1_replace_empty, null); } pptx.Close(); // Sorry, you will have to manually check that the pictures have been replaced }
public void RemoveSlides() { const string srcFileName = "../../files/RemoveSlides.pptx"; const string dstFileName = "../../files/RemoveSlides_output.pptx"; File.Delete(dstFileName); File.Copy(srcFileName, dstFileName); Pptx pptx = new Pptx(dstFileName, FileAccess.ReadWrite); Assert.AreEqual(5, pptx.SlidesCount()); pptx.GetSlide(1).Remove(); Assert.AreEqual(4, pptx.SlidesCount()); pptx.Close(); pptx = new Pptx(dstFileName, FileAccess.ReadWrite); Assert.AreEqual(4, pptx.SlidesCount()); pptx.GetSlide(0).Remove(); pptx.GetSlide(2).Remove(); // 2 = 3 - the first slide removed Assert.AreEqual(2, pptx.SlidesCount()); pptx.Close(); File.Delete(dstFileName); File.Copy(srcFileName, dstFileName); pptx = new Pptx(dstFileName, FileAccess.ReadWrite); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(5, nbSlides); for (int i = nbSlides - 1; i >= 0; i--) { if (i == 0 || i == 2) { pptx.GetSlide(i).Remove(); } } Assert.AreEqual(3, pptx.SlidesCount()); pptx.Close(); }
public void GetTexts() { const string file = "../../files/GetTexts.pptx"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(3, nbSlides); Assert.AreEqual("test1", pptx.GetSlide(0).GetTitle()); Assert.AreEqual("Title 1", pptx.GetSlide(1).GetTitle()); Assert.AreEqual("Title 2", pptx.GetSlide(2).GetTitle()); var slidesTexts = new Dictionary<int, string[]>(); for (int i = 0; i < nbSlides; i++) { PptxSlide slide = pptx.GetSlide(i); IEnumerable<string> texts = slide.GetTexts(); slidesTexts.Add(i, texts.ToArray()); } string[] expected = { "test1", "Hello, world!" }; CollectionAssert.AreEqual(expected, slidesTexts[0]); expected = new string[] { "Title 1", "Bullet 1", "Bullet 2", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5", "Line 1", string.Empty, string.Empty, string.Empty, string.Empty, "Line 2", string.Empty, string.Empty, string.Empty, string.Empty, "Line 3", string.Empty, string.Empty, string.Empty, string.Empty, "Line 4", string.Empty, string.Empty, string.Empty, string.Empty }; CollectionAssert.AreEqual(expected, slidesTexts[1]); expected = new string[] { "Title 2", "Bullet 1", "Bullet 2", "Comment ça va ?" }; CollectionAssert.AreEqual(expected, slidesTexts[2]); pptx.Close(); }
public void GetTables() { const string file = "../../files/ReplaceTables.pptx"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(3, nbSlides); Assert.AreEqual(string.Empty, pptx.GetSlide(0).GetTitle()); Assert.AreEqual(string.Empty, pptx.GetSlide(1).GetTitle()); Assert.AreEqual(string.Empty, pptx.GetSlide(2).GetTitle()); var slidesTables = new Dictionary<int, PptxTable[]>(); for (int i = 0; i < nbSlides; i++) { PptxSlide slide = pptx.GetSlide(i); IEnumerable<PptxTable> tables = slide.GetTables(); slidesTables.Add(i, tables.ToArray()); } string[] expected = { "Table1", "Col2", "Col3", "Col4", "Col5", "Col6" }; CollectionAssert.AreEqual(expected, slidesTables[1][0].ColumnTitles().ToArray()); expected = new string[] { "Table2", "Col2", "Col3", "Col4", "Col5", "Col6" }; CollectionAssert.AreEqual(expected, slidesTables[1][1].ColumnTitles().ToArray()); expected = new string[] { "Table3", "Col2", "Col3", "Col4", "Col5", "Col6" }; CollectionAssert.AreEqual(expected, slidesTables[1][2].ColumnTitles().ToArray()); pptx.Close(); }
public void GetSlides() { const string file = "../../files/GetTexts.pptx"; Pptx pptx = new Pptx(file, FileAccess.Read); int nbSlides = pptx.SlidesCount(); Assert.AreEqual(3, nbSlides); IEnumerable<PptxSlide> slides = pptx.GetSlides(); Assert.AreEqual(3, slides.Count()); pptx.Close(); }