ComponentOne Word for UWP
Quick Start: Word for UWP / Step 2 of 3: Adding Text
In This Topic
    Step 2 of 3: Adding Text
    In This Topic

    While you are still in code view in the Visual Studio project, add the following code within the btnText_Click event:

    Dim word As New C1WordDocument()
    
    ' use landscape for more impact
    word.Landscape = True
    
    ' measure and show some text 
    Dim text = "Hello!! This is a sample text."
    Dim font = New Font("Segoe UI Light", 20, RtfFontStyle.Italic)
    
    ' add paragraph
    word.AddParagraph(text, font, Colors.BlueViolet, RtfHorizontalAlignment.Justify)
    
    Dim picker As New FileSavePicker()
    picker.FileTypeChoices.Add("Word Open XML Format (.docx)", New List(Of String)() From { _
            ".docx" _
    })
    picker.FileTypeChoices.Add("RTF Format (.rtf)", New List(Of String)() From { _
            ".rtf" _
    })
    
    picker.DefaultFileExtension = ".docx"
    picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary
    Dim file As StorageFile = Await picker.PickSaveFileAsync()
    If file IsNot Nothing Then
            Await word.SaveAsync(file, If(file.Name.ToLower().EndsWith(".docx"), FileFormat.OpenXml, FileFormat.Rtf))
    
            Dim dlg As New MessageDialog("File saved")
            Await dlg.ShowAsync()
    End If
    
    C1WordDocument word = new C1WordDocument();
    
    // use landscape for more impact
    word.Landscape = true;
    
    // measure and show some text 
    var text = "Hello!! This is a sample text.";
    var font = new Font("Segoe UI Light", 20, RtfFontStyle.Italic);
    
    // add paragraph
    word.AddParagraph(text, font, Colors.BlueViolet, RtfHorizontalAlignment.Justify);
    
    FileSavePicker picker = new FileSavePicker();
    picker.FileTypeChoices.Add("Word Open XML Format (.docx)", new List < string > () {
      ".docx"
    });
    picker.FileTypeChoices.Add("RTF Format (.rtf)", new List < string > () {
      ".rtf"
    });
    
    picker.DefaultFileExtension = ".docx";
    picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
    StorageFile file = await picker.PickSaveFileAsync();
    if (file != null) {
      await word.SaveAsync(file, file.Name.ToLower().EndsWith(".docx") ? FileFormat.OpenXml : FileFormat.Rtf);
    
      MessageDialog dlg = new MessageDialog("File saved");
      await dlg.ShowAsync();
    }
    

    In the above code, a word document is created in landscape mode with some text added to it using AddParagraph method. It allows you to save the created document to the location of your choice. You can select the desired location and write the name of your document as well. The document is then saved with the same name you provided it.