Unity C# GetSaveFileName()的应用
本文原创,转载请注明出处:http://www.cnblogs.com/AdvancePikachu/p/6944870.html
唉哟,这次厉害咯,网上搜罗了好久,终于被我找到汉化的保存对话框了,根据网上的一些前辈总结的内容,做了一些修改,
先放个效果图:
首先需要定义一个OpenFileName的类:
- [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
- public class OpenFileName
- {
- public int structSize = 0;
- public IntPtr dlgOwner = IntPtr.Zero;
- public IntPtr instance = IntPtr.Zero;
- public String filter = null;
- public String customFilter = null;
- public int maxCustFilter = 0;
- public int filterIndex = 0;
- public String file = null;
- public int maxFile = 0;
- public String fileTitle = null;
- public int maxFileTitle = 0;
- public String initialDir = null;
- public String title = null;
- public int flags = 0;
- public short fileOffset = 0;
- public short fileExtension = 0;
- public String defExt = null;
- public IntPtr custData = IntPtr.Zero;
- public IntPtr hook = IntPtr.Zero;
- public String templateName = null;
- public IntPtr reservedPtr = IntPtr.Zero;
- public int reservedInt = 0;
- public int flagsEx = 0;
- }
当然,也不是都用到了,只用到了一小部分,有性趣的童鞋可以个性化一下保存对话框,
然后是最重要的委托GetSaveName()方法:
- public class DllTest
- {
- [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]
- public static extern bool GetSaveFileName([In, Out] OpenFileName ofn);
- }
挡挡挡,最后调用一下即可:
- public static void OpenDialog(Action<Stream> onSave)
- {
- OpenFileName ofn = new OpenFileName();
- ofn.structSize = Marshal.SizeOf(ofn);
- ofn.filter = "Excel (*.xls)\0*.xls\0\0";
- ofn.file = new string(new char[]);
- ofn.maxFile = ofn.file.Length;
- ofn.fileTitle = new string(new char[]);
- ofn.maxFileTitle = ofn.fileTitle.Length;
- ofn.initialDir = UnityEngine.Application.dataPath;//默认路径
- ofn.title = "保存文件";
- ofn.defExt = ".xls";//显示文件的类型
- ofn.flags = 0x00080000 | 0x00001000 | 0x00000800 | 0x00000200 | 0x00000008;
- if (DllTest.GetSaveFileName(ofn))
- {
- dosomething();
- string Savepath = Path.GetDirectoryName (ofn.file);
- Process.Start (Savepath);
- }
- }
终于搞定保存对话框汉化了,5555,也是不容易啊!
那位小伙伴有更好的方法希望可以分享给我啊!
2017/12/27
前两天同时使用的时候遇到很多问题,原因是封装的不太好,而且也没有注释,逻辑提供不全,今天把完整的代码贴上来,最近比较忙,等空闲了再整理下
首先是调用OpenDialog的方法
- void save()
- {
- SaveDialog.OpenDialog (saveExcel);
- }
- public void saveExcel(Stream s)
- {
- //excell的逻辑
- ExcelWrite ew = new ExcelWrite ();
- ew.WriteToStream (s);
- }
然后是 ExcelWrite.cs
- public void WriteToStream(Stream s)
- {
- IWorkbook workbook = new HSSFWorkbook ();
- ISheet sheet = workbook.CreateSheet ();
- IRow row = sheet.CreateRow (0);//参数0表示第0行
- string[] firstRow = new string[]
- {
- "ID",
- "性别",
- "博客"
- };
- for (int i = 0; i < firstRow.Length; i++)
- {
- ICell cell = row.CreateCell (i);
- cell.SetCellValue (firstRow [i]);
- }
- IRow row2 = sheet.CreateRow (1);
- string[] secondRow = new string[]
- {
- "AdvancePikachu",
- "男",
- "http://www.cnblogs.com/AdvancePikachu/"
- };
- for (int i = 0; i < secondRow.Length; i++)
- {
- ICell cell = row2.CreateCell (i);
- cell.SetCellValue (secondRow [i]);
- }
- workbook.Write (s);
- }
这个excel用的是NPOI写的,效果挺好的,最后附上demo实例,欢迎各路大神提供更好的思路!
- Test
Unity C# GetSaveFileName()的应用的更多相关文章
- Unity C# 运用 GetSaveFileName() 导出Excel文件
本文原创,转载请注明出处:http://www.cnblogs.com/AdvancePikachu/p/6944870.html 唉哟,这次厉害咯,网上搜罗了好久,终于被我找到汉化的保存对话框了,根 ...
- unity 实现调用Windows窗口/对话框交互
Unity调用Window窗口 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...
- Unity 3D调用Windows打开、保存窗口、文件浏览器
Unity调用Window窗口 本文提供全流程,中文翻译. Chinar 坚持将简单的生活方式,带给世人!(拥有更好的阅读体验 -- 高分辨率用户请根据需求调整网页缩放比例) Chinar -- 心分 ...
- Unity中调用Windows窗口句柄以及根据需求设置并且解决扩展屏窗体显示错乱/位置错误的Bug
问题背景: 现在在搞PC端应用开发,我们开发中需要调用系统的窗口以及需要最大化最小化,缩放窗口拖拽窗口,以及设置窗口位置,去边框等功能 解决根据: 使用user32.dll解决 具体功能: Unity ...
- Unity3d入门 - 关于unity工具的熟悉
上周由于工作内容较多,花在unity上学习的时间不多,但总归还是学习了一些东西,内容如下: .1 根据相关的教程在mac上安装了unity. .2 学习了unity的主要的工具分布和对应工具的相关的功 ...
- 聊聊Unity项目管理的那些事:Git-flow和Unity
0x00 前言 目前所在的团队实行敏捷开发已经有了一段时间了.敏捷开发中重要的一个话题便是如何对项目进行恰当的版本管理.项目从最初使用svn到之后的Git One Track策略再到现在的GitFlo ...
- Unity游戏内版本更新
最近研究了一下游戏内apk包更新的方法. ios对于应用的管理比较严格,除非热更新脚本,不太可能做到端内大版本包的更新.然而安卓端则没有此限制.因此可以做到不跳到网页或应用商店,就覆盖更新apk包. ...
- Unity 序列化
Script Serialization http://docs.unity3d.com/Manual/script-Serialization.html 自定义序列化及例子: http://docs ...
- Unity 序列化 总结
查找了 Script Serialization http://docs.unity3d.com/Manual/script-Serialization.html 自定义序列化及例子: http:// ...
随机推荐
- IE和其他浏览器用JS新窗口打开的问题
Chrome中 window.open(pageURL,name,parameters) pageURL 为子窗口路径 name 为子窗口句柄 parameters 为窗口参数(各参数用逗号分隔) 例 ...
- [编织消息框架][传输协议]stcp简单开发
测试代码 public class ServerSTCP { static int SERVER_PORT = 3456; static int US_STREAM = 0; static int F ...
- bootstrap快速入门笔记(四)-less用法指南, mixin和变量
一,less变量,less文件 1.bootstrap.less 这是主要的 Less 文件.该文件中导入了一些其他的 less 文件.该文件中没有任何代码. 2.forms.less 这个 Less ...
- PPT制作线条动画
0.小叙闲言 今天在用PPT做动画的时候小有心得,百度了一下线条动画制作,有一个贴子里面的讨论,也给了我一些灵感,贴子地址:http://www.rapidbbs.cn/thread-24577-1- ...
- 简单的jquery左侧导航栏和页面选中效果
这里是要实现导航的左侧并选中的,此功能需引用jquery 效果: 左侧导航 <div class="box"> <ul class="menu" ...
- DirectFB 之 环境配置
1. 准备 directFB下载地址:http://www.directfb.org/index.php?path=Main%2FDownloads 本人采用的版本是DirectFB-1.5.3.ta ...
- JAVA中令人疑惑的字符串
Java中不同的字符串存在于同一个存储池中,字符串变量将指向存储池中相应的位置,也就是字符串变量里面包含的并不是字符串而是这个字符串对象的内存地址. String a = "123" ...
- 记录——excel导出lua工具(python实现)
项目需要一个从excel导出lua配置表的工具,之前的工具是主程写的,效率极差,i7 CPU 一次全部导出要花掉1个多小时.匪夷所思的是,这么渣的效率,居然用了整整一年.当 然,中途有人反映效率差,主 ...
- linux-redhat-iso 下载
http://archive.download.redhat.com/pub/redhat/linux/9/en/iso/i386/ http://www.jb51.net/do/plus/downl ...
- Python基本语法--语句
# -*- coding: utf-8 -*- #条件语句 ''' if 判断条件: 执行语句…… else: 执行语句…… ''' flag = False name = 'python' if n ...