private async Task <int> TranslateSheet2(IWorksheet newSheet, List <IRange> arRange, int numPrevRequest) { ActionF1 ActionF1 = new ActionF1(); var ienum = arRange.AsEnumerable(); TaskScheduler tsc = TaskScheduler.Current; int i = 0; IRange whatIR = null; int limit = arRange.Count; limit = Math.Min(limit, _iMaxRequest - numPrevRequest); for (i = 0; i < limit; i++) { whatIR = arRange[i]; //DataTable orgTa = whatIR.GetDataTable(SpreadsheetGear.Data.GetDataFlags.NoColumnHeaders); //error convert type double (set columntype = type of first cell DataTable orgTa = GetTableFromIrange(whatIR); string originalText = GetTextFromTable(orgTa); if (originalText.Length > 5000) { continue; } JArray jarr = await ActionF1.GetSingle(originalText, _fromLang, _toLang); toolStripProgressBar1.Value = (int)((i + 1) * 100 / limit); Thread.Sleep(480); List <string> transateText = ActionF1.ReadJArrayRes(jarr); ////fake start //JArray jarr = await FakeTrans(originalText); //List<string> transateText = null; ////fake end DataTable traTa = GetTableFromText(transateText, orgTa); //translate sucess if (traTa != null) { for (int im = 0; im < traTa.Rows.Count; im++) { object vv = traTa.Rows[im][0]; if (vv != null && vv.ToString().Trim().Length > 0) { newSheet.Range[whatIR.Address].Cells[im, 0].Value = vv; } } } else { //remain originalText } } return(limit + numPrevRequest); }
private async void ObserverHook(InterceptKeys.KeysData m, EventArgs e) { string text = CopyTextFromFocusedControl(); if (!string.IsNullOrEmpty(text)) { //await Task.Run(() => { }); label1.Text = text; var jj = await ActionF1.GetSingle(text); if (jj == null) { return; } JToken j_0 = jj[0]; if (j_0 == null) { return; } int iLen = j_0.Count(); JToken spell = j_0[iLen - 1]; if (j_0[0] == null || j_0[0][0] == null) { if (spell == null || spell[3] == null) { return; } label1.Text = label1.Text + Environment.NewLine + spell[3].ToString(); } else { if (spell == null || spell[3] == null) { return; } label1.Text = label1.Text + Environment.NewLine + j_0[0][0].ToString() + Environment.NewLine + spell[3].ToString(); } this.WindowState = FormWindowState.Minimized; this.Show(); this.WindowState = FormWindowState.Normal; } }
private async Task TranslateSheet(IWorksheet newSheet, List <IRange> arRange) { ActionF1 ActionF1 = new ActionF1(); var ienum = arRange.AsEnumerable(); TaskScheduler tsc = TaskScheduler.Current; int i = 0; IRange whatIR = null; for (i = 0; i < arRange.Count; i++) { whatIR = arRange[i]; string originalText = whatIR.Value.ToString(); if (originalText.Length > 2500) { newSheet.Range[whatIR.Address].Value = whatIR.Value; continue; } JArray res = await ActionF1.GetSingle(originalText); string transateText = ActionF1.ReadJArrayRes(res).Aggregate((m, n) => m + n); newSheet.Range[whatIR.Address].Value = transateText; } }
private async Task <int> TranslateSheet2(Excel.Worksheet currentSheet, List <Excel.Range> arRange, int numPrevRequest) { ActionF1 ActionF1 = new ActionF1(); var ienum = arRange.AsEnumerable(); TaskScheduler tsc = TaskScheduler.Current; int i = 0; Excel.Range whatIR = null; int limit = arRange.Count; limit = Math.Min(limit, _iMaxRequest - numPrevRequest); for (i = 0; i < limit; i++) { whatIR = arRange[i]; //DataTable orgTa = whatIR.GetDataTable(SpreadsheetGear.Data.GetDataFlags.NoColumnHeaders); //error convert type double (set columntype = type of first cell DataTable orgTa = GetTableFromIrange(whatIR); string originalText = GetTextFromTable2(orgTa); if (originalText.Length > 5000) { continue; } JArray jarr = await ActionF1.GetSingle(originalText, _fromLang, _toLang); toolStripProgressBar1.Value = (int)((i + 1) * 100 / limit); Thread.Sleep(480); List <string> transateText = ActionF1.ReadJArrayRes2(jarr); ////fake start //JArray jarr = await FakeTrans(originalText); //List<string> transateText = null; ////fake end DataTable traTa = GetTableFromText(transateText, orgTa); //translate sucess if (traTa != null) { for (int im = 1; im <= traTa.Rows.Count; im++) { object vv = traTa.Rows[im - 1][0]; //string[] speStart = new string[] {"\n", "「" , "\"","“",}; if (vv != null && vv.ToString().Trim().Length > 1) //&& (System.Text.RegularExpressions.Regex.IsMatch(vv.ToString().Trim().Substring(0, 1), @"[a-zA-Z0-9]") || speStart.Contains(vv.ToString().Substring(0, 1)))) { if (currentSheet.Range[whatIR.Address].Cells[im, 1].Comment != null) { currentSheet.Range[whatIR.Address].Cells[im, 1].ClearComments(); } currentSheet.Range[whatIR.Address].Cells[im, 1].AddComment(vv.ToString()); Excel.Comment ic = currentSheet.Range[whatIR.Address].Cells[im, 1].Comment; ic.Shape.TextFrame.AutoSize = true; //using (Graphics g = this.CreateGraphics()) //{ // string item = ic.ToString(); // SizeF sizeF = g.MeasureString(item, Font); // ic.Shape.Width = sizeF.Width; //} } } } else { //remain originalText } } return(limit + numPrevRequest); }