Skip to content

Commit bf0bc96

Browse files
JIAMing12gitee-org
authored andcommitted
update src/MiniWord/MiniWord.Implment.cs.
新增一个标签支持插入多个图片 Signed-off-by: JIAMing12 <2237013359@qq.com>
1 parent 1c03ecf commit bf0bc96

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

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)