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);
        }
Exemplo n.º 2
0
        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;
            }
        }