美文网首页Unity跨平台技术分享
unity 选择系统路径并导出excel

unity 选择系统路径并导出excel

作者: _Bob_ | 来源:发表于2019-06-25 11:37 被阅读0次

    首先,网上一搜一大堆,但是大多都千篇一律不实用,本文章主要实现功能,将数据存储为excel,选择系统另存为路径,导出excel。

    该功能都实现在一个脚本之内,首先需要引用以下内容:

    需引用内容

    接下来需要实现3个类,首先是数据接收类

    [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;

    }

    接下来是系统函数调用类

    public class LocalDialog

    {

        //链接指定系统函数 打开文件对话框

        [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]

        public static extern bool GetOpenFileName([In, Out] OpenFileName ofn);

        public static bool GetOFN([In, Out] OpenFileName ofn)

        {

            return GetOpenFileName(ofn);

        }

        //链接指定系统函数 另存为对话框

        [DllImport("Comdlg32.dll", SetLastError = true, ThrowOnUnmappableChar = true, CharSet = CharSet.Auto)]

        public static extern bool GetSaveFileName([In, Out] OpenFileName ofn);

        public static bool GetSFN([In,Out] OpenFileName ofn)

        {

            return GetSaveFileName(ofn);

        }

    }

    最后是讲数据写入文件并存成excel,同时存入后还会打开存入的文件夹可以直接查看

    写入excel 并导出

    需要注意的是写excel需要 EPPlus.dll;

    这个网上有很多,随便下一个就哦了

    相关文章

      网友评论

        本文标题:unity 选择系统路径并导出excel

        本文链接:https://www.haomeiwen.com/subject/awqtcctx.html