L
L
LuckyRuS2019-03-04 18:00:58
Word
LuckyRuS, 2019-03-04 18:00:58

How to make a program to fill data in Word?

Please help in resolving the issue of creating a program whose task is to fill in two or three different types of questionnaires ---> generate the generated file in Word or PDF format ---> Send the file to a specific postal address .
The purpose is as follows:
1. A drop-down list appears like:

  • - application form for applicants
  • - student questionnaire
  • - questionnaire for the teacher

2. As you choose one or another, you need to fill in the standard fields:
  • - FULL NAME
  • - Faculty (position)
  • - Phone number

3. If all the conditions are met (all fields are filled), the "SEND" button appears, after clicking on which a previously prepared DOC or PDF template is generated, which is sent to the postal address of the dean's office.
Previously, I looked at the option with Windows Forms and C ++ , but something is not right. I couldn't find any other good descriptions online. I would be grateful for help, the right direction in solving this problem. Maybe someone has something similar.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
F
Foggy Finder, 2019-03-05
@LuckyRuS

It is not clear why the " Programming " tag was removed from the question. It turns out the answer in some way will be offtopic.
Now, in essence:
I don’t know if there is such an opportunity in Word , but if there is, then it would be better (faster) to use it.
But if it is the program that is needed, then I would start by drawing up a technical specification (technical task), which would contain a detailed description of the required functionality.
So far, the description in the question is rather vague, but here is a sketch that I quickly wrote in a couple of hours in the F# programming language:
Note : Perhaps F# is not the best choice for this task, but since I use it for my personal programs, I also quote German
1. The main objects are defined (Student, Teacher, Entrant) for which the characteristics to be filled in are listed as properties:

module Model

type Student = {
    Name : string
    Surname : string
    LastName : string
    Phone : string
    Faculty : string
}

Separately, for convenience, we present our records as a discriminated union:
[<RequireQualifiedAccess>]
type AccountType = 
    | Student of Student
    | Enrollee of Enrollee
    | Teacher of Teacher

We create the Defaults module which will contain the default values ​​for objects (it will be necessary for display):
[<RequireQualifiedAccess>]
module Defaults = 
    let student:Student = {
        Name = ""
        Surname = ""
        LastName = ""
        Phone = ""
        Faculty = ""
    }

The next step is to create or edit / fill in the finished Word or Pdf template with data.
There are several options (libraries) for working with both formats. There is a very well-known library for Pdf:
iTextSharp
There are others, such as
SharpLayout
Documentation in which leaves much to be desired, but at least it is clear that it has no problems with displaying Cyrillic characters.
The simplest table output might look like this:
[<RequireQualifiedAccess>]
module PdfReport

open Model
open PdfSharp.Drawing
open SharpLayout

let private defaultSettings = 
    PageSettings(
        TopMargin=Util.Cm(1.2),
        BottomMargin=Util.Cm(1.0),
        LeftMargin=Util.Cm(2.0),
        RightMargin=Util.Cm(1.0))

let private createReportForTeacher teacher = 
    let document = Document()
    let section = document.Add(Section(defaultSettings))
    
    let font = 
        Font("Times New Roman", 10.0, XFontStyle.Regular, XPdfFontOptions.UnicodeDefault)
        |> Option
    
    section.Add(Paragraph().Add("Информация об преподователе", font.Value).Alignment(HorizontalAlign.Center.AsOption().ToNullable())) |> ignore

    let table = section.AddTable().Font font
    
    let c1 = table.AddColumn(Util.Px(600.0))
    let c2 = table.AddColumn(Util.Px(600.0))
    
    let r1 = table.AddRow()
    let r2 = table.AddRow()
    let r3 = table.AddRow()
    let r4 = table.AddRow()    
    let r5 = table.AddRow()

    r1.[c1].Add(Paragraph().Add("Имя:")) |> ignore
    r1.[c2].Add(Paragraph().Add(teacher.Name)) |> ignore

    r2.[c1].Add(Paragraph().Add("Фамилия:")) |> ignore
    r2.[c2].Add(Paragraph().Add(teacher.LastName)) |> ignore

    r3.[c1].Add(Paragraph().Add("Отчество:")) |> ignore
    r3.[c2].Add(Paragraph().Add(teacher.Surname)) |> ignore

    r4.[c1].Add(Paragraph().Add("Телефон:")) |> ignore
    r4.[c2].Add(Paragraph().Add(teacher.Phone)) |> ignore

    r5.[c1].Add(Paragraph().Add("Факультет:")) |> ignore
    r5.[c2].Add(Paragraph().Add(teacher.Faculty)) |> ignore

    document

