Unity C# Aspose.words的使用

一、

二、

三、

四、邮件合并(填写域)

4.1. 文本域填写

实例代码

string tempFile = Application.streamingAssetsPath +"\\Templates\\template.doc"string[] fieldNames = { "ID" }; 			//域名
string[] values = { "5" };      			/Document doc = new Document(tempFile);
doc.MailMerge.Execute(fieldNames, values);
doc.Save(Application.persistentDataPath + "\\Export\\out.doc");
4.2. 图像域填写

五、 打印机

5.1. 使用默认打印机打印

实例代码

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");

// 1 - 使用默认打印机打印:
doc.Print();
5.2. 使用指定打印机打印

实例代码

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Hello world!");

// 2 - 按名称指定我们希望打印文档的打印机:
string myPrinter = PrinterSettings.InstalledPrinters[4];
doc.Print(myPrinter);
5.3. 获取打印机列表

实例代码

foreach (string printer in PrinterSettings.InstalledPrinters)
{
	Debug.Log(index +":"+printer);
    index++;
 }
5.4. Unity遇到的错误
  • 错误描述:
    无法调用Print或带参数的Print方法。
  • 错误提示:
    OutOfMemoryException: Not enough memory to complete operation [GDI+ status: OutOfMemory] System.Drawing.GDIPlus.CheckStatus (System.Drawing.Status status) (at <7026bacc22c446e78b11ff130428baf7>:0) System.Drawing.Graphics.FromHdc (System.IntPtr hdc) (at <7026bacc22c446e78b11ff130428baf7>:0) System.Drawing.Printing.PrintDocument.Print () (at <7026bacc22c446e78b11ff130428baf7>:0) (wrapper remoting-invoke-with-check) System.Drawing.Printing.PrintDocument.Print() Aspose.Words.Document.Print (System.Drawing.Printing.PrinterSettings printerSettings, System.String documentName) (at <4d44192afd6745cb0e8eaf873e4443ac>:0) Aspose.Words.Document.Print (System.Drawing.Printing.PrinterSettings printerSettings) (at <4d44192afd6745cb0e8eaf873e4443ac>:0) Aspose.Words.Document.Print () (at <4d44192afd6745cb0e8eaf873e4443ac>:0)
  • 造成原因:
    缺少System.Drawing.dll
  • 解决办法:
    当前Unity版本编辑器下的System.Drawing.dll导入到Asserts中。

六、 Unity发布

6.4 Unity遇到的错误
  • 错误描述
    在unity Editor中正常运行,发布后提示错误。
  • 错误提示:
    NullReferenceException: Object reference not set to an instance of an object
    Rethrow as FileCorruptedException: The document appears to be corrupted and cannot be loaded.
  • 错误原因:
    缺少依赖包。
  • 解决办法:
  1. 首先确定ProjectSetting -> Player -> Other Settings -> Api Compatibility Level。
  2. 查找在Editor安装路径的对应库(I18N.*Aspose.word.dllSystem.Drawing.dll):
    .NET Standard 2.0:\Editor\Data\MonoBleedingEdge\lib\mono\2.0-api
    .NET 4.x:\Editor\Data\MonoBleedingEdge\lib\mono\4.5
  3. 其中 .NET Standard2.0 的System.Drawing.dll在使用过程中有点局限,支持不太好。
  4. 参考文章:https://blog.csdn.net/qq_37484084/article/details/126000485
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值