Yongzhong office secondary development _ Java Secondary Development 1

Source: Internet
Author: User

Overview: yongzhong office is developed using Java, so it is convenient to directly use Java for secondary development. However, it is generally called using VB and VC during client running, therefore, it is necessary to encapsulate it into COM components for other languages to call.

 

Today, we will firstSome call instancesInstructions:

 

1. Create an empty document

Public static document createblankword () {<br/> application. getinstance (); <br/> application. gotoproduct (globalconstants. wordprocessor); <br/> workbook = application. getworkbooks (). getactiveworkbook (); <br/> application. setmainframestatus (globalconstants. mainframe_max); <br/> Windows = application. getwindows (); <br/> If (windows. getactivewindow ()! = NULL) <br/> Windows. getactivewindow (). setstate (globalconstants. mainframe_max); <br/> return Workbook. getdocuments (). getactivedocument (); <br/>}

2. Open the document

Public static document openword (string filename) {<br/> application. getinstance (); <br/> application. gotoproduct (globalconstants. wordprocessor); <br/> // workbook workbook1 = application. getworkbooks (). getactiveworkbook (); <br/> workbook = application. getworkbooks (). openworkbook (filename); <br/> // workbook1.close (); <br/> application. setmainframestatus (globalconstants. mainframe_max); <br/> return workbook. getdocuments (). getactivedocument (); <br/>}

3. Close the document

Public static Boolean closeword () <br/>{< br/> application. exitsystem (); <br/> return true; <br/>}

4. Add bookmarks

Public static Boolean addbookmarktodocument (document, string bookmarkname) <br/>{< br/> document. getbookmarks (). add (document. getrange (document. getoffset (), bookmarkname); </P> <p> return true; <br/>}

5. Modify bookmarks

Public static Boolean changbookmarktext (document, string bookmarkname, string text) <br/>{< br/> bookmark BK = document. getbookmarks (). get (bookmarkname); <br/> Boolean needreturn = false; <br/> If (BK = NULL) <br/> return false; <br/> If (BK. getvalue (). length () = 0 | BK. getvalue (). equals ("/N") // empty bookmarks and bookmarks that only contain line breaks must be followed by line breaks <br/>{< br/> needreturn = true; <br/>}< br/> long start = BK. getstartposition (); <br/> BK. setvalue (text); <br/> BK. setstartposition (start); <br/> BK. setendposition (start + text. length (); </P> <p> If (needreturn) <br/> document. getsection (0 ). getbasetext (). inserttext (start + text. length (), "/N"); </P> <p> return true; <br/>}

6. output text

Public static Boolean settextrangestyle (textrange range, string fontname, double fontsize, Boolean isbold) <br/>{< br/> fontattribute ATTR = range. getfontattribute (); <br/> ATTR. setfontname (fontname); <br/> ATTR. setfontsize (fontsize); <br/> ATTR. setbold (isbold); <br/> range. setfontattribute (ATTR); </P> <p> return true; <br/>}

7. Obtain the shape text content.

Public static string getshapetext (string shapename) <br/>{< br/> shape = application. getworkbooks (). getactiveworkbook (). getactiveshapes (). getshape (shapename); <br/> If (shape = NULL) <br/> return ""; <br/> return shape. getshapetext (). gettext (); <br/>}

8. Set the shape text content

Public static Boolean setshapetext (string shapename, string text) <br/>{< br/> shape = application. getworkbooks (). getactiveworkbook (). getactiveshapes (). getshape (shapename); <br/> If (shape = NULL) <br/> return false; </P> <p> shape. getshapetext (). clearall (); <br/> shape. getshapetext (). inserttext (text); </P> <p> return true; <br/>}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.