A kiválasztott változat és az aktuális verzió közötti különbségek a következők.
— |
oktatas:programozas:mso_dokumentum_generalas [2019/08/22 12:31] (aktuális) admin létrehozva |
||
---|---|---|---|
Sor 1: | Sor 1: | ||
+ | [[oktatas:programozás|< Programozás]] | ||
+ | ====== MSO dokumentum generálás ====== | ||
+ | * **Szerző:** Sallai András | ||
+ | * Copyright (c) Sallai András, 2015 | ||
+ | * Licenc: GNU Free Documentation License 1.3 | ||
+ | * Web: http://szit.hu | ||
+ | ===== MSO dokumentum Java környezetben ===== | ||
+ | |||
+ | |||
+ | * http://www.docx4java.org/ (Docx4java) | ||
+ | * http://www.aspose.com/java/word-component.aspx (Aspose) | ||
+ | * http://poi.apache.org/ (POI) | ||
+ | |||
+ | ===== VisualBasic ===== | ||
+ | |||
+ | <code basic4gl> | ||
+ | Imports Microsoft.Office.Interop | ||
+ | Imports Word = Microsoft.Office.Interop.Word | ||
+ | Imports Office = Microsoft.Office.Core | ||
+ | </code> | ||
+ | |||
+ | |||
+ | <code basic4gl> | ||
+ | Private Sub Gomb1_Click(sender As System.Object, e As System.EventArgs) Handles Gomb1.Click | ||
+ | Dim oWord As Word.Application | ||
+ | Dim oDoc As Word.Document | ||
+ | |||
+ | oWord = New Word.Application | ||
+ | oDoc = oWord.Documents.Open("C:\tesztFajl.docx") | ||
+ | |||
+ | With oDoc | ||
+ | .CustomDocumentProperties.Item("CustomPropertyName").value = "Teszt" | ||
+ | End With | ||
+ | |||
+ | oDoc.Fields.Update() | ||
+ | oDoc.Close() | ||
+ | oWord.Quit() | ||
+ | End Sub | ||
+ | </code> | ||
+ | |||
+ | ===== C# ===== | ||
+ | |||
+ | <code c#> | ||
+ | private void CreateDocument() | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | //Készítünk egy word alkalmazás példányt | ||
+ | Microsoft.Office.Interop.Word.Application winword = | ||
+ | new Microsoft.Office.Interop.Word.Application(); | ||
+ | |||
+ | //Beállítjuk az animáció állapotát | ||
+ | winword.ShowAnimation = false; | ||
+ | |||
+ | //beállítjuk a word alkalmazás láthatóságát. | ||
+ | winword.Visible = false; | ||
+ | | ||
+ | //A missing létrehozása | ||
+ | object missing = System.Reflection.Missing.Value; | ||
+ | |||
+ | //Új dokumentum készítése | ||
+ | Microsoft.Office.Interop.Word.Document document = | ||
+ | winword.Documents.Add(ref missing, ref missing, ref missing, ref missing); | ||
+ | | ||
+ | |||
+ | //szöveg dokumentumhoz adása | ||
+ | document.Content.SetRange(0, 0); | ||
+ | document.Content.Text = "This is test document "+ Environment.NewLine; | ||
+ | | ||
+ | | ||
+ | //Dokumentum mentése | ||
+ | object filename = @"c:\tesztFajl.docx"; | ||
+ | document.SaveAs2(ref filename); | ||
+ | document.Close(ref missing, ref missing, ref missing); | ||
+ | document = null; | ||
+ | winword.Quit(ref missing, ref missing, ref missing); | ||
+ | winword = null; | ||
+ | MessageBox.Show("A dokumentum sikeresen elkészült !"); | ||
+ | } | ||
+ | catch (Exception ex) | ||
+ | { | ||
+ | MessageBox.Show(ex.Message); | ||
+ | } | ||
+ | } | ||
+ | </code> |