Now for the display, I'm more comfortable using WPF, link to the
Gjallarhorn.Bindable manual and library .
For each type, we create our own UserControl , which will be responsible for data entry.
Each display is defined as a navigation state:
[<RequireQualifiedAccess>]
type NavMessages = 
    | Student
    | Teacher
    | Enrollee

work with each type will be moved to separate child components (StudentComponent, ...). You can define your own validation rule for each property.
let appComp =
    Component.create<AppModel, NavMessages, Messages> [
        <@ ctx.Model.Student @> |> Bind.comp (fun m -> m.Student) studentComp fst
        <@ ctx.Model.Enrollee @> |> Bind.comp (fun m -> m.Enrollee) enrolleeComp fst
        <@ ctx.Model.Teacher @> |> Bind.comp (fun m -> m.Teacher) teacherComp fst
                        
        <@ ctx.Model.Menu @> |> Bind.comp (fun m -> m.Menu) menuComponent fst
    
        <@ ctx.SendReport @> |> Bind.cmd
    ]

The SendReport team will be responsible for creating a report and sending it to the mail. The button will be active only if all fields are filled without errors.
It remains to define the function for updating the application model:
let upd (nav : Dispatcher<NavMessages>) message model = 
    match message with
    | Messages.SendReport ->
        let v, m = 
            match model.Menu.Current with
            | NavMessages.Enrollee -> 
                AccountType.Enrollee model.Enrollee, { model with Enrollee = Defaults.enrollee }
            | NavMessages.Student -> 
                AccountType.Student model.Student, { model with Student = Defaults.student }
            | NavMessages.Teacher -> 
                AccountType.Teacher model.Teacher, { model with Teacher = Defaults.teacher }
        v
        |> PdfReport.createReport
        |> PdfReport.saveReport "test.pdf"
        |> PdfReport.sendReport
        m
    | Messages.SetCurrent current ->
        current |> nav.Dispatch
        { model with Menu = { model.Menu with Current = current }}
    | Messages.UpdateEnrollee msg ->
        { model with Enrollee = EnrolleeComponent.update model.Enrollee msg }
    | Messages.UpdateStudent msg ->
        { model with Student = StudentComponent.update model.Student msg }
    | Messages.UpdateTeacher msg ->
        { model with Teacher = TeacherComponent.update model.Teacher msg }

open Gjallarhorn.Bindable.Framework

let applicationCore nav =
    let navigation = Dispatcher<NavMessages>()
    Framework.application init (upd navigation) appComp nav
    |> Framework.withNavigation navigation

To work with mail, you will need to specify the data from which you want to send a letter. How to do it is written here .
Now, to add a new type, you will need to do the following:
1. Define an entry for the new object that describes its properties.
2. Create a function that generates a report for this type.
3. Create a component.
4. Create a user control to display.
5. Add it to the general program model.
The result is the following:
As soon as the report has been sent, the record is reset to the default value.
To demonstrate that the forms can be arbitrary, I displayed a message with short information about whom the data is being filled at the moment.
In this example, such a pdf was written:
I didn’t give the whole code, since it is quite voluminous, if you are interested in this option, I can put it on github.
Just keep in mind that a sketch can be done in a couple of hours, and it will take much longer to bring it to mind.

K
Konstantin Tsvetkov, 2019-03-04
@tsklab

MS Word, "Mailouts".

100 students / teachers at the same time and let them fill in their data and send
Create and distribute PDF forms .

L
LuckyRuS, 2019-03-08
@LuckyRuS

Foggy Finder "Once the report has been submitted, the record is reset to default"
Is it just generating a PDF or is it immediately sent to the mail? The answer is perfect, if I show this, then 4-ku is provided to me right away in a year! Thanks to!

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question