新增PC端实验报告导出功能

This commit is contained in:
shenjianxing 2025-02-27 19:15:03 +08:00
parent ad1dd6f480
commit afc63ea87c
8 changed files with 148 additions and 7 deletions

Binary file not shown.

View File

@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: ba16243601d48674bbd94478034635d0
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,33 @@
fileFormatVersion: 2
guid: 82549cd4bc10d654d876aaf0f7f4b64d
PluginImporter:
externalObjects: {}
serializedVersion: 2
iconMap: {}
executionOrder: {}
defineConstraints: []
isPreloaded: 0
isOverridable: 0
isExplicitlyReferenced: 0
validateReferences: 1
platformData:
- first:
Any:
second:
enabled: 1
settings: {}
- first:
Editor: Editor
second:
enabled: 0
settings:
DefaultValueInitialized: true
- first:
Windows Store Apps: WindowsStoreApps
second:
enabled: 0
settings:
CPU: AnyCPU
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6bb2448096f447040ac74cd700f14893
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,47 @@
using Aspose.Words;
using Aspose.Words.Replacing;
using QFramework;
using System.IO;
using UnityEngine;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
public class AsposeHelper : MonoBehaviour
{
public static void Writer(string json)
{
// 加载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);
//Debug.Log("文档处理完成,新文档已保存到: " + outputFilePath);
}
private static void SaveWithDialog(Document doc)
{
SaveFileDialog dialog = new SaveFileDialog();
dialog.Filter = "Word文档|*.docx";
if (dialog.ShowDialog() == DialogResult.OK)
{
doc.Save(dialog.FileName);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7f42727d4b91acc4e938a10542fba938
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -22,27 +22,36 @@ namespace QFramework.Example
}
#if UNITY_WEBGL
ResLoader loader = ResLoader.Allocate();
loader.Add2Load(Global.reportDemoPath.ToLocalBytesResName(), (success, res) =>
{
if (success)
{
byte[] bytes = res.As<LocalBytesRes>().bytes;
var data = new LabReprotData();
data.realname = InputName.text;
data.biaobencaiji_1_buzhou_1 = "[1111]";
string json = JsonConvert.SerializeObject(data);
#if UNITY_WEBGL
WebGLDownLoadFile.Instance.DownloadDocx(bytes, json);
#endif
WebGLDownLoadFile.Instance.DownloadDocx(bytes, GetScoreDataJson());
}
});
loader.LoadAsync();
#elif UNITY_STANDALONE_WIN
AsposeHelper.Writer(GetScoreDataJson());
#endif
});
Confirm.onClick.AddListener(Hide);
}
public string GetScoreDataJson()
{
var data = new LabReprotData();
data.realname = InputName.text;
data.biaobencaiji_1_buzhou_1 = "[1111]";
string json = JsonConvert.SerializeObject(data);
return json;
}
protected override void OnOpen(IUIData uiData = null)