|
|
Chinar 教程效果:
1
Print Excel —— 打印表格
Unity 调用系统进程,可直接调用外部程序 Excel 进行打印操作
会直接在目标路径下生成对应的 PDF 文件
另外 Verb 还有其他命令: new / edit / open / print / run / run as 分别执行不同操作
using System.Diagnostics;using UnityEngine;////// 打印Excel表格类/// public class ChinarPrint : MonoBehaviour{ private void OnGUI() { if (!GUI.Button(new Rect((Screen.width - 200) / 2, (Screen.height - 200) / 2, 200, 200), "Print Excel")) return; #region 查看Verb //查看对应扩展名的程序,所支持的Verb字符串 命令 //ProcessStartInfo psi = new ProcessStartInfo(Application.dataPath + "/Chinar-TestPrintExcel.xlsx");//这里传一个带扩展名文件的 文件路径 //foreach (var s in psi.Verbs) //{ // print(s); //} #endregion System.Diagnostics.Process process = new System.Diagnostics.Process //系统进程 { //StartInfo的属性成员FileName 表示需要启动的进程,可以被设置成可执行文件,也可以被设置成其扩展名已经与系统上安装的应用程序关联的任何文件类型。本例中FileName 就被设置成pdf文件,这样调用Start()方法启动进程时,便会去启动本机已经安装的且与pdf文件相关联的默认打开程序(本机为Adobe Reader程序)。 // StartInfo = { FileName = Application.dataPath + "/Chinar-TestPrintExcel.xlsx", //要打印的文件路径 CreateNoWindow = true, //不显示调用程序窗口 WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden, //设置窗口状态,最大、最小化 UseShellExecute = true, //使用设定命令执行 Verb = "print" //指定执行的动作,打印:print 打开:open ………… } }; process.Start(); //开始打印 }}
2
Open .Bat File —— 打开 .bat 文件
Unity 调用外部程序打开.bat 文件流程比较繁琐
这里 Chinar 提供一个简单的方式
用记事本打开你需要操作的 .bat 文件
在第一行加上: cd /D %~dp0
Application.OpenURL(文件路径)
直接打开 .bat 文件 using UnityEngine;////// public class ChinarOpenBat : MonoBehaviour{ private void OnGUI() { if (!GUI.Button(new Rect((Screen.width - 200) / 2, (Screen.height - 200) / 2, 200, 200), "Run Bat")) return; Application.OpenURL(Application.streamingAssetsPath.Replace("StreamingAssets", "ChinarDemo/StreamingAssets") + "/BatFile.bat");//传入路径即可 }}作用:打开.bat文件 ///作者:Chinar ///创建日期:2018-08-5 ///
支持
May Be —— 搞开发,总有一天要做的事!
|
本博客为非营利性个人原创,除部分有明确署名的作品外,所刊登的所有作品的著作权均为本人所拥有,本人保留所有法定权利。违者必究 对于需要复制、转载、链接和传播博客文章或内容的,请及时和本博主进行联系,留言,Email: ichinar@icloud.com 对于经本博主明确授权和许可使用文章及内容的,使用时请注明文章或内容出处并注明网址