Skip to content

Commit 3d0ac9f

Browse files
shps951023gitee-org
authored andcommitted
!5 Add a new tag that supports inserting multiple images.
Merge pull request !5 from JIAMing12/N/A
2 parents 1c03ecf + bf0bc96 commit 3d0ac9f

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/MiniWord/MiniWord.Implment.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,34 @@ private static void ReplaceText(Paragraph p, WordprocessingDocument docx, Dictio
592592

593593
t.Remove();
594594
}
595+
else if (value is IEnumerable<MiniWordPicture> pictures)
596+
{
597+
// 新增一个标签插入图片集合
598+
foreach (var pic in pictures)
599+
{
600+
byte[] l_Data = null;
601+
if (pic.Path != null) l_Data = File.ReadAllBytes(pic.Path);
602+
if (pic.Bytes != null) l_Data = pic.Bytes;
603+
604+
var mainPart = docx.MainDocumentPart;
605+
var imagePart = mainPart.AddImagePart(pic.GetImagePartType);
606+
using (var stream = new MemoryStream(l_Data))
607+
{
608+
imagePart.FeedData(stream);
609+
if (pic.WrappingType == MiniWordPictureWrappingType.Anchor)
610+
{
611+
AddPictureAnchor(run, mainPart.GetIdOfPart(imagePart), pic);
612+
}
613+
else
614+
{
615+
AddPicture(run, mainPart.GetIdOfPart(imagePart), pic);
616+
}
617+
// 每个图片不换行
618+
run.Append(new Text(" "));
619+
}
620+
}
621+
t.Remove();
622+
}
595623
else if (value is MiniWordPicture)
596624
{
597625
var pic = (MiniWordPicture)value;

0 commit comments

Comments
 (0)