From b01e2aa84e1b95b4af5188693f1a0881ea7f13a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=AF=85=E5=BD=AC?= <1759414356@qq.com> Date: Tue, 10 Feb 2026 12:16:06 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=89=A9=E5=B1=95=E6=B8=B2=E6=9F=93table?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=8D=95=E5=85=83=E6=A0=BC=E6=B8=B2=E6=9F=93?= =?UTF-8?q?=EF=BC=8C=E5=8D=95=E5=85=83=E6=A0=BC=E6=A8=A1=E6=9D=BF{{}}?= =?UTF-8?q?=E5=8F=AA=E6=9C=89=E4=B8=80=E4=B8=AA=E7=9A=84=E6=97=B6list?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E6=B8=B2=E6=9F=93=E6=AF=8F=E4=B8=AA=E5=8D=95?= =?UTF-8?q?=E5=85=83=E6=A0=BC=EF=BC=8C=E8=B6=85=E8=BF=87=E4=B8=80=E4=B8=AA?= =?UTF-8?q?=E6=97=B6=E6=B8=B2=E6=9F=93=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniWord/MiniWord.Implment.cs | 52 ++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/src/MiniWord/MiniWord.Implment.cs b/src/MiniWord/MiniWord.Implment.cs index 6e48862..af712c7 100644 --- a/src/MiniWord/MiniWord.Implment.cs +++ b/src/MiniWord/MiniWord.Implment.cs @@ -81,6 +81,7 @@ private static void Generate(this OpenXmlElement xmlElement, WordprocessingDocum ReplaceText(xmlElement, docx, tags); } + /// /// 渲染Table /// @@ -91,6 +92,9 @@ private static void Generate(this OpenXmlElement xmlElement, WordprocessingDocum private static void GenerateTable(Table table, WordprocessingDocument docx, Dictionary tags) { var trs = table.Descendants().ToArray(); // remember toarray or system will loop OOM; + var regexStr = "(?<={{).*?\\..*?(?=}})"; + //计算是否只有一个cell存在指令,如果超过1个则纵向渲染,否则横向渲染。 + bool isHorizontal = table.Elements().SelectMany(s => s.Elements()).Count(w => Regex.Matches(w.InnerText, regexStr).Count > 0) <= 1; foreach (var tr in trs) { @@ -98,8 +102,9 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict .Replace("{{if(", "").Replace(")if", "").Replace("endif}}", ""); // 匹配list数据,格式“Items.PropName” - var matchs = (Regex.Matches(innerText, "(?<={{).*?\\..*?(?=}})") + var matchs = (Regex.Matches(innerText, regexStr) .Cast().GroupBy(x => x.Value).Select(varGroup => varGroup.First().Value)).ToArray(); + if (matchs.Length > 0) { //var listKeys = matchs.Select(s => s.Split('.')[0]).Distinct().ToArray(); @@ -124,12 +129,17 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict var attributeKey = matchs[0].Split('.')[0]; var list = tagObj as IEnumerable; + int num = tr.Elements().Count(); + int index = 0; + List elementList = new List(); + + foreach (var item in list) { var dic = new Dictionary(); //TODO: optimize - var newTr = tr.CloneNode(true); + if (item is IDictionary) { var es = (Dictionary)item; @@ -153,16 +163,43 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict ReplaceIfStatements(newTr, tags: dic); ReplaceText(newTr, docx, tags: dic); - //Fix #47 The table should be inserted at the template tag position instead of the last row - if (table.Contains(tr)) + + if (isHorizontal) { - table.InsertBefore(newTr, tr); + var newTable = newTr.Descendants().FirstOrDefault(); + if (newTable != null) + elementList.Add(newTable.CloneNode(true)); + + if (index > 0 && (index + 1) % num == 0 && elementList.Count > 0) + { + var templateTr = tr.CloneNode(true); + for (var i = 0; i < elementList.Count; i++) + { + var tCell = templateTr.Elements().ToList()[i]; + + tCell.RemoveAllChildren(); + tCell.Append(elementList[i]); + } + newTr = templateTr; + elementList = new List(); + + table.Append(newTr); + } } else { - // If it is a nested table, temporarily append it to the end according to the original plan. - table.Append(newTr); + //Fix #47 The table should be inserted at the template tag position instead of the last row + if (table.Contains(tr)) + { + table.InsertBefore(newTr, tr); + } + else + { + // If it is a nested table, temporarily append it to the end according to the original plan. + table.Append(newTr); + } } + index++; } tr.Remove(); @@ -194,6 +231,7 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict } + /// /// 获取Obj对象指定的值 /// From aae9d7c6adc2061d8c737d845bf32fc2ec9b19e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=AF=85=E5=BD=AC?= <1759414356@qq.com> Date: Tue, 10 Feb 2026 17:48:55 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20=E5=BD=93=E6=B8=B2?= =?UTF-8?q?=E6=9F=93table=E6=97=B6=E4=BD=BF=E7=94=A8=20Descendants=20?= =?UTF-8?q?=E4=BC=9A=E8=87=AA=E5=8A=A8=E6=8F=90=E5=8F=96=E6=89=80=E6=9C=89?= =?UTF-8?q?=E7=9A=84tableRow,=E5=8C=85=E6=8B=AC=E5=B5=8C=E5=A5=97=E7=9A=84?= =?UTF-8?q?tableRow,=E6=94=B9=E7=94=A8Elements=EF=BC=8C=E5=8F=AA=E6=8F=90?= =?UTF-8?q?=E5=8F=96=E5=AD=90=E7=BA=A7=E7=9A=84tr=E3=80=82=20=E4=B8=8D?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=88=E6=9E=9C=E6=98=AF=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E5=A4=A7=E9=87=8F=E7=9A=84=E6=97=A0=E6=95=88tr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniWord/MiniWord.Implment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MiniWord/MiniWord.Implment.cs b/src/MiniWord/MiniWord.Implment.cs index af712c7..3a2fd02 100644 --- a/src/MiniWord/MiniWord.Implment.cs +++ b/src/MiniWord/MiniWord.Implment.cs @@ -91,7 +91,7 @@ private static void Generate(this OpenXmlElement xmlElement, WordprocessingDocum /// private static void GenerateTable(Table table, WordprocessingDocument docx, Dictionary tags) { - var trs = table.Descendants().ToArray(); // remember toarray or system will loop OOM; + var trs = table.Elements().ToArray(); // remember toarray or system will loop OOM; var regexStr = "(?<={{).*?\\..*?(?=}})"; //计算是否只有一个cell存在指令,如果超过1个则纵向渲染,否则横向渲染。 bool isHorizontal = table.Elements().SelectMany(s => s.Elements()).Count(w => Regex.Matches(w.InnerText, regexStr).Count > 0) <= 1; From 83afbe8c9d1fb76cff7ee66693a41c434506bc3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=AF=85=E5=BD=AC?= <1759414356@qq.com> Date: Tue, 10 Feb 2026 17:59:24 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dcell=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniWord/MiniWord.Implment.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/MiniWord/MiniWord.Implment.cs b/src/MiniWord/MiniWord.Implment.cs index 3a2fd02..05dd45e 100644 --- a/src/MiniWord/MiniWord.Implment.cs +++ b/src/MiniWord/MiniWord.Implment.cs @@ -94,7 +94,8 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict var trs = table.Elements().ToArray(); // remember toarray or system will loop OOM; var regexStr = "(?<={{).*?\\..*?(?=}})"; //计算是否只有一个cell存在指令,如果超过1个则纵向渲染,否则横向渲染。 - bool isHorizontal = table.Elements().SelectMany(s => s.Elements()).Count(w => Regex.Matches(w.InnerText, regexStr).Count > 0) <= 1; + var cellList = table.Elements().SelectMany(s => s.Elements()).ToList(); + bool isHorizontal = cellList.Count > 1 && cellList.Count(w => Regex.Matches(w.InnerText, regexStr).Count > 0) <= 1; foreach (var tr in trs) { From e3f758fcc3127f2bd12a6a6c73f22e577850f719 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=AF=85=E5=BD=AC?= <1759414356@qq.com> Date: Sat, 21 Mar 2026 10:42:19 +0800 Subject: [PATCH 4/5] 1 --- src/MiniWord/MiniWord.Implment.cs | 43 ++-- tests/MiniWordTests/MiniWordTest4MeAsync.cs | 242 ++++++++++++++++++++ 2 files changed, 268 insertions(+), 17 deletions(-) create mode 100644 tests/MiniWordTests/MiniWordTest4MeAsync.cs diff --git a/src/MiniWord/MiniWord.Implment.cs b/src/MiniWord/MiniWord.Implment.cs index 05dd45e..928b333 100644 --- a/src/MiniWord/MiniWord.Implment.cs +++ b/src/MiniWord/MiniWord.Implment.cs @@ -25,7 +25,7 @@ public static partial class MiniWord { private static void SaveAsByTemplateImpl(Stream stream, byte[] template, Dictionary data) { - SaveAsByTemplateImplAsync(stream,template,data).GetAwaiter().GetResult(); + SaveAsByTemplateImplAsync(stream, template, data).GetAwaiter().GetResult(); } private static async Task SaveAsByTemplateImplAsync(Stream stream, byte[] template, Dictionary data, CancellationToken token = default(CancellationToken)) @@ -133,7 +133,8 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict int num = tr.Elements().Count(); int index = 0; List elementList = new List(); - + int totalCount = list.Cast().Count(); + //int rowCount = (totalCount + num - 1) / (num == 0 ? 1 : num); // 计算总行数 foreach (var item in list) { @@ -171,7 +172,7 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict if (newTable != null) elementList.Add(newTable.CloneNode(true)); - if (index > 0 && (index + 1) % num == 0 && elementList.Count > 0) + if (index > 0 && ((index + 1) % num == 0 || (index == totalCount - 1)) && elementList.Count > 0) { var templateTr = tr.CloneNode(true); for (var i = 0; i < elementList.Count; i++) @@ -687,7 +688,7 @@ private static void ReplaceText(Paragraph p, WordprocessingDocument docx, Dictio { AddPicture(run, mainPart.GetIdOfPart(imagePart), pic); } - + } t.Remove(); @@ -1062,9 +1063,9 @@ private static void AddPicture(OpenXmlElement appendElement, string relationship new A.PresetGeometry( new A.AdjustValueList() ) - { Preset = A.ShapeTypeValues.Rectangle })) + { Preset = A.ShapeTypeValues.Rectangle })) ) - { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }) + { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }) ) { DistanceFromTop = (UInt32Value)0U, @@ -1082,22 +1083,30 @@ private static void AddPictureAnchor(OpenXmlElement appendElement, string relati DW.Anchor anchor3 = new DW.Anchor() { - DistanceFromTop = (UInt32Value)0U, DistanceFromBottom = (UInt32Value)0U, - DistanceFromLeft = (UInt32Value)114300U, DistanceFromRight = (UInt32Value)114300U, - SimplePos = false, RelativeHeight = (UInt32Value)0U, BehindDoc = pic.BehindDoc, Locked = false, - LayoutInCell = true, AllowOverlap = pic.AllowOverlap, EditId = "1EACBECC", AnchorId = "5AF073F3" + DistanceFromTop = (UInt32Value)0U, + DistanceFromBottom = (UInt32Value)0U, + DistanceFromLeft = (UInt32Value)114300U, + DistanceFromRight = (UInt32Value)114300U, + SimplePos = false, + RelativeHeight = (UInt32Value)0U, + BehindDoc = pic.BehindDoc, + Locked = false, + LayoutInCell = true, + AllowOverlap = pic.AllowOverlap, + EditId = "1EACBECC", + AnchorId = "5AF073F3" }; DW.SimplePosition simplePosition3 = new DW.SimplePosition() { X = 0L, Y = 0L }; DW.HorizontalPosition horizontalPosition3 = new DW.HorizontalPosition() - { RelativeFrom = DW.HorizontalRelativePositionValues.Column }; + { RelativeFrom = DW.HorizontalRelativePositionValues.Column }; DW.PositionOffset positionOffset5 = new DW.PositionOffset(); positionOffset5.Text = $"{pic.HorizontalPositionOffset * 9525}"; horizontalPosition3.Append(positionOffset5); DW.VerticalPosition verticalPosition3 = new DW.VerticalPosition() - { RelativeFrom = DW.VerticalRelativePositionValues.Paragraph }; + { RelativeFrom = DW.VerticalRelativePositionValues.Paragraph }; DW.PositionOffset positionOffset6 = new DW.PositionOffset(); positionOffset6.Text = $"{pic.VerticalPositionOffset * 9525}"; @@ -1106,12 +1115,12 @@ private static void AddPictureAnchor(OpenXmlElement appendElement, string relati DW.EffectExtent effectExtent13 = new DW.EffectExtent() - { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }; + { LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L }; DW.WrapNone wrapNone3 = new DW.WrapNone(); DW.DocProperties docProperties13 = new DW.DocProperties() - { Id = (UInt32Value)774829591U, Name = $"Picture {Guid.NewGuid().ToString()}" }; + { Id = (UInt32Value)774829591U, Name = $"Picture {Guid.NewGuid().ToString()}" }; DW.NonVisualGraphicFrameDrawingProperties nonVisualGraphicFrameDrawingProperties13 = new DW.NonVisualGraphicFrameDrawingProperties(); @@ -1126,14 +1135,14 @@ private static void AddPictureAnchor(OpenXmlElement appendElement, string relati graphic13.AddNamespaceDeclaration("a", "http://schemas.openxmlformats.org/drawingml/2006/main"); A.GraphicData graphicData13 = new A.GraphicData() - { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }; + { Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture" }; PIC.Picture picture13 = new PIC.Picture(); picture13.AddNamespaceDeclaration("pic", "http://schemas.openxmlformats.org/drawingml/2006/picture"); PIC.NonVisualPictureProperties nonVisualPictureProperties13 = new PIC.NonVisualPictureProperties(); PIC.NonVisualDrawingProperties nonVisualDrawingProperties13 = new PIC.NonVisualDrawingProperties() - { Id = (UInt32Value)0U, Name = $"Image {Guid.NewGuid().ToString()}.{pic.Extension}" }; + { Id = (UInt32Value)0U, Name = $"Image {Guid.NewGuid().ToString()}.{pic.Extension}" }; PIC.NonVisualPictureDrawingProperties nonVisualPictureDrawingProperties13 = new PIC.NonVisualPictureDrawingProperties(); @@ -1143,7 +1152,7 @@ private static void AddPictureAnchor(OpenXmlElement appendElement, string relati PIC.BlipFill blipFill13 = new PIC.BlipFill(); A.Blip blip13 = new A.Blip() - { Embed = relationshipId, CompressionState = A.BlipCompressionValues.Print }; + { Embed = relationshipId, CompressionState = A.BlipCompressionValues.Print }; A.BlipExtensionList blipExtensionList11 = new A.BlipExtensionList(); A.BlipExtension blipExtension11 = new A.BlipExtension() { Uri = $"{{{Guid.NewGuid().ToString("n")}}}" }; diff --git a/tests/MiniWordTests/MiniWordTest4MeAsync.cs b/tests/MiniWordTests/MiniWordTest4MeAsync.cs new file mode 100644 index 0000000..e5296e4 --- /dev/null +++ b/tests/MiniWordTests/MiniWordTest4MeAsync.cs @@ -0,0 +1,242 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; +using DocumentFormat.OpenXml.Office2010.ExcelAc; +using MiniSoftware; +using Xunit; + +namespace MiniWordTests; + +public class MiniWordTest4MeAsync +{ + [Fact] + public async void TestForeachLoopInTablesAsync() + { + var path = "C:\\Users\\Administrator\\Downloads\\";// PathHelper.GetTempFilePath(); + var templatePath = "D:\\工作文档\\毅智科技\\导出模板\\信息标签模板A4_2.docx";//PathHelper.GetFile("TestForeachInTablesDemo.docx"); + + + var list = new List>(); + + foreach (var i in Enumerable.Range(1, 8)) + { + var values = new Dictionary() + { + ["u:name"] = "李哈哈" + i, + ["u:sex"] = "男", + ["r:userGroupParentName"] = "广州人才凯盛幼儿园", + ["r:userGroupName"] = $"大{i}班", + ["e:2613220640424581"] = i % 2 == 0 ? "男" : "女", + ["e:2613186883781253"] = i % 2 == 0 ? "5" : "6", + ["u:months"] = i, + ["e:2660464484401477"] = i, + ["s:2642862487273797"] = "维生素D", + ["s:2642861958398277"] = "乙肝两对半", + ["s:2642862864793925"] = "铁蛋白", + + ["qc1"] = "sdsdfds", + }; + list.Add(values); + } + + var value = new Dictionary(); + value["list"] = list; + + + await MiniWord.SaveAsByTemplateAsync(path + DateTime.Now.ToFileTimeUtc() + ".docx", templatePath, value); + //System.Diagnostics.Process.Start("explorer.exe", path); + //var xml = Helpers.GetZipFileContent(path + DateTime.Now.ToFileTimeUtc() + ".docx", "word/document.xml"); + //Assert.Contains(@"Discussion requirement part2 and development", xml); + //Assert.Contains(@"Discussion requirement part1", xml); + //Assert.Contains( + // "Air way to the Airplane | Parking way to the Car / Hotel way to the Room, Food way to the Plate", xml); + } + + [Fact] + public async void TestForeachLoopInTables2Async() + { + + string path = "D:\\工作文档\\毅智科技\\导出模板\\3-6岁体检表2026_列表.docx"; + string outputPath = "C:\\Users\\Administrator\\Downloads\\"; + List streamList = new List(); + List> valueList = new List>(); + byte[] buffer = File.ReadAllBytes("C:\\Users\\Administrator\\Downloads\\qcode.png"); + + foreach (var index in Enumerable.Range(1, 6)) + { + var values = new Dictionary() + { + ["u:name"] = "李哈哈_" + index, + ["u:sex"] = "男", + ["r:userGroupParentName"] = "广州人才凯盛幼儿园", + ["r:userGroupName"] = "大一班", + ["u:sex"] = "男", + ["u:age"] = "5", + ["u:months"] = "4", + ["e:ti200020"] = "110", + ["s:2642862487273797"] = "维生素D", + ["s:ei100008"] = "乙肝两对半", + ["s:ei100009"] = "铁蛋白", + ["qc1"] = new MiniSoftware.MiniWordPicture(buffer, MiniSoftware.Common.Enums.Extension.Png, 50, 50) + }; + //MemoryStream stream = new MemoryStream(); + //await MiniSoftware.MiniWord.SaveAsByTemplateAsync(stream, path, values); + //streamList.Add(stream); + valueList.Add(values); + }; + Dictionary listData = new Dictionary() + { + }; + listData["list"] = valueList; + MemoryStream stream = new MemoryStream(); + await MiniSoftware.MiniWord.SaveAsByTemplateAsync(outputPath + (DateTime.Now.ToFileTimeUtc()) + ".docx", path, listData); + } + + [Fact] + public async void MiniWordIfStatement_FirstIfAsync() + { + var path = PathHelper.GetTempFilePath(); + var templatePath = PathHelper.GetFile("TestIfStatement.docx"); + var value = new Dictionary() + { + ["Name"] = new List(){ + new MiniWordHyperLink(){ + Url = "https://google.com", + Text = "測試連結22!!" + }, + new MiniWordHyperLink(){ + Url = "https://google1.com", + Text = "測試連結11!!" + } + }, + ["Company_Name"] = "MiniSofteware", + ["CreateDate"] = new DateTime(2021, 01, 01), + ["VIP"] = true, + ["Points"] = 123, + ["APP"] = "Demo APP", + }; + await MiniWord.SaveAsByTemplateAsync(path, templatePath, value); + //Console.WriteLine(path); + var docXml = Helpers.GetZipFileContent(path, "word/document.xml"); + Assert.Contains("First if chosen: MiniSofteware", docXml); + Assert.DoesNotContain("Second if chosen: MaxiSoftware", docXml); + Assert.Contains("Points are greater than 100", docXml); + Assert.Contains("CreateDate is not less than 2021", docXml); + Assert.DoesNotContain("CreateDate is not greater than 2021", docXml); + } + + [Fact] + public async void TestForeachLoopInTablesWithIfStatementAsync() + { + var path = PathHelper.GetTempFilePath(); + var templatePath = PathHelper.GetFile("TestForeachInTablesWithIfStatementDemo.docx"); + var value = new Dictionary() + { + ["TripHs"] = new List> + { + new Dictionary + { + { "sDate", DateTime.Parse("2022-09-08 08:30:00") }, + { "eDate", DateTime.Parse("2022-09-08 15:00:00") }, + { "How", "Discussion requirement part1" }, + { + "Details", new List() + { + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Air"}, + {"Value", "Airplane"} + }, + Separator = " | " + }, + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Parking"}, + {"Value", "Car"} + }, + Separator = " / " + }, + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Hotel"}, + {"Value", "Room"} + }, + Separator = ", " + }, + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Food"}, + {"Value", "Plate"} + }, + Separator = "" + } + } + } + }, + new Dictionary + { + { "sDate", DateTime.Parse("2022-09-09 08:30:00") }, + { "eDate", DateTime.Parse("2022-09-09 17:00:00") }, + { "How", "Discussion requirement part2 and development" }, + { + "Details", new List() + { + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Air"}, + {"Value", "Airplane"} + }, + Separator = " | " + }, + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Parking"}, + {"Value", "Car"} + }, + Separator = " / " + }, + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Hotel"}, + {"Value", "Room"} + }, + Separator = ", " + }, + new MiniWordForeach() + { + Value = new Dictionary() + { + {"Text", "Food"}, + {"Value", "Plate"} + }, + Separator = "" + } + } + } + } + } + }; + await MiniWord.SaveAsByTemplateAsync(path, templatePath, value); + //System.Diagnostics.Process.Start("explorer.exe", path); + var xml = Helpers.GetZipFileContent(path, "word/document.xml"); + Assert.Contains(@"Discussion requirement part2 and development", xml); + Assert.Contains(@"Discussion requirement part1", xml); + Assert.Contains("Air way to the Airplane | Hotel way to the Room", xml); + } +} \ No newline at end of file From 2b87e977b6179c27f24f6e014848f1be2754cbe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=AF=85=E5=BD=AC?= <1759414356@qq.com> Date: Sat, 21 Mar 2026 10:44:35 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=B8=B2=E6=9F=93table?= =?UTF-8?q?=E4=B8=8D=E6=BB=A1=E8=A1=8C=E6=97=B6=E6=BC=8F=E8=A1=8Cbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/MiniWord/MiniWord.Implment.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MiniWord/MiniWord.Implment.cs b/src/MiniWord/MiniWord.Implment.cs index 928b333..a99bf8d 100644 --- a/src/MiniWord/MiniWord.Implment.cs +++ b/src/MiniWord/MiniWord.Implment.cs @@ -139,7 +139,7 @@ private static void GenerateTable(Table table, WordprocessingDocument docx, Dict foreach (var item in list) { var dic = new Dictionary(); //TODO: optimize - + var newTr = tr.CloneNode(true); if (item is IDictionary)