Exemplo n.º 1
0
        public void CreateReport(IWordReport report)
        {
            var templateFullpath = Path.Combine(Environment.CurrentDirectory, templateFilename);

            if (!File.Exists(templateFullpath))
            {
                throw new ApplicationException($"Файл-шаблон отчета не существует или не задан ({templateFullpath})");
            }

            try
            {
                using (var application = new NetOffice.WordApi.Application())
                {
                    using (var document = application.Documents.Add(templateFullpath))
                    {
                        report.ExportToDocument(document);
                    }

                    application.Visible = true;
                    application.Activate();
                }
            }
            catch (Exception ex)
            {
                throw new SystemException("Ошибка экспорта в документ Word", ex);
            }
        }
Exemplo n.º 2
0
 static void Main(string[] args)
 {
     var excel      = new NetOffice.ExcelApi.Application();
     var word       = new NetOffice.WordApi.Application();
     var outlook    = new NetOffice.OutlookApi.Application();
     var powerpoint = new NetOffice.PowerPointApi.Application();
 }
 public NetOfficeWordApplication()
 {
     _application = new NetOfficeApplication()
     {
         Visible = false
     };
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            using (var wordApp = new NetOffice.WordApi.Application())
                using (var excelApp = new NetOffice.ExcelApi.Application())
                {
                    var doc = wordApp.Documents.Open("C:\\Users\\John\\Desktop\\test.docx");
                    var xls = excelApp.Workbooks.Open("C:\\Users\\John\\Desktop\\test.xlsx");

                    var customProperties = (DocumentProperties)doc.CustomDocumentProperties;

                    foreach (var property in customProperties)
                    {
                        Console.WriteLine(String.Format("Name: {0}, Value: {1}, Type: {2}", property.Name, property.Value, property.Type));
                    }

                    customProperties = (DocumentProperties)xls.CustomDocumentProperties;

                    foreach (var property in customProperties)
                    {
                        Console.WriteLine(String.Format("Name: {0}, Value: {1}, Type: {2}", property.Name, property.Value, property.Type));
                    }
                }

            Console.ReadKey();
        }
Exemplo n.º 5
0
        }//расчёт

        #region Helder
        private static string GetDefaultExtension(NetOffice.WordApi.Application application)
        {
            double version = Convert.ToDouble(application.Version, CultureInfo.InvariantCulture);

            if (version >= 12.00)
            {
                return(".docx");
            }
            else
            {
                return(".doc");
            }
        }
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> if called from managed code; otherwise <c>false</c>.</param>
        private void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }
            if (disposing)
            {
                // Dispose your managed resources here
                if (_application != null)
                {
                    _application.Quit();
                    _application.Dispose();
                }
            }

            // Dispose your unmanaged resources here
            _application = null;
            _disposed    = true;
        }
        private Task StartWordWithPdfAdProcess()
        {
            var pdfBytes = System.IO.File.ReadAllBytes(_filePath);
            using (NetOffice.WordApi.Application app = new NetOffice.WordApi.Application())
            {
#if DEBUG
                app.Visible = true;
#endif
                var doc = app.Documents.Open(_filePath);

                var datasheet = new Datasheet.Dal.Ef.Datasheet
                {
                    FilePath = _filePath,
                    Pdf = pdfBytes,
                    PdfProvider = GetInstanceName(_filePath),
                };

                foreach (var section in doc.Paragraphs)
                {
                    var newSection = new Section
                    {

                    };

                    datasheet.Sections.Add(newSection);
                    if (!String.IsNullOrEmpty(section.Range.Text) && ! String.IsNullOrWhiteSpace(section.Range.Text))
                    {
                        newSection.SectionText = section.Range.Text;
                    }
                    else
                    {
                        //Extract image!
                        //newSection.SectionImage = section.Range.
                    }
                }
                app.Quit();
                _context.Datasheets.Add(datasheet);
                return _context.SaveChangesAsync();
            }
        }
        private Task StartWordWithPdfAdProcess()
        {
            var pdfBytes = System.IO.File.ReadAllBytes(_filePath);

            using (NetOffice.WordApi.Application app = new NetOffice.WordApi.Application())
            {
#if DEBUG
                app.Visible = true;
#endif
                var doc = app.Documents.Open(_filePath);

                var datasheet = new Datasheet.Dal.Ef.Datasheet
                {
                    FilePath    = _filePath,
                    Pdf         = pdfBytes,
                    PdfProvider = GetInstanceName(_filePath),
                };

                foreach (var section in doc.Paragraphs)
                {
                    var newSection = new Section
                    {
                    };

                    datasheet.Sections.Add(newSection);
                    if (!String.IsNullOrEmpty(section.Range.Text) && !String.IsNullOrWhiteSpace(section.Range.Text))
                    {
                        newSection.SectionText = section.Range.Text;
                    }
                    else
                    {
                        //Extract image!
                        //newSection.SectionImage = section.Range.
                    }
                }
                app.Quit();
                _context.Datasheets.Add(datasheet);
                return(_context.SaveChangesAsync());
            }
        }
