[[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 ===== Imports Microsoft.Office.Interop Imports Word = Microsoft.Office.Interop.Word Imports Office = Microsoft.Office.Core 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 ===== 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); } }