Exemple #1
0
        static void Main(string[] args)
        {
            #region ChineseChar 小试
            //string str = Console.ReadLine();
            //var ch = str[0];
            //Console.WriteLine($"汉字:{ch}");

            //ChineseChar cc = new ChineseChar(ch);
            //var pinyins = cc.Pinyins.ToList();
            //pinyins.ForEach(p =>
            //{
            //    Console.WriteLine($"拼音:{p}");
            //});
            #endregion

            for (int i = 0; i < 10; i++)
            {
                Console.WriteLine("请输入中文:");
                string str      = Console.ReadLine();
                var    pingyins = PinYinConverterHelp.GetTotalPingYin(str);
                Console.WriteLine("全拼音:" + String.Join(",", pingyins.TotalPingYin));
                Console.WriteLine("首音:" + String.Join(",", pingyins.FirstPingYin));
                Console.WriteLine();
            }
        }
Exemple #2
0
 static void Main(string[] args)
 {
     for (int i = 0; i < 10; i++)
     {
         Console.WriteLine("请输入中文:");
         string str      = Console.ReadLine();
         var    pingyins = PinYinConverterHelp.GetTotalPingYin(str);
         Console.WriteLine("全拼音:" + String.Join(",", pingyins.TotalPingYin));
         Console.WriteLine("首音:" + String.Join(",", pingyins.FirstPingYin));
         Console.WriteLine();
     }
 }
Exemple #3
0
        private void BT_OpenFile_Click(object sender, EventArgs e)
        {
            //Console.WriteLine("全拼音:" + String.Join(",", pingyins.TotalPingYin));
// Console.WriteLine("首音:" + String.Join(",", pingyins.FirstPingYin));

            List <string> sheetNames        = new List <string>();
            List <string> newSheetNamesList = new List <string>();
            string        strTabColName     = string.Empty;

            string strNewSheetName = string.Empty;

            string strPinYinColName = string.Empty;

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                RegisterLib.PrograssBar prgBar = new PrograssBar();
                prgBar.BarLength = 20;

                //pb.Max
                ExcelHelper helper = new ExcelHelper();
                Worksheet   ws;
                foreach (var fileName in openFile.FileNames)
                {
                    helper.OpenFile(fileName);

                    prgBar.MaxValue = helper.Sheets.Count;

                    for (int i = 0; i < helper.Sheets.Count; i++)
                    {
                        ws = helper.Sheets[i + 1] as Worksheet;

                        //if (ws.Name.Contains("表名对照")==true)
                        //{
                        //    ws.Delete();
                        //}

                        sheetNames.Add(ws.Name);
                        LB_SheetNames.Items.Add(ws.Name);

                        LB_TotalProgress.Text = prgBar.ProgressMsg(string.Format("正在重命名sheet,第{0}个/总共{1}个", i + 1, helper.Sheets.Count), i, helper.Sheets.Count);

                        ///获取新的sheet名称
                        var pingyins = PinYinConverterHelp.GetTotalPingYin(ws.Name);
                        strNewSheetName = pingyins.FirstPingYin.First <string>().ToUpper();
                        strNewSheetName = GetReNameRulsPrefix(ws.Name) + strNewSheetName;
                        if (newSheetNamesList.Contains(strNewSheetName))
                        {
                            strNewSheetName += i.ToString();
                        }
                        ws.Name = strNewSheetName;

                        newSheetNamesList.Add(ws.Name);
                        LB_NewSheetNames.Items.Add(ws.Name);
                        if (ws.Name.StartsWith("TB"))
                        {
                            ///修改每个sheet的表名称为汉语拼音
                            ReNameFields(ws);
                        }
                    }

                    //File.WriteAllLines("D:\\Dic.txt", fieldNames.ToArray());
                    ////将表明保存在excel中。
                    Worksheet newSheet = helper.Sheets.Add() as Worksheet;
                    try
                    {
                        if (newSheet != null)
                        {
                            newSheet.Name = "表名对照";
                        }
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("表名对照保存为:" + newSheet.Name);
                    }


                    for (int x = 1; x < sheetNames.Count; x++)
                    {
                        newSheet.Cells[x, 1].Value = sheetNames[x - 1];
                        newSheet.Cells[x, 2].Value = newSheetNamesList[x - 1];
                    }

                    string newFile = fileName.Replace(".", "_OK.");
                    helper.SaveAsNewFile(newFile);// (fileName);

                    helper.WorkBook.Close();
                    helper.Excel.Quit();

                    MessageBox.Show("文件" + fileName + "改名完成");
                    //string[] sheetNames = ExcelHelper.GetSheetNames(fileName);

                    //LB_SheetNames.DataSource = sheetNames;
                    //LB_ReNamedSheetNames.DataSource = sheetReNames;
                }
            }

            File.WriteAllLines(@"未翻译字段.txt", unTranslatedFields.ToArray(), Encoding.UTF8);
            File.WriteAllLines(@"字典.txt", TB_DIC.Lines, Encoding.UTF8);
        }