006 C ා automatic generation of information card

Time:2020-9-30

Hey,How are you doing?

2020 is both an opportunity and a challenge for me.

The so-called challenge means that the system course of C ා realizing office automation is almost blank.

The so-called opportunity refers to the possibility of becoming the first person of C ා office automation.

006 C ා automatic generation of information card

I’m not a professional farmer. I don’t have much project experience.

Fortunately, the daily office is exposed to a lot of highly repetitive work.

My goal is very clear, that is to achieve automation of repetitive work through C ා.

Maybe, unlike many people, I’m not following python.

006 C ා automatic generation of information card

C / C + +, the big guys are usually used in the fields of operating system, hardware bottom and so on.

Python focuses on artificial intelligence.

Because of VBA, Python is not the most suitable tool for office automation.

Java was born in 1995 and C in 2002,

Java and C ා belong to C-system language, but C ා is simpler and easier to learn than Java.

If you’re looking for a job, you can learn Java.

Our goal is to automate repetitive work,

Using C ා, you can get off work earlier.

I’m not very good at it. I studied VBA for 2 months and didn’t go on to further study.

A little understanding of some basic grammar, I feel that this is actually enough.

Through a brief study, I know that VBA realizes office automation through COM components.

In fact, I can also achieve office automation with C ා.

It is with such a broken idea that I opened a new hole [workplace coding],

Committed to contributing some small white workplace skills to improve efficiency.

To tell you the truth, after learning VBA for two months, I have already learned how to use sub + end sub,

With + end with has a dependency.

VBA is so easy to use. At that time, I didn’t look at C ා.

At the end of January 2020, I started to study C ා. From the basic grammar, I saw the latest features,

After nearly four months of running in, I found that,

I fell in love with the elegant {curly brackets} and [index].

The former can quickly distinguish code blocks without having to worry about indenting with a vernier caliper.

The latter can quickly refer to an object without being confused with the object’s (method).

The COM component I mentioned above refers to:

  • Microsoft.Office.Interop.Word;
  • Microsoft.Office.Interop.Excel;
  • Microsoft.Office.Interop.Powerpoint;

Of course, there are other components, such as access, publisher, Visio, etc.

Because the basic daily contact is the office of the three big pieces.

In the future, I will open a special topic to explain other components in detail.

We are technical articles. Typesetting is not the most important thing.

Usually, tweets are mainly technical. If you can’t read it, you can’t understand it,

Or I don’t write clearly enough. Please contact me by private message.

Next, let’s take a look at how to automatically generate information cards.

006 C ා automatic generation of information card

According to the operation diagram, we can know that we only need to write the Excel data into the word template.

First of all, I will create an information card template in word and put it in the folder ~ C003 / bin / debug \.

Next, I used sharp develop to create a console application.

General idea: observe that there are 10 pieces of data ready to be written in Excel,

Then I will copy 9 copies of the word template, and then use the code loop to write it.

001 preparatory work

006 C ා automatic generation of information card

Daily reference word / Excel, System.Runtime.InteropServices Kill process dedicated space.

002 start work

006 C ා automatic generation of information card

  • General operation: declare, visible, define and open word / excel.
  • Create a table: control the number of cycles through mxr-2, Wdc.Tables.Count Calculate the number of tables.
  • Data writing: via Wdc.Tables [].Cell(). Range.Text=Eap .Worksheets[].Cells(). value.ToString () to write data.

003 finishing work

006 C ා automatic generation of information card

By defining kill method, call kill method to realize excel process termination.

The following is the source map, if you also want to learn in depth, reply to the source code for your reference.

006 C ා automatic generation of information card

———— The End ————