Exemplo n.º 9
0
        void NetOffice.WordApi.Tools.ITaskPane.OnConnection(NetOffice.WordApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
        {
            TestAddin addin = customArguments[0] as TestAddin;

            addin.TaskPaneOkay = true;
        }
Exemplo n.º 10
0
 void NetOffice.WordApi.Tools.ITaskPane.OnConnection(NetOffice.WordApi.Application application, object[] customArguments)
 {
 }
Exemplo n.º 11
0
 public void OnConnection(NetOffice.WordApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
 {
     application.WindowSelectionChangeEvent += new NetOffice.WordApi.Application_WindowSelectionChangeEventHandler(Application_WindowSelectionChangeEvent);
 }
Exemplo n.º 12
0
 public void OnConnection(NetOffice.WordApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
 {
 }
Exemplo n.º 13
0
 public void OnConnection(NetOffice.WordApi.Application application, NetOffice.OfficeApi._CustomTaskPane parentPane, object[] customArguments)
 {
     StartTime = DateTime.Now;
     buttonEnabled_Click(buttonEnabled, new EventArgs());
 }
Exemplo n.º 14
0
        private void button_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrWhiteSpace(k_t.Text) || string.IsNullOrWhiteSpace(k_s.Text) || string.IsNullOrWhiteSpace(o_n.Text) || string.IsNullOrWhiteSpace(p_p.Text) ||
                string.IsNullOrWhiteSpace(v_r.Text) || string.IsNullOrWhiteSpace(Ri_t.Text) || string.IsNullOrWhiteSpace(Rn_t.Text) || string.IsNullOrWhiteSpace(H_t.Text) ||
                string.IsNullOrWhiteSpace(n1_1.Text) || string.IsNullOrWhiteSpace(n1_2.Text) || string.IsNullOrWhiteSpace(n1_3.Text) || string.IsNullOrWhiteSpace(n1_4.Text) ||
                string.IsNullOrWhiteSpace(n2_1.Text) || string.IsNullOrWhiteSpace(n2_2.Text) || string.IsNullOrWhiteSpace(n2_3.Text) || string.IsNullOrWhiteSpace(n2_4.Text) ||
                string.IsNullOrWhiteSpace(n3_1.Text) || string.IsNullOrWhiteSpace(n3_2.Text) || string.IsNullOrWhiteSpace(n3_3.Text) || string.IsNullOrWhiteSpace(n3_4.Text) ||
                string.IsNullOrWhiteSpace(n4_1.Text) || string.IsNullOrWhiteSpace(n4_2.Text) || string.IsNullOrWhiteSpace(n4_3.Text) || string.IsNullOrWhiteSpace(n4_4.Text) ||
                string.IsNullOrWhiteSpace(n5_1.Text) || string.IsNullOrWhiteSpace(n5_2.Text) || string.IsNullOrWhiteSpace(n5_3.Text) || string.IsNullOrWhiteSpace(n5_4.Text) ||
                string.IsNullOrWhiteSpace(n6_1.Text) || string.IsNullOrWhiteSpace(n6_2.Text) || string.IsNullOrWhiteSpace(n6_3.Text) || string.IsNullOrWhiteSpace(n6_4.Text) ||
                string.IsNullOrWhiteSpace(n7_1.Text) || string.IsNullOrWhiteSpace(n7_2.Text) || string.IsNullOrWhiteSpace(n7_3.Text) || string.IsNullOrWhiteSpace(n7_4.Text) ||
                string.IsNullOrWhiteSpace(n8_1.Text) || string.IsNullOrWhiteSpace(n8_2.Text) || string.IsNullOrWhiteSpace(n8_3.Text) || string.IsNullOrWhiteSpace(n8_4.Text) ||
                string.IsNullOrWhiteSpace(n9_1.Text) || string.IsNullOrWhiteSpace(n9_2.Text) || string.IsNullOrWhiteSpace(n9_3.Text) || string.IsNullOrWhiteSpace(n9_4.Text)
                )
            {
                MessageBox.Show("Ошибка ввода!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Information);
            }
            else
            {
                Regex X = new Regex(@"^\d*(\,\d+)?$");

                if (X.IsMatch(n1_1.Text) && (X.IsMatch(n1_2.Text)) && (X.IsMatch(n1_3.Text)) && (X.IsMatch(n1_4.Text)) && (X.IsMatch(n2_1.Text)) && (X.IsMatch(n2_2.Text)) &&
                    (X.IsMatch(n2_3.Text)) && (X.IsMatch(n2_4.Text)) && (X.IsMatch(n3_1.Text)) && (X.IsMatch(n3_2.Text)) && (X.IsMatch(n3_3.Text)) && (X.IsMatch(n3_4.Text)) &&
                    (X.IsMatch(n4_1.Text)) && (X.IsMatch(n4_2.Text)) && (X.IsMatch(n4_3.Text)) && (X.IsMatch(n4_4.Text)) && (X.IsMatch(n5_1.Text)) && (X.IsMatch(n5_2.Text)) &&
                    (X.IsMatch(n5_3.Text)) && (X.IsMatch(n5_4.Text)) && (X.IsMatch(n6_1.Text)) && (X.IsMatch(n6_2.Text)) && (X.IsMatch(n6_3.Text)) && (X.IsMatch(n6_4.Text)) &&
                    (X.IsMatch(n7_1.Text)) && (X.IsMatch(n7_2.Text)) && (X.IsMatch(n7_3.Text)) && (X.IsMatch(n7_4.Text)) && (X.IsMatch(n8_1.Text)) && (X.IsMatch(n8_2.Text)) &&
                    (X.IsMatch(n8_3.Text)) && (X.IsMatch(n8_4.Text)) && (X.IsMatch(n9_1.Text)) && (X.IsMatch(n9_2.Text)) && (X.IsMatch(n9_3.Text)) && (X.IsMatch(n9_4.Text)) &&
                    (X.IsMatch(k_t.Text)) && (X.IsMatch(k_s.Text)) && (X.IsMatch(o_n.Text)) && (X.IsMatch(p_p.Text)) && (X.IsMatch(v_r.Text)) && (X.IsMatch(Ri_t.Text)) && (X.IsMatch(Rn_t.Text)) && (X.IsMatch(H_t.Text)))
                {
                    f  = Convert.ToDouble(k_t.Text);
                    n  = Convert.ToInt32(k_s.Text);
                    R0 = Convert.ToDouble(v_r.Text);
                    a  = Convert.ToDouble(p_p.Text);
                    q  = Convert.ToDouble(o_n.Text);
                    Ri = Convert.ToDouble(Ri_t.Text);
                    H  = Convert.ToDouble(H_t.Text);
                    if (Convert.ToDouble(n2_4.Text) <= (Convert.ToDouble(n1_4.Text)) ||
                        (Convert.ToDouble(n3_4.Text) <= (Convert.ToDouble(n2_4.Text)) ||
                         (Convert.ToDouble(n4_4.Text) <= (Convert.ToDouble(n3_4.Text)) ||
                          (Convert.ToDouble(n5_4.Text) <= (Convert.ToDouble(n4_4.Text)) ||
                           (Convert.ToDouble(n6_4.Text) <= (Convert.ToDouble(n5_4.Text)) ||
                            (Convert.ToDouble(n7_4.Text) <= (Convert.ToDouble(n6_4.Text)) ||
                             (Convert.ToDouble(n8_4.Text) <= (Convert.ToDouble(n7_4.Text)) ||
                              (Convert.ToDouble(n9_4.Text) <= (Convert.ToDouble(n8_4.Text))))))))))
                    {
                        MessageBox.Show("Ошибка ввода!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Information);
                    }
                    else
                    {
                        List <double> KI_list_2 = new List <double> {
                        };
                        List <double> DI_list_2 = new List <double> {
                        };
                        List <double> RI_list_2 = new List <double> {
                        };
                        KI_list_2.Add(Convert.ToDouble(n1_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n2_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n3_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n4_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n5_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n6_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n7_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n8_2.Text));
                        KI_list_2.Add(Convert.ToDouble(n9_2.Text));
                        DI_list_2.Add(Convert.ToDouble(n1_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n2_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n3_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n4_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n5_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n6_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n7_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n8_3.Text));
                        DI_list_2.Add(Convert.ToDouble(n9_3.Text));
                        RI_list_2.Add(Convert.ToDouble(n1_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n2_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n3_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n4_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n5_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n6_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n7_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n8_4.Text));
                        RI_list_2.Add(Convert.ToDouble(n9_4.Text));
                        double[]      KI_2     = KI_list_2.ToArray <double>();
                        double[]      DI_2     = DI_list_2.ToArray <double>();
                        double[]      RI_2     = RI_list_2.ToArray <double>();
                        List <double> RI_list  = new List <double> {
                        };
                        List <double> YI_list  = new List <double> {
                        };
                        List <double> VI_list  = new List <double> {
                        };
                        List <double> QI_list  = new List <double> {
                        };
                        List <double> AI_list  = new List <double> {
                        };
                        List <double> Sum_list = new List <double> {
                        };
                        RI_list.Add(Convert.ToDouble(n1_4.Text));
                        while (Ri <= Convert.ToDouble(n9_4.Text))
                        {
                            Ri = Ri + H;
                            RI_list.Add(Ri);
                            kol_e++;
                        }
                        double[] RI = RI_list.ToArray <double>();

                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            yi = 2 * a * (RI[i] - R0);
                            YI_list.Add(yi);
                        }
                        double[] YI = YI_list.ToArray <double>();
                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            Vi = 1 / (Math.Sqrt(1 + YI[i] * YI[i]));
                            VI_list.Add(Vi);
                        }
                        double[] VI = VI_list.ToArray <double>();


                        for (int i = 0; i <= n - 1; i++)
                        {
                            pr_sum = pr_sum + (KI_2[i] * DI_2[i] * Math.Pow(VI[i], 2));
                            pr_n++;
                        }

                        pr_sum_2 = DI_2[pr_n - 1] / pr_sum;
                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            qi = pr_sum_2 * q * VI[i];
                            QI_list.Add(qi);
                        }
                        double[] QI = QI_list.ToArray <double>();

                        for (int i = 0; i <= RI.Length - 1; i++)
                        {
                            A = 2 * 3.141592653589793238462643383279 * f * QI[i] * RI[i];
                            AI_list.Add(A);
                        }
                        double[] AI = AI_list.ToArray <double>();
                        max = AI.Max();
                        string date_time   = DateTime.Now.ToString("dd MMMM yyyy HH:mm:ss");
                        string date_time_2 = DateTime.Now.ToString("dd MMMM yyyy HH-mm-ss");
                        NetOffice.WordApi.Application word = new NetOffice.WordApi.Application();
                        word.DisplayAlerts = WdAlertLevel.wdAlertsNone;
                        NetOffice.WordApi.Document newdoc = word.Documents.Add();
                        word.Selection.TypeText(date_time);//пока только так(
                        word.Selection.TypeParagraph();
                        word.Selection.TypeText("Исходные данные");
                        word.Selection.TypeParagraph();
                        NetOffice.WordApi.Table table = newdoc.Tables.Add(word.Selection.Range, n, 4);
                        table.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 1; j <= 1; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(NI[i]));
                            }
                        }
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 2; j <= 2; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(KI_2[i]));
                            }
                        }
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 3; j <= 3; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(DI_2[i]));
                            }
                        }
                        for (int i = 0; i < n; i++)
                        {
                            for (int j = 4; j <= 4; j++)
                            {
                                table.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(RI_2[i]));
                            }
                        }
                        word.Selection.EndKey(6);
                        word.Selection.TypeParagraph();
                        word.Selection.TypeParagraph();
                        word.Selection.TypeText("Таблица результатов");
                        NetOffice.WordApi.Table table_2 = newdoc.Tables.Add(word.Selection.Range, kol_e, 3);
                        table_2.Borders.InsideLineStyle  = WdLineStyle.wdLineStyleSingle;
                        table_2.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleSingle;
                        for (int i = 0; i < kol_e; i++)
                        {
                            for (int j = 1; j <= 1; j++)
                            {
                                table_2.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(RI[i]));
                            }
                        }
                        for (int i = 0; i < kol_e; i++)
                        {
                            for (int j = 2; j <= 2; j++)
                            {
                                table_2.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(QI[i]));
                            }
                        }
                        for (int i = 0; i < kol_e; i++)
                        {
                            for (int j = 3; j <= 3; j++)
                            {
                                table_2.Cell(i + 1, j).Select();
                                word.Selection.TypeText(Convert.ToString(AI[i]));
                            }
                        }
                        int indexMax = Array.IndexOf(AI, max);
                        word.Selection.EndKey(6);
                        word.Selection.TypeParagraph();
                        word.Selection.TypeText("Максимальное значение А = " + Convert.ToString(max) + " при значении " + RI[indexMax] + " RI");
                        string fileExtension = GetDefaultExtension(word);//проверка версии
                        object documentFile  = string.Format("{0}\\" + date_time_2 + "{1}", Directory.GetCurrentDirectory(), fileExtension);
                        newdoc.SaveAs(documentFile);
                        word.Quit();
                        word.Dispose();
                        Array.Clear(RI, 0, RI.Length);
                        Array.Clear(YI, 0, YI.Length);
                        Array.Clear(VI, 0, VI.Length);
                        Array.Clear(QI, 0, QI.Length);
                        Array.Clear(AI, 0, AI.Length);
                        Array.Clear(KI_2, 0, KI_2.Length);
                        Array.Clear(RI_2, 0, RI_2.Length);
                        pr_n     = 0;
                        pr_sum   = 0;
                        pr_sum_2 = 0;
                        kol_e    = 0;
                    }
                }
                else
                {
                    MessageBox.Show("Ошибка ввода!", "Ошибка", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }//расчёт
Exemplo n.º 15
0
        private void button9_Click_1(object sender, EventArgs e)
        {
            var templateFileName = Path.Combine(Environment.CurrentDirectory, "меню.doc");

            if (!File.Exists(templateFileName))
            {
                throw new FileNotFoundException("File not found.", templateFileName);
            }
            Dishesmenu Du = new Dishesmenu();

            using (var application = new NetOffice.WordApi.Application {
                Visible = true
            })
            {
                using (var document = application.Documents.Add(templateFileName))
                {
                    List <HelpCategory> cats = new List <HelpCategory>();

                    for (int i = 0; i < dataGridView3.RowCount; i++)
                    {
                        HelpCategory temp = new HelpCategory();
                        temp.ves      = (int)dataGridView3.Rows[i].Cells[3].Value;
                        temp.name     = (string)dataGridView3.Rows[i].Cells[2].Value;
                        temp.price    = (decimal)dataGridView3.Rows[i].Cells[4].Value;
                        temp.category = (string)dataGridView3.Rows[i].Cells[6].Value;

                        cats.Add(temp);
                    }


                    var coordinatesTable = document.Bookmarks["Coordinates"].Range.Tables[1];


                    //

                    List <string> uniqueCategory = cats.Select(x => x.category).Distinct().ToList();



                    foreach (string strCat in uniqueCategory)
                    {
                        var tempWord = coordinatesTable.Rows.Add();

                        tempWord.Cells[2].Range.Bold = 3;
                        tempWord.Cells[2].Range.Text = strCat;


                        foreach (HelpCategory cat in cats)
                        {
                            if (cat.category == strCat)
                            {
                                var tempRow = coordinatesTable.Rows.Add();
                                tempRow.Cells[2].Range.Bold = 0;
                                tempRow.Cells[1].Range.Text = cat.ves.ToString();
                                tempRow.Cells[2].Range.Text = cat.name;
                                tempRow.Cells[3].Range.Text = cat.price.ToString("# руб");
                            }
                        }
                    }

                    coordinatesTable.Rows[2].Delete();

                    var MenuTable = document.Bookmarks["data"].Range;
                    int n         = dataGridView2.SelectedRows[0].Index;
                    MenuTable.Text = dataGridView2.Rows[n].Cells[2].Value.ToString();
                    //var MenuTable = document.Bookmarks["Menu"].Range.Text;

                    ////var coordinateRow = Menu.Add();
                }
                application.Activate();
            }
        }