コード例 #1
0
        private void WriteStackLanguageExcel(DataTable dt)
        {
            string excelPath = textBoxPath.Text;
            string sheetName = "FB_Stack";

            bool result = ExcelOrXmlManager.WriteDataTableToExcel(dt, excelPath, sheetName);

            MessageBox.Show(string.Format("Write Finish , Result : {0}", result), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
コード例 #2
0
        private void buttonSure_Click(object sender, EventArgs e)
        {
            string    excelPath = textBoxPath.Text;
            string    sheetName = "FB_Dunkshot";
            DataTable dt        = ExcelOrXmlManager.ReadExcelToDataTable(excelPath, sheetName);

            if (dt.Rows.Count <= 1 || dt.Columns.Count <= 1)
            {
                Console.WriteLine("None Item Information.");
                return;
            }
            Dictionary <string, Dictionary <string, object> > dic = new Dictionary <string, Dictionary <string, object> >();

            dic.Clear();

            for (int i = 1; i < dt.Columns.Count; i++)
            {
                if (dt.Rows[1][i] == null || string.IsNullOrEmpty(dt.Rows[1][i].ToString().Trim()))
                {
                    continue;
                }
                string language = dt.Rows[0][i].ToString().Trim();
                Dictionary <string, object> dicItem = new Dictionary <string, object>();
                dicItem.Clear();
                for (int j = 1; j < dt.Rows.Count; j++)
                {
                    string key   = dt.Rows[j][0].ToString().Trim();
                    string value = dt.Rows[j][i] == null ? string.Empty : dt.Rows[j][i].ToString().Trim();

                    dicItem.Add(key, value);
                }
                dic.Add(language, dicItem);
            }



            foreach (KeyValuePair <string, Dictionary <string, object> > item in dic)
            {
                string json = JsonUtils.Instance.DictionaryToJson(item.Value);

                StringBuilder sb = new StringBuilder();
                //sb.Append(string.Format("export const language_{0} = \n", m_language[item.Key]));
                string[] data = json.Split(',');
                for (int i = 0; i < data.Length; i++)
                {
                    int    index = data[i].IndexOf(':');
                    string str1  = data[i].Substring(0, index);
                    string str2  = data[i].Substring(index, data[i].Length - index);
                    str1 = str1.Replace("\"", "");
                    sb.Append(string.Format("{0}{1}", str1, str2));
                    if (i < data.Length - 1)
                    {
                        sb.Append(",\n");
                    }
                }

                byte[] bt = Encoding.UTF8.GetBytes(sb.ToString());

                //using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite))
                //{
                //    fs.Write(bt, 0, bt.Length);
                //}
            }
        }