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/>}