示例#1
0
        void ExcelToJSON()
        {
            //如果存在导出目录,则创建
            if (!Directory.Exists(OutPath.Text))
            {
                Directory.CreateDirectory(OutPath.Text);
            }
            if (ExcelFileList.Items.Count <= 0)
            {
                SearchExcelFileAdd("ExcelPath");
            }
            for (int i = 0; i < ExcelFileList.Items.Count; i++)
            {
                JArray arr = new JArray();
                arr = ExcelUtility.ExcelSingleSheetToJson(ExcelFileList.Items[i].ToString().Replace("\\", "/"), ToError);
                //如果没有值,则不做操作
                if (!arr.HasValues)
                {
                    return;
                }

                string fileName = Path.GetFileName(ExcelFileList.Items[i].ToString());

                fileName = fileName.Split('.')[0];
                fileName = OutPath.Text + fileName + ".json";
                if (File.Exists(fileName))
                {
                    File.Delete(fileName);
                }
                using (FileStream fs = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                {
                    string js = ExcelUtility.ConvertJsonString(arr.ToString());

                    if (js.Equals(""))
                    {
                        return;
                    }
                    byte[] data = Encoding.UTF8.GetBytes(js);
                    fs.Write(data, 0, data.Length);
                }
            }
            SearchJsonFileAdd(OutPath.Text);
            MessageBox.Show("转换完成");
        }
示例#2
0
        private static void getQueue(string Format, string Encode, string[] strList)
        {
            lock (taskList)
            {
                if (taskList.Count > 0)
                {
                    string          output = GetRootPath("OutputPath");
                    FileInformation Info   = (FileInformation)taskList.Dequeue();
                    ExcelUtility    excel  = new ExcelUtility(Info);

                    Encoding encoding = Encoding.GetEncoding(Encode);

                    if (Format == "Json")
                    {
                        output = string.Format("{0}/Json", output);
                    }
                    else if (Format == "Csv")
                    {
                        output = string.Format("{0}/Csv", output);
                    }
                    else if (Format == "Xml")
                    {
                        output = string.Format("{0}/Xml", output);
                    }
                    else if (Format == "Lua")
                    {
                        output = string.Format("{0}/Lua", output);
                        excel.ConvertToLua(output, encoding, strList);
                    }
                    completeNum++;
                }

                //计数
                if (bardia != null)
                {
                    bardia.BeginInvoke(new MethodInvoker(() => { bardia.UpdateBarValue(maxtaskNum, completeNum); }));
                }
            }
        }