using Aspose.Words; using Aspose.Words.Replacing; using QFramework; using System.IO; using UnityEngine; using System.Windows.Forms; using Newtonsoft.Json.Linq; using System; public class AsposeHelper : MonoBehaviour { public static void Writer(string json, Action callback = null) { // 加载Word文档 Document doc = new Document(Global.reportDemoPath); JObject jObject = JObject.Parse(json); foreach (JProperty property in jObject.Properties()) { string key = property.Name; string value = property.Value.ToString(); doc.Range.Replace($"{{{key}}}", $"{value}", new FindReplaceOptions()); } // 替换文本 SaveWithDialog(doc, callback); //Debug.Log("文档处理完成,新文档已保存到: " + outputFilePath); } private static void SaveWithDialog(Document doc, Action callback) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Word文档|*.docx"; var result = dialog.ShowDialog(); if (result == DialogResult.OK) { doc.Save(dialog.FileName); } callback?.Invoke(result); } }