Beispiel #1
0
        private void buttonSaveToExel_Click(object sender, EventArgs e)
        {
            if (this.e == null || b == null || a == null)
            {
                throw new Exception("Сначала должны быть сгенерированы уравнения!");
            }

            string[] singleCodesString = this.e.Select(val => val.ToString()).ToArray();
            string[] bString           = b.Select(val => val.ToString()).ToArray();
            string[] binaryString      = MathProcessor.TransposeBitMatrix(a)
                                         .Select(val => val.ToString()).ToArray();
            ExcelTools excel = new ExcelTools(progressBar);

            excel.GenerateDocument(singleCodesString, bString, binaryString);
            excel.Dispose();
            progressBar.Value = 0;
        }
Beispiel #2
0
        /// <summary>
        /// Создание документа docx с формулами ai
        /// </summary>
        /// <param name="transpB">Массив состовляющих ЕПК</param>
        /// <param name="a">ДК</param>
        /// <param name="path">Путь к результирующему файлу</param>
        public void GenerateDocument(LongBits[] b, out LongBits[] a, string path)
        {
            application = new Word.Application {
                Visible = false
            };
            try
            {
                document = application.Documents.Add();
                document.Range(0, 0).PageSetup.Orientation = WdOrientation.wdOrientLandscape;

                LongBits[] transpB = MathProcessor.TransposeBitMatrix(b);
                int        n       = MathProcessor.GetN(transpB.Length + 1);
                a = new LongBits[n];
                SetMaxValueBar(n);

                for (int i = n - 1; i >= 0; i--)
                {
                    List <string> formules = new List <string>();
                    a[i] = new LongBits(transpB[0].Length);
                    a[i] = ~a[i];
                    int kmax = (int)Math.Pow(2, n - 1 - i) - 1;
                    for (int k = 0; k <= kmax; k++)
                    {
                        int tmin = (int)Math.Pow(2, i) * (2 * k + 1);
                        int tmax = (int)Math.Pow(2, i + 1) * (k + 1) - 1;
                        for (int t = tmin; t <= tmax; t++)
                        {
                            if (formules.Count == 0 || formules[formules.Count - 1].Length > 250)
                            {
                                formules.Add(string.Empty);
                            }
                            formules[formules.Count - 1] += " b_" + t + notSign + " ";
                            a[i] &= ~transpB[t - 1];
                        }
                    }
                    a[i] = ~a[i];

                    document.Range(0, 0).Text += "\n ";
                    for (int index = formules.Count - 1; index >= 0; index--)
                    {
                        document.Range(0, 0).Text += "\n ";
                        BuildFormula(notSign);
                        BuildFormula(")", WdColor.wdColorWhite);
                        BuildFormula(formules[index]);
                        BuildFormula("(", WdColor.wdColorWhite);
                        if (index == 0)
                        {
                            BuildFormula("a_" + i + "=");
                        }
                        else
                        {
                            BuildFormula("          ");
                        }
                        document.OMaths.BuildUp();
                    }
                    PerformStepBar();
                }
                document.SaveAs(path);
            }
            finally
            {
                //Закрывание ворда
                document.Close();
                application.Quit();
            }
        }