These two days want to write a small program, is in C # operation Word document. Many people are very pessimistic about Microsoft's own solution COM components, such as the need to install Office and so on, in short, a lot of spit, give up directly.
Found a home-made Npoi library, is said to operate simple powerful, download trial, the discovery operation Excel is good, but Word does not work. and the official website documentation is not complete, updated slowly.
try text substitution, always error. added the official group, asked questions, no one responded.
Online and find, found a spire library is good, there are free DLLs can be used. (review: This is a free and powerful C # Word component that does not require word automatio to run, and any third-party functionality is included)
Try it out, it's a very simple and successful solution to my problem.
The code is as follows:
private void Button1_Click (object sender, EventArgs e) { var doc = new Document (); Doc. LoadFromFile ("D:\\ht.docx"); Doc. Replace ("[< unit name;]", Tbdwmc.text, False, false); Doc. Replace ("[< Bank", Tbkhh.text, False, false); Doc. Replace ("[< bank account;]", Tbyhzh.text, False, false); Doc. Replace ("[< unit address;]", Tbaddress.text, False, false); Doc. Replace ("[< unit phone;]", Tbtel.text, False, false); var guid = Guid.NewGuid (). ToString (); Doc. SaveToFile ("s" + GUID + ". docx", fileformat.docx); Doc. Close (); Process.Start ("s" + GUID + ". docx"); }
A trivial thing to do:
It was late at night, and finally someone spoke in the Npoi official group. See a buddy said Npoi bad use, I took a word that has changed spire. At this time is estimated to be stimulated to the Npoi group, impressively show up, first said in the group asked questions do not pay the money with whom you, then point out my problem is not enough IQ. I quickly respond: curse is not Jieduan, IQ your mother forced oh.
In fact, programmers are supposed to pay for their hard work. Writing something is not easy, waist sore neck, charge this point I very much agree. but your official group, is not to let users communicate? Ask a question, just beg a person, give a direction or keyword what is enough. You are the mother to talk about money, hurt feelings do not say, the point is-unexpectedly by this grandson to see my IQ is not high, is too embarrassed.
Later, I was kicked. Wish Npoi continue to flourish.
links to Spire are attached: https://freeword.codeplex.com/
Use C # to replace characters with Word, instead of npoi, use spire