It was a weekend. When I got home, my parents were prepared and happy. But Yuki was still very busy. It turned out to be a very tedious job, organizing a 1600-row Excel table into Word documents, ft. Isn't that a waste? It takes more than 10 hours every 30 seconds. What is this? To reduce the workload, let me tell you this. So I made a program based on this. 1. Import the Excel table into the database; 2. Read the Excel table data and write each entry into the word document in the specified format. Specifically: 1. create a console program C # in Visual Studio 2003. add an office COM component reference, including Microsoft Word 11.0 Object Library (InterOP. word), Microsoft Office 11.0 Object Library (Microsoft InterOP core), of course, the premise is that the installation of office2003; 3. call the Word template to create a temporary Word document, mainly using word. application and word. document; 4. write content according to the format, mainly using word. paragraph and opara1.range. font. 5. The label concept is used when writing to the word, that is, to insert text from this place, which needs to be pre-set through the menu item "insert-bookmarks" when the dot template is created. It took two and a half hours for the code to run and the Final Word documents were as long as 440 pages. It can be seen that this job was not done by humans. I'm very happy. The core code is as follows: --------------------- how to create a Word document -------------------------- // <summary> /// Open the Word document and return the wdoc and wdoc objects. /// </Summary> /// <Param name = "FILENAME"> complete Word file path + name </param> /// <Param name = "wdoc"> the returned word. Document wdoc object </param> /// <Param name = "wapp"> returned word. Application Object </param> Public static void createworddocument (string filename, ref word. Document wdoc, ref Word. Application wapp)
{
If (filename = "") return;
Word. Document thisdocument = NULL;
Word. formfields Formfields = NULL;
Word. Application thisapplication = new word. applicationclass ();
Thisapplication. Visible = true;
Thisapplication. Caption = "";
Thisapplication. Options. checkspellingasyoutype = false;
Thisapplication. Options. checkgrammarasyoutype = false; Object filename = filename;
Object confirmconversions = false;
Object readonly = true;
Object addtorecentfiles = false; Object passworddocument = system. type. missing;
Object passwordtemplate = system. type. missing;
Object revert = system. type. missing;
Object writepassworddocument = system. type. missing;
Object writepasswordtemplate = system. type. missing;
Object format = system. type. missing;
Object encoding = system. type. missing;
Object visible = system. type. missing;
Object openandrepair = system. type. missing;
Object documentdirection = System. type. missing;
Object noencodingdialog = system. type. missing;
Object xmltransform = system. type. missing; Try
{
Word. Document worddoc =
Thisapplication. Documents. Open (ref filename, ref confirmconversions,
Ref readonly, ref addtorecentfiles, ref passworddocument, ref passwordtemplate,
Ref revert, ref writepassworddocument, ref writepasswordtemplate, ref format,
Ref encoding, ref visible, ref openandrepair, ref documentdirection,
Ref noencodingdialog, ref xmltransform );
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.