WebOffice.js 139 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666
  1. window.console = window.console || (function() {
  2. var c = {}
  3. c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function() {
  4. }
  5. return c
  6. })()
  7. function base64toBlob(base64Data, contentType) {
  8. contentType = contentType || ''
  9. var sliceSize = 1024
  10. var byteCharacters = atob(base64Data)
  11. var bytesLength = byteCharacters.length
  12. var slicesCount = Math.ceil(bytesLength / sliceSize)
  13. var byteArrays = new Array(slicesCount)
  14. for (var sliceIndex = 0; sliceIndex < slicesCount; ++sliceIndex) {
  15. var begin = sliceIndex * sliceSize
  16. var end = Math.min(begin + sliceSize, bytesLength)
  17. var bytes = new Array(end - begin)
  18. for (var offset = begin, i = 0; offset < end; ++i, ++offset) {
  19. bytes[i] = byteCharacters[offset].charCodeAt(0)
  20. }
  21. byteArrays[sliceIndex] = new Uint8Array(bytes)
  22. }
  23. return new Blob(byteArrays, { type: contentType })
  24. }
  25. function WebOffice2015() {
  26. this.SaveServlet = ''
  27. this.ServerUrl = 'ServerUrl'
  28. this.dVersion = '5.0.0.12'
  29. this.dUpdateDate = '2019-05-22'
  30. //高级功能:全文检索、文档对比
  31. // *****************************************************************************************************************************
  32. // 内部变量和方法
  33. this.PASSWORD = '123456'
  34. var ISO // 服务器返回值
  35. var root
  36. var rootValue
  37. this.Ashell = null
  38. this.BookMark = '' // 书签名称
  39. this.ImageName = '' // 图片名称
  40. this.obj // Office控件对象,可直接调用控件接口及属性
  41. this.DownloadedFileTempPathName = '' // 下载保存的临时文件路径名
  42. this.DOWN = '\\WebOffice\\Down\\' // 指定隐藏路径并设置名称
  43. this.UP = '\\WebOffice\\UP\\' // 指定隐藏路径并设置名称
  44. this.FilePath = null // 文档路径
  45. this.TmpFile = null // 临时下载的文档名称(含完整路径)
  46. this.tempInsertName = '' // 插入文件的文件名称
  47. this.DocTypeValue = {
  48. DOC: 0,
  49. DOCX: 16,
  50. XLS: 56,
  51. XLSX: 51,
  52. WPS: 0,
  53. ET: 56,
  54. PDF: 41,
  55. OFD: 42
  56. } // 枚举所有的文档类型值用户保存用
  57. this.DocSuffixType = {
  58. 0: '.doc',
  59. 12: '.docx',
  60. 56: '.xls',
  61. 51: '.xlsx',
  62. 0: '.wps',
  63. 56: '.et',
  64. 41: '.pdf',
  65. 42: '.ofd'
  66. } // 根据打开文档类型,来获取后缀名称
  67. this.setVersion = -1 // Office版本号
  68. this.OfficeVersion = {
  69. v2003: 1,
  70. vOther: 0
  71. } // 判断Office版本,这个只要用于保存到本地
  72. this.sendMode = null // 设置异步调用模式
  73. this.iWebOfficeTempName = 'iWebOfficeTempName.doc'
  74. // *****************************************************************************************************************************
  75. // *****************************************************************************************************************************
  76. // 对外公共属性
  77. this.WebUrl = '' // 服务器应用程序Url路径
  78. this.getResultJson = '' // 服务器应用程序Url路径
  79. this.RecordID = '' // 文档的纪录号
  80. this.Template = '' // 模板编号
  81. this.SingleFileName = ''
  82. this.FileName = '' // 文档名称
  83. this.UserName = '' // 操作文档用户名
  84. this.OfficeUserName = '' // 记录本地office用户名
  85. this.FileType = '' // 文档类型 .doc .xls .wps
  86. this.EditType = '' //文档编辑类型
  87. this.DataBase = ''
  88. this.WebObject = null // 设置WebObject对象,方便调用VBA 方法()
  89. // 设置是否显示整个控件工具栏,包括OFFICE的工具栏
  90. // 0 : 自定义工具栏=false, Office工具栏=true;
  91. // 1 : 自定义工具栏=true, Office工具栏=true;
  92. // 2 : 自定义工具栏=false, Office工具栏=false;
  93. // 3 : 自定义工具栏=true, Office工具栏=false;
  94. this.ShowToolBar = 1 //
  95. this.CopyType = '1' // 设置拷贝类型 "1": 允许拷贝 "0": 禁止拷贝
  96. // 该属性控制的是操作系统的粘贴板,一旦设置为禁止拷贝则整个操作系统的拷贝也被禁止。
  97. this.ShowMenu = '1' // 设置是否显示整个菜单 "1": 显示菜单 "0": 不显示菜单
  98. this.Status = '' // Status:状态信息
  99. // “工具栏空间”即当所有OFFICE工具栏都隐藏时控件故意产生一个灰色条占住空间,在OFFICE2000、2003下有此功能
  100. this.MaxFileSize = 8 * 1024 // 设置文件最大允许值,单位k,默认为8M
  101. this.ShowWindow = true // 设置是否显示保存及打开窗口 True: 显示 False: 不显示
  102. // 设置为显示,在打开文档和保存文档时会出现进度窗口
  103. this.RibbonUIXML = '' // 用来详细设置Office2007选项卡工具界面
  104. this.UIControl = false // 控制OFFICE2010环境中是否可以使用另存为和保存功能,用于控制客户使用自定义快捷键和快捷工具栏的另存为功能下载文件
  105. this.HiddenDirectory = false // 是否开启将文档保存在隐藏目录中 true:开启 false: 不开启 默认:false
  106. this.DelFileAfterSave = true // 保存文档后删除该目录中的文档 true:删除 false:不删除 默认:true
  107. this.Charset = true //后台数据编码,true为utf-8编码,false为gb2312编码
  108. // ******************************************************************************************************************************
  109. // ******************************************************************************************************************************//
  110. // ---------------------------------------------------对外接口-------------------------------------------------------------------//
  111. // 设置浏览器Cookie
  112. this.INetSetCookie = function(url, cookie) {
  113. this.obj.INetSetCookie(url, cookie)
  114. }
  115. // 设置控件标题
  116. this.SetCaption = function(captionName) {
  117. this.obj.Caption = captionName// this.Caption;
  118. }
  119. this.GetFileType = function(downloadLink) {
  120. var filename = downloadLink
  121. var index1 = filename.lastIndexOf('.')
  122. var index2 = filename.length
  123. var postf = filename.substring(index1, index2)//后缀名
  124. this.FileType = postf
  125. }
  126. this.GetSingleFileName = function(downloadLink) {
  127. var filename = downloadLink
  128. var index1 = filename.lastIndexOf('/')
  129. var index2 = filename.length
  130. var postf = filename.substring(index1 + 1, index2)//后缀名
  131. this.SingleFileName = postf
  132. }
  133. this.WebOpen2 = function(downloadLink) {
  134. this.Status = '成功'
  135. var httpclient = this.obj.Http // 设置http对象
  136. this.FileName = downloadLink
  137. this.GetFileType(downloadLink)
  138. this.GetSingleFileName(downloadLink)
  139. if (httpclient.Open(this.HttpMethod.Get, this.ServerUrl + downloadLink, false)) {
  140. if (httpclient.Send()) {
  141. if (this.hiddenSaveLocal(httpclient, this, false, false)) {
  142. var mSaveResult = this.WebOpenLocalFile(this.DownloadedFileTempPathName)
  143. if (mSaveResult == 0) { // 打开本地磁盘文件
  144. this.getOfficeVersion()// 打开文档后,判断当前office版本
  145. return true
  146. } else if (mSaveResult == 1) {
  147. var windows = window.confirm('可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)'
  148. + '\r\r单击“确定”关闭。单击“取消”继续。')
  149. this.Status = '可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)'
  150. if (windows == 1) {
  151. window.close()
  152. return false
  153. }
  154. } else if (mSaveResult == 2) {
  155. var windows = window.confirm('没有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确'
  156. + '\r\r单击“确定”关闭。单击“取消”继续。')
  157. this.Status = '有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确'
  158. if (windows == 1) {
  159. window.close()
  160. return false
  161. }
  162. } else if (mSaveResult == 3) {
  163. var windows = window.confirm('没有权限导致文档打开失败,请用管理员身份运行浏览器后重试'
  164. + '\r\r单击“确定”关闭。单击“取消”继续。')
  165. this.Status = '没有权限导致文档打开失败,请用管理员身份运行浏览器后重试'
  166. if (windows == 1) {
  167. window.close()
  168. return false
  169. }
  170. } else if (mSaveResult == 4) {
  171. var windows = window.confirm('文件可能损坏,请确定服务器文档是否已经损坏'
  172. + '\r\r单击“确定”关闭。单击“取消”继续。')
  173. this.Status = '文件可能损坏,请确定服务器文档是否已经损坏'
  174. if (windows == 1) {
  175. window.close()
  176. return false
  177. }
  178. } else if (mSaveResult == 5) {
  179. var windows = window.confirm('未安装Office或者注册表有损坏'
  180. + '\r\r单击“确定”关闭。单击“取消”继续。')
  181. this.Status = '未安装Office或者注册表有损坏'
  182. if (windows == 1) {
  183. window.close()
  184. return false
  185. }
  186. } else if (mSaveResult == 6) {
  187. var windows = window.confirm('文件被占用,请结束Office进程后重试'
  188. + '\r\r单击“确定”关闭。单击“取消”继续。')
  189. this.Status = '文件被占用,请结束Office进程后重试'
  190. if (windows == 1) {
  191. window.close()
  192. return false
  193. }
  194. } else {
  195. var windows = window.confirm('打开文档时未知错误!错误码为: '
  196. + mSaveResult
  197. + '\r\r单击“确定”关闭。单击“取消”继续。')
  198. this.Status = '打开文档时未知错误!错误码为: '
  199. + mSaveResult
  200. if (windows == 1) {
  201. window.close()
  202. return false
  203. }
  204. }
  205. } else {
  206. // 失败后,this.Status的值由hiddenSaveLocal返回
  207. this.Status = '保存文档到本地 失败'
  208. return false
  209. }
  210. }
  211. }
  212. }
  213. this.WebOpen3 = function(downloadLink) {
  214. this.Status = '成功'
  215. var httpclient = this.obj.Http // 设置http对象
  216. this.ShowMenuBar(this.ShowMenu) //控制菜单栏是否可以显示
  217. this.NewShowToolBar(this.ShowToolBar) //控制Office工具栏和自定义工具栏
  218. this.GetFileType(this.FileName)
  219. this.GetSingleFileName(this.FileName)
  220. //alert("want to download: " + downloadLink);
  221. if (httpclient.Open(this.HttpMethod.Get, downloadLink, false)) {
  222. if (httpclient.Send()) {
  223. if (this.hiddenSaveLocal(httpclient, this, false, false)) {
  224. var mSaveResult = this.WebOpenLocalFile(this.DownloadedFileTempPathName)
  225. if (mSaveResult == 0) { // 打开本地磁盘文件
  226. this.getOfficeVersion()// 打开文档后,判断当前office版本
  227. return true
  228. } else if (mSaveResult == 1) {
  229. var windows = window.confirm('可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)'
  230. + '\r\r单击“确定”关闭。单击“取消”继续。')
  231. this.Status = '可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)'
  232. if (windows == 1) {
  233. window.close()
  234. return false
  235. }
  236. } else if (mSaveResult == 2) {
  237. var windows = window.confirm('没有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确'
  238. + '\r\r单击“确定”关闭。单击“取消”继续。')
  239. this.Status = '有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确'
  240. if (windows == 1) {
  241. window.close()
  242. return false
  243. }
  244. } else if (mSaveResult == 3) {
  245. var windows = window.confirm('没有权限导致文档打开失败,请用管理员身份运行浏览器后重试'
  246. + '\r\r单击“确定”关闭。单击“取消”继续。')
  247. this.Status = '没有权限导致文档打开失败,请用管理员身份运行浏览器后重试'
  248. if (windows == 1) {
  249. window.close()
  250. return false
  251. }
  252. } else if (mSaveResult == 4) {
  253. var windows = window.confirm('文件可能损坏,请确定服务器文档是否已经损坏'
  254. + '\r\r单击“确定”关闭。单击“取消”继续。')
  255. this.Status = '文件可能损坏,请确定服务器文档是否已经损坏'
  256. if (windows == 1) {
  257. window.close()
  258. return false
  259. }
  260. } else if (mSaveResult == 5) {
  261. var windows = window.confirm('未安装Office或者注册表有损坏'
  262. + '\r\r单击“确定”关闭。单击“取消”继续。')
  263. this.Status = '未安装Office或者注册表有损坏'
  264. if (windows == 1) {
  265. window.close()
  266. return false
  267. }
  268. } else if (mSaveResult == 6) {
  269. var windows = window.confirm('文件被占用,请结束Office进程后重试'
  270. + '\r\r单击“确定”关闭。单击“取消”继续。')
  271. this.Status = '文件被占用,请结束Office进程后重试'
  272. if (windows == 1) {
  273. window.close()
  274. return false
  275. }
  276. } else {
  277. var windows = window.confirm('打开文档时未知错误!错误码为: '
  278. + mSaveResult
  279. + '\r\r单击“确定”关闭。单击“取消”继续。')
  280. this.Status = '打开文档时未知错误!错误码为: '
  281. + mSaveResult
  282. if (windows == 1) {
  283. window.close()
  284. return false
  285. }
  286. }
  287. } else {
  288. // 失败后,this.Status的值由hiddenSaveLocal返回
  289. this.Status = '保存文档到本地 失败'
  290. return false
  291. }
  292. }
  293. }
  294. }
  295. /* 从服务器上取文档并打开,打开RecordID指定的文件 */ //该功能已完整实现
  296. this.WebOpen = function(mBoolean) {
  297. this.Status = '成功'
  298. var httpclient = this.obj.Http // 设置http对象
  299. httpclient.Clear()
  300. this.GetSingleFileName(this.FileName)
  301. this.WebSetMsgByName('USERNAME', this.UserName) // 加载UserName
  302. this.WebSetMsgByName('FILENAME', this.FileName) // 加载FileName
  303. this.WebSetMsgByName('FILETYPE', this.FileType) // 加载FileType
  304. this.WebSetMsgByName('RECORDID', this.RecordID) // 加载RecordID
  305. this.WebSetMsgByName('EDITTYPE', this.EditType) // 加载RecordID
  306. this.WebSetMsgByName('DATABASE', this.DataBase) // 加载数据库
  307. this.WebSetMsgByName('OPTION', 'LOADFILE') // 发送请求LOADFILE
  308. httpclient.AddForm('FormData', this.GetMessageString()) // 这里是自定义json
  309. // 传输格式。
  310. this.WebClearMessage() // 清除所有WebSetMsgByName参数
  311. this.sendMode = 'OpenFile'
  312. this.ShowMenuBar(this.ShowMenu) //控制菜单栏是否可以显示
  313. this.NewShowToolBar(this.ShowToolBar) //控制Office工具栏和自定义工具栏
  314. if (this.LOADFILE(httpclient)) // Http下载服务器文件
  315. {
  316. this.NewCopyType(this.CopyType) // 控制是否可以复制
  317. this.NewUIControl(this.UIControl) // 控制 2010保存跟另存为
  318. if (this.FileType != '.ppt' && this.FileType != '.pptx' && this.FileType != '.pdf' && this.FileType != '.ofd') {
  319. this.VBASetUserName(this.UserName) // 设置Office用户名
  320. this.setEditType(this.EditType) // 设置文档编辑权限 0 、只读不能复制 1、无痕迹打开 2、有痕迹打开
  321. }
  322. this.Status = '打开文档成功' // Status:状态信息
  323. return true
  324. } else {
  325. //this.Status = "打开文档失败"; // Status:状态信息 由This.LOADFILE返回
  326. return false
  327. }
  328. }
  329. /* 从服务器上取文档并打开,打开RecordID指定的文件 */ //该功能已完整实现
  330. this.WebOpenBase64 = function() {
  331. var jsWebOffice = this
  332. var officeobj = this.obj
  333. var filename = this.FileName
  334. var tmpDownPath = this.DownFilePath()
  335. var send = 'OPTION=LOADFILE&FILENAME=' + this.FileName + '&FILETYPE=' + this.FileType + '&RECORDID=' + this.RecordID + '&EDITTYPE=' + this.EditType
  336. /* $.post("../../AJAXServer", send, function(data) {
  337. console.log(data);
  338. });*/
  339. $.ajax({
  340. type: 'POST',
  341. url: '../../AJAXServer',
  342. data: send,
  343. cache: false,
  344. processData: false,
  345. xhr: function() { //这是关键 获取原生的xhr对象 做以前做的所有事情
  346. console.log('xhr function eee')
  347. var xhr = jQuery.ajaxSettings.xhr()
  348. console.log(xhr)
  349. xhr.onprogress = function(evt) {
  350. if (evt.lengthComputable) {
  351. var percentComplete = evt.loaded / evt.total
  352. console.log(percentComplete)
  353. }
  354. }
  355. return xhr
  356. },
  357. success: function(data) {
  358. //console.log(data);
  359. var filePathName = tmpDownPath
  360. filePathName += '\\'
  361. filePathName += filename
  362. officeobj.Base64Text2File(data, filePathName)
  363. jsWebOffice.WebOpenLocalFile(filePathName)
  364. }
  365. })
  366. return true
  367. }
  368. this.WebSave2 = function(callback) {
  369. var rands = Math.round(Math.random() * 1000000)
  370. var fileUpPathName = this.getFilePath() + rands + this.FileName
  371. //alert(fileUpPathName);
  372. var mSaveResult = this.WebSaveLocalFile(fileUpPathName)
  373. if (!(mSaveResult == 0)) {
  374. this.Status = '保存本地文档失败!错误代码为:' + mSaveResult
  375. return false
  376. } else {
  377. // alert("文档没有内容,是否确定保存");
  378. }
  379. var jsWebOffice = this
  380. var officeobj = this.obj
  381. var filename = this.FileName
  382. var base64file = officeobj.File2Base64Text(fileUpPathName)
  383. var formData = new FormData()
  384. var timestamp1 = new Date().getTime()
  385. var myfff = base64toBlob(base64file)
  386. var timestamp2 = new Date().getTime()
  387. //alert(myfff);
  388. formData.append('FileData', myfff, 'myFileName')
  389. var aaa = '${pageContext.request.contextPath}'
  390. var strUrl = jsWebOffice.WebUrl + '/AJAXServer?OPTION=MultiPartUpload&FILENAME=' + filename
  391. $.ajax({
  392. //url: '${pageContext.request.contextPath}/AJAXServer?OPTION=MultiPartUpload',
  393. url: strUrl,
  394. type: 'POST',
  395. data: formData,
  396. contentType: false,
  397. cache: false,
  398. processData: false,
  399. xhr: function() { //这是关键 获取原生的xhr对象 做以前做的所有事情
  400. console.log('xhr function')
  401. var xhr = jQuery.ajaxSettings.xhr()
  402. console.log(xhr)
  403. xhr.upload.onprogress = function(evt) {
  404. if (evt.lengthComputable) {
  405. var percentComplete = evt.loaded / evt.total
  406. console.log(percentComplete)
  407. //callback(0);
  408. }
  409. }
  410. return xhr
  411. },
  412. success: function(data, textStatus) {
  413. console.log('success')
  414. console.log('textStatus: ' + textStatus)
  415. console.log('data: ' + data)
  416. callback(0)
  417. },
  418. error: function(XMLHttpRequest, textStatus, errorThrown) {
  419. console.log('essor')
  420. console.log(XMLHttpRequest)
  421. console.log('textStatus: ' + textStatus)
  422. console.log('errorThrown: ' + errorThrown)
  423. callback(1)
  424. }
  425. })
  426. return true
  427. }
  428. this.WebSaveBase64 = function() {
  429. //alert("this.FileName = " + this.FileName);
  430. var rands = Math.round(Math.random() * 1000000)
  431. var fileUpPathName = this.getFilePath() + rands + this.FileName
  432. var mSaveResult = this.WebSaveLocalFile(fileUpPathName)
  433. if (!(mSaveResult == 0)) {
  434. this.Status = '保存本地文档失败!错误代码为:' + mSaveResult
  435. return false
  436. } else {
  437. // alert("文档没有内容,是否确定保存");
  438. }
  439. var jsWebOffice = this
  440. var officeobj = this.obj
  441. var filename = this.FileName
  442. var base64file = officeobj.File2Base64Text(fileUpPathName)
  443. //alert(base64file);
  444. var newBase64 = base64file.replace(/\+/g, '%2B')
  445. //alert(newBase64);
  446. //创建XMLHttpRequest对象
  447. if (window.XMLHttpRequest) {
  448. //针对FireFox,Mozillar,Opera,Safari,IE7,IE8
  449. xmlhttp = new XMLHttpRequest()
  450. //对某些特定版本的mozillar浏览器的bug进行修正
  451. if (xmlhttp.overrideMineType) {
  452. xmlhttp.overrideMineType('text/xml')
  453. }
  454. } else if (window.ActiveXObject) {
  455. //针对IE5,IE5.5,IE6
  456. //两个可以用于创建XMLHTTPRequest对象的控件名称。保存在一个JS数组中。
  457. var activexName = ['MSXML2.XMLHTTP', 'Microsoft.XMLHTTP']
  458. for (var i = 0; i < activeName.length; i++) {
  459. //取出一个控件名进行创建,如果成功就终止循环
  460. try {
  461. xmlhttp = new ActiveXObject(activexName[i])
  462. break
  463. } catch (e) {
  464. }
  465. }
  466. }
  467. if (xmlhttp) {
  468. // alert("XMLHttpRequest对象创建成功!");
  469. } else {
  470. //alert("XMLHttpRequest对象创建失败!");
  471. return false
  472. }
  473. var jsWebOffice = this
  474. var officeobj = this.obj
  475. var filename = this.FileName
  476. // xmlhttp.onreadystatechange = function()
  477. // {
  478. // //判断对象的状态是否交互完成
  479. // if(xmlhttp.readyState == 4)
  480. // {
  481. // //判断http的交互是否成功
  482. // if(xmlhttp.status == 200)
  483. // {
  484. // }
  485. //
  486. // }
  487. // };
  488. var postdata = 'OPTION=SAVEFILE&FILENAME=' + this.FileName + '&FILETYPE=' + this.FileType + '&RECORDID=' + this.RecordID + '&EDITTYPE=' + this.EditType
  489. + '&TEMPLATE=' + this.Template + '&SUBJECT=' + this.Subject + '&AUTHOR=' + this.Author + '&BASE64FILE=' + newBase64
  490. //alert("aaa.length = " + aaa.length);
  491. xmlhttp.open('POST', '../../AJAXServer?name=', false) // false 是同步
  492. //xmlhttp.setRequestHeader("Content-Length",aaa.length);
  493. xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') //POST 必须要写这句,GET不用写
  494. //发送数据,开始和服务器进行交互。
  495. //xmlhttp.send("OPTION=SAVEFILE&FILENAME="+this.FileName+"&FILETYPE="+this.FileType+"&RECORDID="+this.RecordID+"&EDITTYPE="+this.EditType
  496. // +"&TEMPLATE="+this.Template+"&SUBJECT="+this.Subject+"&AUTHOR="+this.Author+"&BASE64FILE="+newBase64);
  497. xmlhttp.send(postdata)
  498. this.Status = '成功将文档保存到服务器'
  499. return true
  500. }
  501. //todo
  502. //保存到服务器上
  503. this.WebSave2Servelt = function() {
  504. var httpclient = this.obj.Http // 设置http对象
  505. httpclient.Clear()
  506. var mSavePath = this.getFilePath() + Math.random() * 100000 + this.SingleFileName
  507. this.sendMode = 'SaveFile'
  508. // 判断本地文件是否大于指定的文件大小,如果大于不保存
  509. if (this.WebSetMaxFileSize(mSavePath)) {
  510. //alert(this.FilePath + this.SingleFileName);
  511. if (this.SAVEFILE(httpclient, mSavePath)) {
  512. var ISO = httpclient.status// 获取返回值
  513. if (ISO == 200) {
  514. alert('保存成功')
  515. }
  516. //this.Close();
  517. /* if (this.DelFileAfterSave)
  518. {
  519. this.ClearDirectory(); //清除临时文件
  520. }*/
  521. this.Status = '成功将文档保存到服务器'
  522. return true
  523. } else {
  524. //STATUS 由this.SAVEFILE返回
  525. return false
  526. }
  527. } else {
  528. this.Status = '保存失败:MaxFileSize只能允许保存:<' + this.MaxFileSize / 1024
  529. + '>' + 'M'
  530. return false
  531. }
  532. }
  533. /* 保存文件 */ //(该功能已完整实现)
  534. this.WebSave = function(header) {
  535. this.Status = ''
  536. var httpclient = this.obj.Http // 设置http对象
  537. httpclient.Clear()
  538. this.WebSetMsgByName('USERNAME', this.UserName)
  539. this.WebSetMsgByName('RECORDID', this.RecordID)
  540. this.WebSetMsgByName('TEMPLATE', this.Template)
  541. this.WebSetMsgByName('SUBJECT', this.Subject)
  542. this.WebSetMsgByName('AUTHOR', this.Author)
  543. this.WebSetMsgByName('HTMLPATH', this.HTMLPath)
  544. this.WebSetMsgByName('FILETYPE', this.FileType)
  545. this.WebSetMsgByName('OPTION', 'SAVEFILE')
  546. this.WebSetMsgByName('DATABASE', this.DataBase)
  547. this.WebSetMsgByName('FILENAME', this.FileName) // 加载FileName
  548. if (this.WebSetAllowEmpty()) {
  549. this.GetSingleFileName(this.FileName)
  550. var mSavePath = this.getFilePath() + Math.random() * 100000 + this.SingleFileName
  551. var mSaveResult = this.WebSaveLocalFile(mSavePath)
  552. if (!(mSaveResult == 0)) {
  553. this.Status = '保存本地文档失败!错误代码为:' + mSaveResult
  554. return false
  555. }
  556. } else {
  557. alert('文档没有内容,是否确定保存')
  558. }
  559. this.sendMode = 'SaveFile'
  560. // 判断本地文件是否大于指定的文件大小,如果大于不保存
  561. if (this.WebSetMaxFileSize(mSavePath)) {
  562. //alert(this.FilePath + this.SingleFileName);
  563. if (this.SAVEFILE(httpclient, mSavePath, header)) {
  564. var ISO = httpclient.status// 获取返回值
  565. //this.Close();
  566. /* if (this.DelFileAfterSave)
  567. {
  568. this.ClearDirectory(); //清除临时文件
  569. }*/
  570. this.Status = '成功将文档保存到服务器'
  571. return true
  572. } else {
  573. //STATUS 由this.SAVEFILE返回
  574. return false
  575. }
  576. } else {
  577. this.Status = '保存失败:MaxFileSize只能允许保存:<' + this.MaxFileSize / 1024
  578. + '>' + 'M'
  579. return false
  580. }
  581. }
  582. /* 关闭文档 */
  583. this.WebClose = function() {
  584. if (this.Close()) {
  585. return true
  586. }
  587. return false
  588. }
  589. /* 保存上传到服务器的数据*/
  590. this.WebSetMsgByName = function(FieldName, FieldValue) {
  591. this.ht.Add(FieldName, FieldValue)
  592. }
  593. /* 获取从服务器得到的数据*/
  594. this.WebGetMsgByName = function(FieldName) {
  595. return this.ht.Get(FieldName)
  596. }
  597. /* 按json格式发送数据 */ //
  598. this.WebSendMessage = function() {
  599. var httpclient = this.obj.Http // 设置http对象
  600. httpclient.Clear()
  601. this.WebSetMsgByName('OPTION', 'SENDMESSAGE')
  602. this.sendMode = 'SendMessage'
  603. httpclient.ShowProgressUI = this.ShowWindow
  604. httpclient.AddForm('FormData', this.GetMessageString())
  605. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) // true 异步方式 false同步
  606. {
  607. if (httpclient.Send()) {
  608. this.GetDataToSend() //得到服务器setMsgByName的值并发送到前台
  609. httpclient.Clear()
  610. this.Status = this.WebGetMsgByName('STATUS')
  611. return true
  612. } else {
  613. this.Status = this.WebGetMsgByName('STATUS')
  614. return false
  615. }
  616. } else {
  617. this.Status = '网络通信异常' //Status:状态信息
  618. return false
  619. }
  620. return this.ht.toString()
  621. }
  622. /* 清除由WebSetMsgByName设置的值 */
  623. this.WebClearMessage = function() {
  624. this.ht.Clear()
  625. }
  626. /* 保存为PDF文件并上传至服务器 */
  627. this.WebSavePDF = function() {
  628. var httpclient = this.obj.Http // 设置http对象
  629. httpclient.Clear()
  630. this.WebSetMsgByName('RECORDID', this.RecordID)
  631. this.WebSetMsgByName('OPTION', 'SAVEPDF')
  632. this.WebSetMsgByName('FILENAME', this.RecordID + '.pdf')// 加载FileName
  633. this.SaveAsPdf(this.getFilePath() + this.RecordID + '.pdf')
  634. if (this.SAVEFILE(httpclient, this.getFilePath() + this.RecordID + '.pdf')) {
  635. this.Status = '保存PDF文件成功'
  636. return true
  637. } else {
  638. this.Status = '保存PDF文件失败'
  639. return false
  640. }
  641. }
  642. /* 保存HTML到服务器 需要V12.4.0.450以上版本*/
  643. this.WebSaveAsHtml = function() {
  644. if (this.SaveAsHtml(this.getFilePath() + this.RecordID + '.html')) {
  645. var strDirPath = this.getFilePath() + this.RecordID + '.files' //获取html files路径
  646. var FindFile = this.obj.FileSystem.FindToDirAsFileEx(strDirPath)//获取html文件夹里的内容
  647. var DirPath = FindFile.split('\r\n')
  648. var httpclient = this.obj.Http // 设置http对象
  649. httpclient.Clear()
  650. this.WebSetMsgByName('RECORDID', this.RecordID)
  651. this.WebSetMsgByName('OPTION', 'SAVEHTML')
  652. this.WebSetMsgByName('DIRECTORY', this.RecordID + '.files')
  653. for (var i = 0; i < DirPath.length; i++) {
  654. var FilesName = DirPath[i]
  655. this.WebSetMsgByName('FILENAME', FilesName)// 加载FileName
  656. if (!this.SAVEFILE(httpclient, strDirPath + '\\' + FilesName)) {
  657. this.Status = '保存HTML文件失败'
  658. return false
  659. }
  660. }
  661. this.WebSetMsgByName('DIRECTORY', '') //作用吧html和files区分开
  662. this.WebSetMsgByName('FILENAME', this.RecordID + '.html')// 加载FileName
  663. if (this.SAVEFILE(httpclient, this.getFilePath() + this.RecordID + '.html')) {
  664. this.Status = '保存HTML文件成功'
  665. return true
  666. } else {
  667. this.Status = '保存HTML文件失败'
  668. return false
  669. }
  670. }
  671. this.Status = '保存HTML文件失败!'
  672. return false
  673. }
  674. /* 保存模板文件 */
  675. this.WebSaveTemplate = function() {
  676. this.Status = ''
  677. var httpclient = this.obj.Http //设置http对象
  678. httpclient.Clear()
  679. this.WebSetMsgByName('OPTION', 'SAVETEMPLATE')
  680. this.WebSetMsgByName('TEMPLATE', this.Template)
  681. var mSaveResult = this.WebSaveLocalFile(this.getFilePath() + this.FileName)
  682. if (!(mSaveResult == 0)) {
  683. this.Status = '保存本地文档失败!错误代码为:' + mSaveResult
  684. return false
  685. }
  686. this.sendMode = 'WebSaveTemplate'
  687. if (this.SAVEFILE(httpclient, this.FilePath + this.FileName)) {
  688. this.Status = '保存模板文件成功'
  689. return true
  690. } else {
  691. //STATUS 由this.SAVEFILE返回
  692. return false
  693. }
  694. }
  695. /* 调入由Template指定的模版,该功能主要用于模版管理或模板套红 */
  696. this.WebUseTemplate = function() {
  697. this.ClearRevisions() //清除正文痕迹的目的是为了避免痕迹状态下出现内容异常问题。
  698. this.WebDelLocalFile(this.getFilePath() + this.iWebOfficeTempName) //删除临时文件
  699. var mSaveResult = this.WebSaveLocalFile(this.getFilePath() + this.iWebOfficeTempName)//将当前文档保存下来
  700. if (!(mSaveResult == 0)) {
  701. this.Status = '保存本地文档失败!错误代码为:' + mSaveResult
  702. return false
  703. }
  704. var httpclient = this.obj.Http //设置http对象
  705. this.WebSetMsgByName('OPTION', 'LOADTEMPLATE')
  706. this.WebSetMsgByName('RECORDID', this.RecordID)
  707. this.WebSetMsgByName('TEMPLATE', this.Template)
  708. httpclient.AddForm('FormData', this.GetMessageString()) //这里是自定义json 传输格式。
  709. this.WebClearMessage() //清除所有WebSetMsgByName参数
  710. if (this.LOADFILE(httpclient)) {
  711. if (this.VBAInsertFile('Content', this.getFilePath() + this.iWebOfficeTempName)) {
  712. this.Status = '套红成功'
  713. return true
  714. } else {
  715. //this.Status = "套红失败"; //STATUS 由this.VBAInsertFile返回
  716. return false
  717. }
  718. } else {
  719. this.Status = '打开套红文档失败' //Status:状态信息
  720. return false
  721. }
  722. }
  723. /* 将当前文档作为图片格式保存在服务器上 WebSaveImage(".gif","abc.gif"); */
  724. this.WebSaveImage = function(ImageType, ImageName) {
  725. if (this.FileType == '.doc' || this.FileType == '.docx' || this.FileType == '.wps') {
  726. var iFilePath = this.getFilePath() + this.RecordID + '.htm'
  727. var strDirPath = this.getFilePath() + this.RecordID + '.files' //获取html files路径
  728. this.obj.ActiveDocument.SaveAs(iFilePath, 10, false, '', false, '', false, false, false, false, false, 0) //保存到本地html
  729. this.obj.ActiveDocument.Application.ActiveWindow.View.type = 3 //3是页面视图
  730. var DirPath = new VBArray(this.obj.FileSystem.FindToDirAsFile(strDirPath)).toArray() //获取html文件夹里的内容
  731. var httpclient = this.obj.Http // 设置http对象
  732. httpclient.Clear()
  733. this.WebSetMsgByName('RECORDID', this.RecordID)
  734. this.WebSetMsgByName('OPTION', 'SAVEIMAGE')
  735. this.WebSetMsgByName('DIRECTORY', this.RecordID + '.files')
  736. for (var i = 0; i < DirPath.length; i++) {
  737. var FilesName = DirPath[i]
  738. this.WebSetMsgByName('FILENAME', FilesName) // 加载FileName
  739. if (!this.SAVEFILE(httpclient, strDirPath + '\\' + FilesName)) {
  740. this.Status = '保存HTML图片文件失败'
  741. return false
  742. }
  743. }
  744. this.WebSetMsgByName('DIRECTORY', '') //作用把html和files区分开
  745. this.WebSetMsgByName('FILENAME', this.RecordID + '.htm') // 加载FileName
  746. if (this.SAVEFILE(httpclient, this.getFilePath() + this.RecordID + '.htm')) {
  747. this.Status = '保存HTML图片文件成功'
  748. return true
  749. } else {
  750. this.Status = '保存HTML图片文件失败'
  751. return false
  752. }
  753. }
  754. this.Status = '保存HTML图片文件失败!'
  755. return false
  756. }
  757. /* 插入服务器上执行的文档 */
  758. this.WebInsertFile = function() {
  759. var httpclient = this.obj.Http
  760. this.WebSetMsgByName('TEMPLATE', this.Template) //在接口获取模板名称
  761. this.WebSetMsgByName('OPTION', 'INSERTFILE') //发送请求LOADFILE
  762. httpclient.AddForm('FormData', this.GetMessageString()) //这里是自定义json 传输格式。
  763. this.WebClearMessage() //清除所有WebSetMsgByName参数
  764. var URL = this.WebUrl.substring(0, this.WebUrl.lastIndexOf('/'))
  765. httpclient.ShowProgressUI = this.ShowWindow //隐藏进度条
  766. if (httpclient.Open(this.HttpMethod.Post, URL + '/Document/' + this.Template, false)) //Http下载服务器文件
  767. {
  768. if (httpclient.Send()) {
  769. if (httpclient.Status == 200) {
  770. if (this.hiddenSaveLocal(httpclient, this, false, false, this.Template)) {
  771. if (this.obj.ActiveDocument.BookMarks.Exists(this.BookMark)) {
  772. if (this.VBAInsertFile(this.BookMark, this.DownloadedFileTempPathName)) {
  773. this.Status = '插入成功' //Status:状态信息
  774. httpclient.Clear()
  775. return true
  776. } else {
  777. //状态信息由 this.VBAInsertFILE返回
  778. return false
  779. }
  780. } else {
  781. this.Status = '文档里没有对应书签'
  782. return false
  783. }
  784. } else {
  785. this.Status = '文档保存到本地失败'
  786. return false
  787. }
  788. } else {
  789. this.Status = '数据接收错误'
  790. return false
  791. }
  792. } else {
  793. this.Status = '数据包发送失败' //Status:状态信息
  794. return false
  795. }
  796. } else {
  797. this.Status = '打开连接失败' //Status:状态信息
  798. return false
  799. }
  800. }
  801. /* 在指定的标签位置插入服务器上的图片,并决定是否做透明处理 */
  802. this.WebInsertImage = function(BookMark, ImageName, Transparent, ZOrder) //插入远程图片:BookMark插入的书签的位置;ImageName远程图片的名称
  803. {
  804. if (this.FileType == '.doc' || this.FileType == '.docx') {
  805. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  806. var httpclient = this.obj.Http
  807. this.BookMark = BookMark
  808. this.ImageName = ImageName
  809. this.WebSetMsgByName('OPTION', 'INSERTIMAGE')
  810. this.WebSetMsgByName('IMAGENAME', this.ImageName)
  811. httpclient.AddForm('FormData', this.GetMessageString()) //这里是自定义json 传输格式。
  812. this.WebClearMessage() //清除所有WebSetMsgByName参数
  813. httpclient.ShowProgressUI = this.ShowWindow//隐藏进度条
  814. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) {
  815. if (httpclient.Send()) {
  816. if (httpclient.Status == 200) {
  817. if (this.hiddenSaveLocal(httpclient, this, false, false, this.ImageName)) {
  818. if (this.InsertImageByBookMark(Transparent, ZOrder)) {
  819. this.ImageName = null
  820. this.BookMark = null
  821. httpclient.Clear()
  822. this.Status = '插入服务器图片成功'
  823. return true
  824. } else {
  825. this.Status = '书签插入图片失败'
  826. return false
  827. }
  828. } else {
  829. this.Status = '文档保存到本地失败'
  830. return false
  831. }
  832. } else {
  833. this.Status = '数据接收错误'
  834. return false
  835. }
  836. } else {
  837. this.Status = '发送数据包失败' //Status:状态信息
  838. return false
  839. }
  840. } else {
  841. this.Status = '打开连接失败' //Status:状态信息
  842. return false
  843. }
  844. } else {
  845. this.Status = '文档锁定,插入失败'
  846. return false
  847. }
  848. } else {
  849. this.Status = '非Word文档,插入失败'
  850. return false
  851. }
  852. }
  853. /* 保存当前文档中所有的书签名称。该功能主要把当前文档中所使用的书签都保存到数据库里 */
  854. this.WebSaveBookMarks = function() {
  855. var httpclient = this.obj.Http
  856. httpclient.Clear()
  857. var BKCount = this.obj.ActiveDocument.Bookmarks.Count //获取书签数量
  858. for (var i = 1; i <= BKCount; i++) {
  859. var BookName = this.obj.ActiveDocument.Bookmarks.Item(i).Name
  860. var BookValue = this.obj.ActiveDocument.Bookmarks.Item(BookName).Range.text
  861. this.WebSetMsgByName(BookName, BookValue) //存入书签名和值
  862. }
  863. this.WebSetMsgByName('OPTION', 'SAVEBOOKMARKS')
  864. this.WebSetMsgByName('TEMPLATE', this.RecordID) //在接口获取模板名称
  865. httpclient.AddForm('FormData', this.GetMessageString()) //这里是自定义json 传输格式。
  866. this.WebClearMessage()
  867. httpclient.ShowProgressUI = this.ShowWindow//隐藏进度条
  868. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) {
  869. if (httpclient.Send()) {
  870. this.Status = '书签保存成功'
  871. httpclient.Clear()
  872. return true
  873. } else {
  874. this.Status = '数据包发送失败'
  875. httpclient.Clear()
  876. return false
  877. }
  878. } else {
  879. this.Status = '打开连接失败'
  880. httpclient.Clear()
  881. return false
  882. }
  883. }
  884. /* 打开书签管理窗口,显示书签列表,可以用于添加、删除和定位书签 */
  885. this.WebOpenBookMarks = function() {
  886. if (this.FileType == '.doc' || this.FileType == '.docx') {
  887. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  888. this.obj.ActiveDocument.Application.Dialogs.Item(168).Show()
  889. return true
  890. }
  891. this.Status = '文档被锁定,操作失败'
  892. return false
  893. }
  894. this.Status = '非Word文档,操作失败'
  895. return false
  896. }
  897. /* 取数据库内容填充文档中书签的值 */
  898. this.WebLoadBookMarks = function() {
  899. var httpclient = this.obj.Http
  900. httpclient.Clear()
  901. this.WebSetMsgByName('RECORDID', this.RecordID) //在接口获取RecordID值
  902. this.WebSetMsgByName('TEMPLATE', this.Template) //在接口获取模板名称
  903. this.WebSetMsgByName('FILENAME', this.FileName) //在接口获取文件名称
  904. this.WebSetMsgByName('FILETYPE', this.FileType) //在接口获取文件类型
  905. this.WebSetMsgByName('OPTION', 'LOADBOOKMARKS') //在接口获取模板名称
  906. httpclient.AddForm('FormData', this.GetMessageString()) //这里是自定义json 传输格式。
  907. this.WebClearMessage() //清除所有WebSetMsgByName参数
  908. this.sendMode = 'WebLoadBookMarks'
  909. httpclient.ShowProgressUI = this.ShowWindow //隐藏进度条
  910. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) {
  911. if (httpclient.Send()) {
  912. var ReturnValue = httpclient.GetResponseHeader('RName')// 获取返回值
  913. var jsonObj = eval('(' + ReturnValue + ')')
  914. try {
  915. for (var i in jsonObj) {
  916. var BookName = i
  917. var BookValue = jsonObj[i]
  918. if (this.obj.ActiveDocument.BookMarks.Exists(BookName)) {
  919. var mBookRange = this.obj.ActiveDocument.Bookmarks.Item(BookName).Range
  920. mBookRange.text = BookValue
  921. } else {
  922. this.Status = '没有找到' + BookName + '书签'
  923. return false
  924. }
  925. }
  926. } catch (e) {
  927. this.Status = e.description
  928. return false
  929. }
  930. this.Status = '书签内容已插入到书签'
  931. return true
  932. } else {
  933. this.Status = '向后台发送数据包错误'
  934. return false
  935. }
  936. } else {
  937. this.Status = '打开链接错误'
  938. return false
  939. }
  940. }
  941. /* 打开签名窗口,允许用户输入密码,来获取已经保存起来的印章或签名信息。确定签名后的信息将保存在服务器的数据库中以便将来验证使用*/
  942. this.WebOpenSignature = function() {
  943. var FunExt = this.obj.FuncExtModule
  944. FunExt.SetServerType(1)
  945. if (this.Charset != true) {
  946. FunExt.SetCharset('UTF-8') //根据后台传输数据的编码,判定是否启用,默认为gb2312
  947. }
  948. FunExt.WebUrl = this.WebUrl
  949. FunExt.UserName = this.UserName
  950. FunExt.FileName = this.FileName
  951. FunExt.RecordID = this.RecordID
  952. FunExt.FileType = this.FileType
  953. FunExt.SetDocument(this.obj.ActiveDocument)
  954. FunExt.WebSetMsgByName('USERID', '123456')
  955. FunExt.WebSetMsgByName('USERIDONE', '123456')
  956. FunExt.WebSetMsgByName('USERIDTWO', '123456')
  957. FunExt.WebOpenSignature()
  958. this.Status = FunExt.Status
  959. return true
  960. }
  961. /* 不打开签名或印章检验窗口,检验签名或印章是否合法有效 */
  962. this.WebCheckSignature = function() {
  963. var FunExt = this.obj.FuncExtModule
  964. FunExt.SetServerType(1)
  965. if (this.Charset != true) {
  966. FunExt.SetCharset('UTF-8') //根据后台传输数据的编码,判定是否启用,默认为gb2312
  967. }
  968. FunExt.WebUrl = this.WebUrl
  969. FunExt.UserName = this.UserName
  970. FunExt.FileName = this.FileName
  971. FunExt.RecordID = this.RecordID
  972. FunExt.FileType = this.FileType
  973. FunExt.SetDocument(this.obj.ActiveDocument)
  974. var i = FunExt.WebCheckSignature()
  975. FunExt.Alert('检测结果:' + i + '\r\n 注释: (=-1 有非法印章) (=0 没有任何印章) (>=1 有多个合法印章)')
  976. this.Status = FunExt.Status
  977. return true
  978. }
  979. /* 打开签名或印章检验窗口,检验签名或印章是否合法有效 */
  980. this.WebShowSignature = function() {
  981. var FunExt = this.obj.FuncExtModule
  982. FunExt.SetServerType(1)
  983. if (this.Charset != true) {
  984. FunExt.SetCharset('UTF-8') //根据后台传输数据的编码,判定是否启用,默认为gb2312
  985. }
  986. FunExt.WebUrl = this.WebUrl
  987. FunExt.UserName = this.UserName
  988. FunExt.FileName = this.FileName
  989. FunExt.RecordID = this.RecordID
  990. FunExt.FileType = this.FileType
  991. FunExt.SetDocument(this.obj.ActiveDocument)
  992. FunExt.WebShowSignature()
  993. this.Status = FunExt.Status
  994. return true
  995. }
  996. /*下载服务器上的文件并保存在本地 */
  997. this.WebGetFile = function(LocalFile, RemoteFile) {
  998. var httpclient = this.obj.Http //设置http对象
  999. httpclient.Clear()
  1000. this.WebSetMsgByName('RECORDID', this.RecordID) //加载RecordID
  1001. this.WebSetMsgByName('LOCALFILE', LocalFile) //取得本地文件名称
  1002. this.WebSetMsgByName('REMOTEFILE', RemoteFile) //取得远程文件名称
  1003. this.WebSetMsgByName('OPTION', 'GETFILE') //发送请求LOADFILE
  1004. httpclient.AddForm('FormData', this.GetMessageString()) //这里是自定义json 传输格式。
  1005. this.WebClearMessage() //清除所有WebSetMsgByName参数
  1006. httpclient.ShowProgressUI = true //显示进度条
  1007. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) { //这里采用同步方式接收文档数据。
  1008. if (httpclient.Send()) {
  1009. if (httpclient.GetResponseHeader('MsgError') == '404') { //判断服务器是否存在文件
  1010. this.Status = '后台未找到对应文档'
  1011. httpclient.Clear()
  1012. return false
  1013. }
  1014. httpclient.ResponseSaveToFile(LocalFile)
  1015. this.Status = '文档下载到本地成功'
  1016. httpclient.Clear()
  1017. return true
  1018. } else {
  1019. this.Status = '数据包发送失败' //Status:状态信息
  1020. return false
  1021. }
  1022. } else {
  1023. this.Status = '打开连接失败' //Status:状态信息
  1024. httpclient.Clear()
  1025. return false
  1026. }
  1027. }
  1028. /* 将本地文件上传到服务器上,并保存为远程文件 */
  1029. this.WebPutFile = function(LocalFile, RemoteFile) {
  1030. var httpclient = this.obj.Http //设置http对象
  1031. httpclient.Clear()
  1032. this.WebSetMsgByName('REMOTEFILE', RemoteFile) //取得远程文件名称
  1033. this.WebSetMsgByName('OPTION', 'PUTFILE') //发送请求LOADFILE
  1034. httpclient.AddForm('FormData', this.GetMessageString())
  1035. httpclient.AddFile('FileData', LocalFile) //需要上传的文件 无法判断本地文档是否存在,导致上传时找不到文档情况下会生成空白文档)
  1036. this.WebClearMessage()
  1037. httpclient.ShowProgressUI = false //隐藏进度条
  1038. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) //true 异步方式 false同步
  1039. {
  1040. if (!httpclient.Send()) {
  1041. this.Status = '文档上传失败'
  1042. httpclient.Clear()
  1043. return false
  1044. } else {
  1045. this.Status = '文档上传成功'
  1046. httpclient.Clear()
  1047. return true
  1048. }
  1049. } else {
  1050. this.Status = '打开链接失败'
  1051. httpclient.Clear()
  1052. return false
  1053. }
  1054. }
  1055. /* 删除指定的本地文件或服务器上的文件 */
  1056. this.WebDelFile = function(LocalFile, RemoteFile) {
  1057. if (LocalFile == '') {
  1058. if (RemoteFile != '') {
  1059. var httpclient = this.obj.Http //设置http对象
  1060. httpclient.Clear()
  1061. this.WebSetMsgByName('REMOTEFILE', RemoteFile) //取得远程文件名称
  1062. this.WebSetMsgByName('OPTION', 'DELFILE') //发送请求LOADFILE
  1063. httpclient.AddForm('FormData', this.GetMessageString())
  1064. this.WebClearMessage()
  1065. httpclient.ShowProgressUI = false //隐藏进度条
  1066. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) //true 异步方式 false同步
  1067. {
  1068. if (!httpclient.Send()) {
  1069. this.Status = '向后台发送数据包失败'
  1070. httpclient.Clear()
  1071. return false
  1072. } else {
  1073. if (this.WebGetMsgByName('DelFileState') == '成功') {
  1074. this.Status = '文档删除成功'
  1075. httpclient.Clear()
  1076. return true
  1077. } else {
  1078. this.Status = '文档不存在'
  1079. httpclient.Clear()
  1080. return false
  1081. }
  1082. }
  1083. } else {
  1084. this.Status = '打开链接失败'
  1085. return false
  1086. }
  1087. } else {
  1088. this.Status = '文件名为空,请输入要删除的文件名'
  1089. return false
  1090. }
  1091. } else {
  1092. var fs = this.obj.FileSystem
  1093. if (fs.DeleteFile(LocalFile)) {
  1094. this.Status = '删除本地文件成功'
  1095. return true
  1096. } else {
  1097. this.Status = '该文档不存在或者没有权限删除'
  1098. return false
  1099. }
  1100. }
  1101. }
  1102. /* 建立新文件 */
  1103. this.CreateFile = function() {
  1104. var docType = this.getDocType(this.FileType) // 获取文档类型
  1105. switch (docType) {
  1106. case this.DocType.WORD:
  1107. this.obj.CreateNew('Word.Document') // 创建word
  1108. this.Status = '新建WORD成功'
  1109. break
  1110. case this.DocType.EXECL:
  1111. this.obj.CreateNew('Excel.Sheet') // 创建execl
  1112. this.Status = '新建EXECL成功'
  1113. break
  1114. case this.DocType.PICTURE:
  1115. this.obj.CreateNew('iWebPicture.iWebPictureMain') // 创建tif
  1116. this.Status = '新建TIF成功'
  1117. break
  1118. case this.DocType.PPT:
  1119. this.obj.CreateNew('PowerPoint.Show') // 创建ppt
  1120. this.Status = '新建PPT成功'
  1121. break
  1122. default:
  1123. this.obj.CreateNew('Word.Document') // 默认创建word文档
  1124. this.Status = '新建WORD成功'
  1125. break
  1126. }
  1127. }
  1128. /* 使Office控件全屏 */
  1129. this.FullSize = function(mValue) {
  1130. this.obj.FullSize = mValue //true为全屏,false为关闭全屏
  1131. }
  1132. /* 文档保存到本地(有对话框)
  1133. this.WebSaveLocal = function()
  1134. {
  1135. this.setShowDialog(this.ShowDialog.DialogSaveCopyAs);
  1136. this.Status = "文档保存到本地成功";
  1137. }*/
  1138. this.WebSaveLocal = function() {
  1139. var fileNamePath
  1140. if (this.FileType == '.doc' || this.FileType == '.docx') {
  1141. var exts = '所有支持的文件格式(*.docx;*.doc)|*.docx;*.doc'
  1142. exts += '|Word 文档(*.docx)|*.docx'
  1143. exts += '|Word 97-2003文档(*.doc)|*.doc'
  1144. exts += '||'
  1145. } else if (this.FileType == '.xls' || this.FileType == '.xlsx') {
  1146. var exts = '所有支持的文件格式(*.xlsx;*.xls)|*.xlsx;*.xls'
  1147. exts += '|Excel 工作簿(*.xlsx)|*.xlsx'
  1148. exts += '|Excel 97-2003工作簿(*.xls)|*.xls'
  1149. exts += '||'
  1150. }
  1151. fileNamePath = this.obj.FileSystem.FileSaveAs(exts, this.FileName) //this.FileName 显示名称
  1152. var ext = fileNamePath.substring(fileNamePath.length - 3, fileNamePath.length)
  1153. if (fileNamePath == '') {
  1154. return true
  1155. }
  1156. try {
  1157. this.obj.Save(fileNamePath, 0)
  1158. } catch (e) {
  1159. this.Status = e.description
  1160. alert(e.description)
  1161. return false
  1162. }
  1163. return true
  1164. }
  1165. /* 打开本地文档(有对话框)*/
  1166. this.WebOpenLocal = function() {
  1167. this.setShowDialog(this.ShowDialog.DialogOpen, this.getOpenDocSuffix(this.FileType))
  1168. this.Status = '打开本地文档成功'
  1169. }
  1170. /* 文档保存到本地 */
  1171. this.WebSaveLocalFile = function(FileName) {
  1172. try {
  1173. this.WebDelLocalFile(FileName)
  1174. if (this.FileType != '.pdf') {
  1175. var saveState = this.Save(FileName, this.getOfficeVersion(), this.FileType.substring(1).toUpperCase())
  1176. } else {
  1177. var saveState = this.Save(FileName, 0, this.FileType.substring(1).toUpperCase())
  1178. }
  1179. return saveState
  1180. this.Status = '保存本地文件成功'
  1181. } catch (e) {
  1182. this.Status = e.description
  1183. this.Status = '保存本地文档失败'
  1184. return -1
  1185. }
  1186. }
  1187. /* 打开本地文档 */
  1188. this.WebOpenLocalFile = function(filePath) {
  1189. if (this.getDocType(this.FileType) == this.DocType.PICTURE) {
  1190. try {
  1191. this.obj.ActiveDocument.WebOpenLocalFile(filePath)
  1192. this.Status = '打开本地文档成功'
  1193. return 0
  1194. } catch (e) {
  1195. this.Status = '打开本地文档失败'
  1196. return -1
  1197. }
  1198. }
  1199. return this.obj.Open(filePath)
  1200. }
  1201. /* 取得书签的值 */
  1202. this.WebGetBookMarks = function(BMarksName) {
  1203. if (this.obj.ActiveDocument.BookMarks.Exists(BMarksName)) // 判断是否存在该书签
  1204. {
  1205. return this.obj.ActiveDocument.Bookmarks.Item(BMarksName).Range.Text
  1206. } else {
  1207. this.Status = '名称为' + BMarksName + '的书签在文档中不存在'
  1208. return ''
  1209. }
  1210. }
  1211. /* 光标处添加书签(新增功能) */
  1212. this.WebAddBookMarks = function(BMarksName, BMarksValue) {
  1213. if (this.FileType == '.doc' || this.FileType == '.docx') {
  1214. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  1215. if (!this.obj.ActiveDocument.BookMarks.Exists(BMarksName)) // 判断是否存在该书签
  1216. {
  1217. var BMVLength = BMarksValue.length
  1218. this.obj.ActiveDocument.Application.Selection.TypeText(BMarksValue)// 插入内容
  1219. this.obj.ActiveDocument.Application.Selection.MoveLeft(Unit = 1,
  1220. Count = BMVLength)
  1221. var StartR = this.obj.ActiveDocument.Application.Selection.Start
  1222. var EndR = this.obj.ActiveDocument.Application.Selection.Start + BMVLength
  1223. this.obj.ActiveDocument.Range(Start = StartR, End = EndR).Select()
  1224. this.obj.ActiveDocument.Bookmarks.Add(BMarksName)// 添加书签
  1225. this.Status = '光标处添加书签成功'
  1226. return true
  1227. } else {
  1228. this.Status = '名称为' + BMarksName + '的书签在文档中已存在'
  1229. this.WebFindBookMarks(BMarksName)
  1230. return false
  1231. }
  1232. }
  1233. this.Status = '文档被锁定,操作失败'
  1234. return false
  1235. }
  1236. this.Status = '非Word文档,操作失败'
  1237. return false
  1238. }
  1239. /* 书签定位 */
  1240. this.WebFindBookMarks = function(BMarksName) {
  1241. if (this.FileType == '.doc' || this.FileType == '.docx') {
  1242. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  1243. if (this.obj.ActiveDocument.BookMarks.Exists(BMarksName)) // 判断是否存在该书签
  1244. {
  1245. var range = this.obj.Range
  1246. range = this.obj.ActiveDocument.Bookmarks.Item(BMarksName).Range
  1247. range.Select()
  1248. this.Status = '已定位到书签'
  1249. return true
  1250. } else {
  1251. this.Status = '名称为' + BMarksName + '的书签在文档中不存在'
  1252. return false
  1253. }
  1254. }
  1255. this.Status = '文档被锁定,操作失败'
  1256. return false
  1257. }
  1258. this.Status = '非Word文档,操作失败'
  1259. return false
  1260. }
  1261. /* 删除书签(新增功能) */
  1262. this.WebDelBookMarks = function(BMarksName) {
  1263. if (this.FileType == '.doc' || this.FileType == '.docx') {
  1264. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  1265. if (this.obj.ActiveDocument.BookMarks.Exists(BMarksName)) // 判断是否存在该书签
  1266. {
  1267. this.obj.ActiveDocument.Bookmarks.Item(BMarksName).Delete()// 删除书签
  1268. this.Status = '删除书签成功'
  1269. return true
  1270. } else {
  1271. this.Status = '名称为' + BMarksName + '的书签在文档中不存在'
  1272. return false
  1273. }
  1274. }
  1275. this.Status = '文档被锁定,操作失败'
  1276. return false
  1277. }
  1278. this.Status = '非Word文档,操作失败'
  1279. return false
  1280. }
  1281. /* 将vbmValue值设置到书签vbmName位置 */
  1282. this.WebSetBookmarks = function(vbmName, vbmValue) {
  1283. if (this.FileType == '.doc' || this.FileType == '.docx' || this.FileType == '.wps') {
  1284. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  1285. try {
  1286. if (this.obj.ActiveDocument.BookMarks.Exists(vbmName)) { // 判断是否存在该书签
  1287. var vRange = this.obj.ActiveDocument.Bookmarks.Item(vbmName).Range
  1288. vRange.text = vbmValue
  1289. this.obj.ActiveDocument.Bookmarks.Add(vbmName, vRange)
  1290. this.Status = '书签赋值成功'
  1291. return true
  1292. }
  1293. this.Status = '名称为' + vbmName + '的书签在文档中不存在'
  1294. return false
  1295. } catch (e) {
  1296. this.Status = e.description
  1297. return false
  1298. }
  1299. } else {
  1300. this.Status = '插入失败,文档被锁定'
  1301. return false
  1302. }
  1303. } else {
  1304. this.Status = '非Word文档,插入失败'
  1305. return false
  1306. }
  1307. }
  1308. //设置书签字体
  1309. this.SetBookMarksFont = function(bMarksName, fColor, fSize, fName, fBold, fItalic) {
  1310. this.WebObject.ActiveDocument.Bookmarks.Item(bMarksName).Range.Select()
  1311. var Selection = this.WebObject.ActiveDocument.Application.Selection
  1312. Selection.Font.Color = fColor //字体红色
  1313. Selection.Font.Size = fSize //字体大小
  1314. Selection.Font.Name = fName //字体类型
  1315. Selection.Font.Bold = fBold // 是否加粗(True加粗,False正常)
  1316. Selection.Font.Italic = fItalic // 是否斜体(True斜体,False正常)
  1317. }
  1318. /* 设置显示或隐藏工具栏 (需要修改控件代码) */
  1319. this.WebToolsVisible = function(ToolName, Visibled) {
  1320. this.Status = '该功能暂未提供!'
  1321. return false
  1322. }
  1323. /* 设置工具栏按钮是否有效 (需要修改控件代码) */
  1324. this.WebToolsEnable = function(ToolName, ToolIndex, Enabled) {
  1325. this.Status = '该功能暂未提供!'
  1326. return false
  1327. }
  1328. /* 打印文档 */
  1329. this.WebOpenPrint = function() {
  1330. this.setShowDialog(this.ShowDialog.DialogPrint)
  1331. }
  1332. /* 打开插入图片窗口 */
  1333. this.WebOpenPicture = function() {
  1334. if (this.FileType == '.doc' || this.FileType == '.docx' || this.FileType == '.wps') {
  1335. var spDlg = this.obj.ActiveDocument.Application.Dialogs.Item(163)
  1336. spDlg.Show()
  1337. } else if (this.FileType == '.xls' || this.FileType == '.xlsx' || this.FileType == '.et') {
  1338. var spDlg = this.obj.ActiveDocument.Application.Dialogs.Item(342)
  1339. spDlg.Show()
  1340. }
  1341. }
  1342. /* 使文档重新获得焦点刷新文档 */
  1343. this.WebRefresh = function() {
  1344. this.obj.Activate(true)
  1345. }
  1346. /* 设置文档痕迹保留的状态 */
  1347. this.WebSetRevision = function(Show, Track, Print, Tool) {
  1348. var strCustomUI
  1349. strCustomUI = '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="LoadImage"> ' +
  1350. ' <ribbon startFromScratch="false"> ' +
  1351. ' <tabs>' +
  1352. ' <tab idMso="TabReviewWord" visible="false">' + //隐藏审阅工具栏
  1353. ' </tab> ' +
  1354. ' </tabs> ' +
  1355. ' </ribbon> ' +
  1356. ' </customUI>'
  1357. if (this.getDocType(this.FileType) == this.DocType.WORD
  1358. && this.obj.ActiveDocument.ProtectionType == '-1') {
  1359. this.obj.ActiveDocument.TrackRevisions = Track // 显示标记和隐藏标记
  1360. this.obj.ActiveDocument.ShowRevisions = Show // 显示痕迹或隐藏
  1361. this.obj.ActiveDocument.PrintRevisions = Print //控制是否打印痕迹
  1362. if (Tool) {
  1363. this.obj.RibbonCustomUI = strCustomUI
  1364. this.Status = '设置痕迹成功'
  1365. return true
  1366. } else {
  1367. this.Status = '设置痕迹成功'
  1368. return true
  1369. }
  1370. } else {
  1371. this.Status = '非word文档,无法执行'
  1372. return false
  1373. }
  1374. }
  1375. /* 使文档保护状态 */
  1376. this.WebSetProtect = function(Boolean, password) {
  1377. var docType = this.getDocType(this.FileType)
  1378. if (password == '') {
  1379. password = this.PASSWORD
  1380. }
  1381. Boolean ? this.VBAProtectDocument(docType, password) : this
  1382. .VBAUnProtectDocument(docType, password)
  1383. }
  1384. /* 下载由Url指定的文件,保存为FileName路径的本地文件 */
  1385. this.WebDownLoadFile = function(Url, FileName) {
  1386. var kwoHttpGet = 0
  1387. var kwoHttpPost = 1
  1388. var httpclient = this.obj.Http
  1389. httpclient.Clear()
  1390. httpclient.ShowProgressUI = true
  1391. httpclient.Hidden = false
  1392. // 异步下载先调用OnSendEnd(),再调用OnRecEnd()
  1393. var info = httpclient.Open(kwoHttpGet, Url, false)
  1394. if (info) {
  1395. var send = httpclient.Send()
  1396. if (send) {
  1397. if (httpclient.Status == 200) {
  1398. httpclient.ResponseSaveToFile(FileName)
  1399. this.Status = '下载成功'
  1400. return true
  1401. } else {
  1402. this.Status = '下载失败请检查URL是否正确'
  1403. return false
  1404. }
  1405. } else {
  1406. this.Status = '数据包发送失败' // Status:状态信息
  1407. return false
  1408. }
  1409. } else {
  1410. this.Status = '打开连接失败' // Status:状态信息
  1411. httpclient.Clear()
  1412. return false
  1413. }
  1414. }
  1415. /* 建立本地目录 */
  1416. this.WebMkDirectory = function(DirName) {
  1417. var fs = this.obj.FileSystem // 创建file对象:
  1418. if (fs.CreateDirectory(DirName)) {
  1419. this.Status = '创建目录成功'
  1420. return true
  1421. } else {
  1422. this.Status = '创建目录失败检查是否已经有此目录或者路径不对'
  1423. return false
  1424. }
  1425. }
  1426. /* 删除本地目录 */
  1427. this.WebRmDirectory = function(DirName) {
  1428. var fs = this.obj.FileSystem // 创建file对象:
  1429. fs.ClearDirectory(DirName) //此接口无返回值
  1430. this.Status = '删除目录成功'
  1431. return true
  1432. }
  1433. /* 判断本地文件是否存在 (需要控件修改代码) */
  1434. this.WebFileExists = function(FileName) {
  1435. this.Status = '该功能暂未提供!'
  1436. return false
  1437. }
  1438. /* 得到某文件的大小 */
  1439. this.WebFileSize = function(FileName) {
  1440. var fs = this.obj.FileSystem // 创建file对象:
  1441. var fsize = fs.GetFileSize(FileName)
  1442. if (fsize == 0) {
  1443. this.Status = '请检查文件路径是否有误'
  1444. return 0
  1445. } else {
  1446. this.Status = '获取成功大小为' + fsize + '字节'
  1447. return fsize
  1448. }
  1449. }
  1450. /* 得到某文件的修改日期 (需要控件修改代码) */
  1451. this.WebFileDate = function(FileName) {
  1452. this.Status = '该功能暂未提供!'
  1453. return false
  1454. }
  1455. /* 禁止指定菜单项 */
  1456. this.DisableMenu = function(MenuName) {
  1457. var custommenu = this.obj.CustomMenu
  1458. return custommenu.DisableMenu(MenuFile, MenuName)
  1459. }
  1460. /* 允许菜单项有效 */
  1461. this.EnableMenu = function(MenuName) {
  1462. var custommenu = this.obj.CustomMenu
  1463. return custommenu.EnableMenu(MenuFile, MenuName)
  1464. }
  1465. /* 禁止指定快捷键的功能 (需要控件修改代码) */
  1466. this.DisableKey = function(KeyName) {
  1467. this.Status = '该功能暂未提供!'
  1468. return false
  1469. }
  1470. /* 建立注册表对象 */
  1471. this.WebOpenKey = function(mRoot, mValue) {
  1472. root = mRoot
  1473. rootValue = mValue
  1474. var register = this.obj.Register
  1475. var res = register.QueryStringValue(root, rootValue, '')
  1476. if (!res) {
  1477. register.SetStringValue(root, rootValue, '', '')
  1478. this.Status = '建立注册对象失败,已新建注册表对象'
  1479. return res
  1480. }
  1481. this.Status = '建立注册对象成功'
  1482. return true
  1483. }
  1484. /* 写入由Name指定的注册表项的值Value(字符串类型的值) */
  1485. this.WebWriteString = function(mKey, mValue) {
  1486. var register = this.obj.Register
  1487. if (root != undefined && rootValue != undefined) {
  1488. var res = register.SetStringValue(root, rootValue, mKey, mValue)
  1489. this.Status = '写入注册表成功'
  1490. return res
  1491. }
  1492. this.Status = '写入注册表失败,请先调用WebOpenKey接口'
  1493. return false
  1494. }
  1495. /* 读取由Name指定的注册表项的值(字符串类型的值) */
  1496. this.WebReadString = function(mKey) {
  1497. var register = this.obj.Register
  1498. if (root != undefined && rootValue != undefined) {
  1499. var res = register.QueryStringValue(root, rootValue, mKey)
  1500. if (res != null || res != '') {
  1501. this.Status = '读取注册表成功'
  1502. return res
  1503. } else {
  1504. this.Status = '读取失败,没有对应的注册表'
  1505. return res
  1506. }
  1507. }
  1508. this.Status = '读取注册表失败,请先调用WebOpenKey接口'
  1509. return false
  1510. }
  1511. /* 写入由Name指定的注册表项的值Value */
  1512. this.WebWriteInteger = function(mKey, mValue) {
  1513. var register = this.obj.Register
  1514. if (root != undefined && rootValue != undefined) {
  1515. var res = register.SetDWordValue(root, rootValue, mKey, mValue)
  1516. this.Status = '写入注册表成功'
  1517. return res
  1518. }
  1519. this.Status = '写入注册表失败,请先调用WebOpenKey接口'
  1520. return false
  1521. }
  1522. /* 读取由Name指定的注册表项的值Value */
  1523. this.WebReadInteger = function(mKey) {
  1524. var register = this.obj.Register
  1525. if (root != undefined && rootValue != undefined) {
  1526. var res = register.QueryDWORDValue(root, rootValue, mKey)
  1527. if (res != null || res != '') {
  1528. this.Status = '读取注册表成功'
  1529. return res
  1530. } else {
  1531. this.Status = '读取失败,没有对应的注册表'
  1532. return res
  1533. }
  1534. }
  1535. this.Status = '读取注册表失败,请先调用WebOpenKey接口'
  1536. return false
  1537. }
  1538. /* 盖章时自动载入日期信息附加在所盖的印章上 (需要控件修改代码) */
  1539. this.ShowDate = function(DateString, Align) {
  1540. this.Status = '该功能暂未提供!'
  1541. return false
  1542. }
  1543. /* 将文档中的印章变为黑白或彩色 (需要控件修改代码) */
  1544. this.SignatureColor = function(Flag) {
  1545. this.Status = '该功能暂未提供!'
  1546. return false
  1547. }
  1548. /* 返回当前文档中的印章或签名个数 (需要控件修改代码) */
  1549. this.SignatureCount = function(Flag) {
  1550. this.Status = '该功能暂未提供!'
  1551. return 0
  1552. }
  1553. /* 用来定位某用户的最后一个印章。光标定位到该印章上 (需要控件修改代码) */
  1554. this.GetSignature = function(UserName) {
  1555. this.Status = '该功能暂未提供!'
  1556. return false
  1557. }
  1558. /* 接受当前文档中所有的痕迹 */
  1559. this.ClearRevisions = function() {
  1560. if (this.getDocType(this.FileType) == this.DocType.WORD && this.obj.ActiveDocument.ProtectionType == '-1') {
  1561. try {
  1562. this.obj.Activate(true)
  1563. this.obj.ActiveDocument.AcceptAllRevisions()
  1564. this.obj.ActiveDocument.Revisions.AcceptAll()
  1565. this.Status = '痕迹接受成功'
  1566. return this.obj.ActiveDocument.Revisions.Count >= 0 ? true : false
  1567. } catch (e) {
  1568. this.Status = '痕迹接受失败,错误原因:' + e.description
  1569. return false
  1570. }
  1571. } else {
  1572. this.Status = '痕迹接受失败,错误原因:' + e.description
  1573. return false
  1574. }
  1575. }
  1576. /* 用于删除目录下的文件 */
  1577. this.WebDelTree = function(Directory) {
  1578. var fs = this.obj.FileSystem
  1579. fs.ClearDirectory(Directory) //此接口无返回值
  1580. return true
  1581. }
  1582. /* 用于取得当前控件的版本号信息 */
  1583. this.Version = function() {
  1584. return this.obj.Version
  1585. }
  1586. // 用于取得当前控件的生产版本信息 (需要控件修改代码) */
  1587. this.VersionEx = function() {
  1588. this.Status = '该功能暂未提供!'
  1589. return false
  1590. }
  1591. /* 按设置的打印份数进行打印 */
  1592. this.PrintByCopies = function(Copies, Show) {
  1593. parseInt(Copies)
  1594. var mAPIObj
  1595. var mApiName
  1596. var mAppName
  1597. mAppName = this.obj.ActiveDocument.Application.Name
  1598. if (mAppName == 'Microsoft Word') {
  1599. mAPIObj = this.obj.ActiveDocument.Application.Dialogs.Item(88)
  1600. if (Show) {
  1601. mAPIObj.NumCopies = Copies
  1602. if (mAPIObj.Display == -1) {
  1603. mAPIObj.Execute
  1604. this.Status = '打印成功'
  1605. return true
  1606. } else {
  1607. this.Status = '启用打印机窗口失败'
  1608. return false
  1609. }
  1610. } else {
  1611. mAPIObj.NumCopies = Copies
  1612. mAPIObj.Execute
  1613. this.Status = '打印成功'
  1614. return true
  1615. }
  1616. } else {
  1617. this.Status = '文档不是word类型'
  1618. return false
  1619. }
  1620. }
  1621. /* 用于获取中央处理器CUPID (需要控件修改代码) */
  1622. this.WebGetCpuID = function() {
  1623. this.Status = '该功能暂未提供!'
  1624. return false
  1625. }
  1626. /* 用于获取硬盘序列号IDEID (需要控件修改代码) */
  1627. this.WebGetIdeID = function() {
  1628. this.Status = '该功能暂未提供!'
  1629. return false
  1630. }
  1631. /* 将HTML文本生成Word可识别的格式,之后带格式可插入Word文档 (需要控件修改代码) */
  1632. this.BuildContentFromHTML = function(HTMLText) {
  1633. this.Status = '该功能暂未提供!'
  1634. return false
  1635. }
  1636. /* 执行宏 */
  1637. this.WebRunMacro = function(MarcroName, MacroValue) {
  1638. try {
  1639. var VBAStr = MacroValue
  1640. var VBCom = this.obj.ActiveDocument.VBProject.VBComponents.Add(1)
  1641. VBCom.CodeModule.AddFromString(VBAStr)
  1642. this.obj.ActiveDocument.Application.Run(MarcroName)
  1643. return true
  1644. } catch (e) {
  1645. return false
  1646. }
  1647. }
  1648. /* 文档对比 */
  1649. this.WebDocumentCompare = function(FileName1, FileName2) {
  1650. // 与当前打开的文档进行对比
  1651. this.Status = ''
  1652. var fs = this.obj.FileSystem // 创建file对象:
  1653. var filePath = this.DownFilePath() //获取文件保存临时路劲
  1654. var saveFilePath = filePath + Math.round(Math.random() * 100000000)
  1655. + '.doc'
  1656. if ((FileName1 == null) || (FileName1 == '')) {
  1657. if ((FileName2 == null) || (FileName2 === '')) {
  1658. this.Status = '【FileName2】不能为空!'
  1659. return false
  1660. } else {
  1661. // 开始下载FileName2
  1662. if (this.WebDownloadFile_int(FileName2)) {
  1663. FileName1 = this.FileName
  1664. this.WebSaveLocalFile(filePath + FileName1)
  1665. this.WebClose()
  1666. var bRet = this.obj.FuncExtModule.WebDocumentCompare(
  1667. filePath + FileName1, this.DownloadedFileTempPathName,
  1668. saveFilePath)
  1669. if (bRet == true) {
  1670. this.obj.Open(saveFilePath)
  1671. this.obj.ActiveDocument.Application.ActiveWindow.View.type = 3
  1672. this.obj.ActiveDocument.Application.ActiveWindow.View.SplitSpecial = 20
  1673. return true
  1674. } else {
  1675. this.Status = '文档对比失败,请确认待对比的文档是否能够正常打开!'
  1676. return false
  1677. }
  1678. } else {
  1679. this.Status = '文件【' + FileName2 + '】下载失败,该文档可能在服务器不存在!'
  1680. return false
  1681. }
  1682. }
  1683. }
  1684. // 与指定的后台两个文档进行对比
  1685. else {
  1686. if ((FileName2 == null) || (FileName2 == '')) {
  1687. this.Status = '【FileName2】不能为空!'
  1688. return false
  1689. } else {
  1690. // 开始分别下载指定的两个文件
  1691. if (this.WebDownloadFile_int(FileName1)) {
  1692. if ((this.WebDownloadFile_int(FileName2))) {
  1693. this.WebClose()
  1694. var bRet = this.obj.FuncExtModule.WebDocumentCompare(
  1695. filePath + FileName1, filePath + FileName2,
  1696. saveFilePath)
  1697. if (bRet == true) {
  1698. this.obj.Open(saveFilePath)
  1699. this.obj.ActiveDocument.Application.ActiveWindow.View.type = 3 //
  1700. this.obj.ActiveDocument.Application.ActiveWindow.View.SplitSpecial = 20
  1701. return true
  1702. } else {
  1703. this.Status = '文档对比失败,请确认待对比的文档是否能够正常打开!'
  1704. return false
  1705. }
  1706. } else {
  1707. this.Status = '文件【' + FileName2 + '】下载失败,该文档可能在服务器不存在!'
  1708. return false
  1709. }
  1710. } else {
  1711. this.Status = '文件【' + FileName1 + '】下载失败,该文档可能在服务器不存在!'
  1712. return false
  1713. }
  1714. }
  1715. }
  1716. }
  1717. /* 设置控件皮肤 注:颜色格式为BGR格式*/
  1718. this.WebSetSkin = function(titleBarColor/* 控件标题栏颜色 */,
  1719. menuBarStartColor/* 自定义菜单开始颜色 */,
  1720. menuBarButtonStartColor/* 自定义工具栏按钮开始颜色 */,
  1721. menuBarButtonEndColor/* 自定义工具栏按钮结束颜色 */,
  1722. menuBarButtonFrameColor/* 自定义工具栏按钮边框颜色 */,
  1723. CustomToolbarStartColor/* 自定义工具栏开始颜色 */, TitleBarTextColor/* 控件标题栏文本颜色 */) {
  1724. this.Status = ''
  1725. var style = this.obj.Style
  1726. try {
  1727. style.TitleBarColor = titleBarColor
  1728. if ((TitleBarTextColor == undefined) || (TitleBarTextColor == '')) // 设置默认标题文字颜色
  1729. {
  1730. style.TitleBarTextColor = 0x000000 // 黑色
  1731. } else {
  1732. style.TitleBarTextColor = TitleBarTextColor
  1733. }
  1734. titleBarColor = 0xf2f9ff
  1735. CustomToolbarStartColor = 0xf2f9ff
  1736. menuBarStartColor = 0xf2f9ff
  1737. menuBarButtonStartColor = 0x90cbf4
  1738. menuBarButtonEndColor = 0x90cbf4
  1739. menuBarButtonFrameColor = 0x90cbf4
  1740. style.MenuBarStartColor = menuBarStartColor
  1741. style.MenuBarEndColor = 0xFFFFFF
  1742. style.MenuBarTextColor = 0x000000
  1743. style.MenuBarHighlightTextColor = 0x000000
  1744. style.MenuBarButtonStartColor = menuBarButtonStartColor
  1745. style.MenuBarButtonEndColor = menuBarButtonEndColor
  1746. style.MenuBarButtonFrameColor = menuBarButtonFrameColor
  1747. style.CustomToolbarStartColor = CustomToolbarStartColor
  1748. style.CustomToolbarEndColor = CustomToolbarStartColor
  1749. style.Invalidate()
  1750. return true
  1751. } catch (e) {
  1752. this.Status = '皮肤设置错误,错误信息为:' + e.description
  1753. return false
  1754. }
  1755. }
  1756. /* 是否启用iWebOffice对象内的拷贝功能。非控件的不受影响 */
  1757. this.WebEnableCopy = function(mValue) {
  1758. switch (mValue) {
  1759. case 0:
  1760. case false:
  1761. case '0':
  1762. this.obj.CopyEnabled = false
  1763. this.Status = '禁止复制'
  1764. break // 启用
  1765. case 1:
  1766. case '1':
  1767. case true:
  1768. this.obj.CopyEnabled = true
  1769. this.Status = '允许复制'
  1770. break // 关闭
  1771. default:
  1772. return
  1773. }
  1774. }
  1775. /* 显示痕迹和隐藏痕迹 */
  1776. this.VBAShowRevisions = function(mValue) {
  1777. if (this.getDocType(this.FileType) == this.DocType.WORD
  1778. && this.obj.ActiveDocument.ProtectionType == '-1') {
  1779. this.obj.ActiveDocument.TrackRevisions = mValue // 显示标记和隐藏标记
  1780. this.obj.ActiveDocument.ShowRevisions = mValue // 显示痕迹或隐藏
  1781. this.Status = '隐藏痕迹成功'
  1782. return true
  1783. } else {
  1784. this.Status = '非Office文档或文档已被锁定,无法执行操作'
  1785. return false
  1786. }
  1787. }
  1788. /* 保护文档 */
  1789. this.VBAProtectDocument = function(docType, password) {
  1790. if (docType == this.DocType.WORD) // word 保护模式
  1791. {
  1792. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  1793. this.obj.ActiveDocument.Protect(2, false, password) //第一个参数: 3可以复制 2不能复制
  1794. this.Status = '文档已被锁定'
  1795. return true
  1796. } else {
  1797. this.Status = '文档锁定失败'
  1798. return false
  1799. }
  1800. } else if (docType == this.DocType.EXECL) // Excel
  1801. // 保护模式,这里只保护表单1,其他的按自己需求编写
  1802. {
  1803. if (!this.obj.ActiveDocument.Application.Sheets(1).ProtectContents) // 判断表单是否是保护的
  1804. {
  1805. this.obj.ActiveDocument.Application.Sheets(1).Protect(password)
  1806. this.Status = '文档锁定成功'
  1807. } else {
  1808. this.Status = '文档已锁定'
  1809. return false
  1810. }
  1811. } else {
  1812. this.Status = '非Office文档,无法执行锁定操作'
  1813. return false
  1814. }
  1815. }
  1816. /* 根据密码解除保护 */
  1817. this.VBAUnProtectDocument = function(docType, password) {
  1818. var docType = this.getDocType(this.FileType)
  1819. if (docType == this.DocType.WORD) // word 保护模式
  1820. {
  1821. this.obj.ActiveDocument.Unprotect(password)
  1822. this.Status = 'WORD解除保护'
  1823. return true
  1824. } else if (docType == this.DocType.EXECL) {
  1825. this.obj.ActiveDocument.Application.Sheets(1).Unprotect(password)
  1826. this.Status = '解除保护'
  1827. return true
  1828. } else {
  1829. this.Status = '非Office文档,无法执行解锁操作'
  1830. return false
  1831. }
  1832. }
  1833. /* 把文档插入到指定的书签位置 */
  1834. this.VBAInsertFile = function(Position, FileName) {
  1835. try {
  1836. var docType = this.getDocType(this.FileType)
  1837. if (docType == this.DocType.WORD) {
  1838. this.obj.Activate(true)
  1839. if (this.obj.ActiveDocument.BookMarks.Exists(Position)) {
  1840. setTimeout(this.obj.ActiveDocument.Application.Selection.GoTo(-1, 0, 0, Position), 200)
  1841. }
  1842. this.obj.Activate(true)
  1843. this.obj.ActiveDocument.Application.Selection.InsertFile(FileName, '', false, false, false)
  1844. return true
  1845. } else {
  1846. this.Status = '非Office文档,无法执行插入文档操作'
  1847. return false
  1848. }
  1849. } catch (e) {
  1850. this.Status = '插入文档失败,错误原因:' + e.description
  1851. return false
  1852. }
  1853. }
  1854. /* 接受本地文档中的所有痕迹 */
  1855. this.WebAcceptAllRevisions = function(FileName) {
  1856. this.obj.FuncExtModule.WebAcceptAllRevisions(FileName)
  1857. this.Status = '接受所有痕迹成功!'
  1858. return false
  1859. }
  1860. /* 设置WORD用户名 */
  1861. this.VBASetUserName = function(UserName) {
  1862. if (this.FileType != '.ppt' && this.FileType != '.pptx') {
  1863. try {
  1864. //this.OfficeUserName = this.obj.ActiveDocument.Application.UserName; //保存office本身用户名以做还原用
  1865. this.obj.ActiveDocument.Application.UserName = UserName //痕迹名称
  1866. if (this.FileType != '.xls' && this.FileType != '.xlsx') {
  1867. this.WebObject.ActiveDocument.Application.Options.UseLocalUserInfo = true //设置不管是否登录Office都始终使用UserName值
  1868. this.obj.ActiveDocument.Application.UserInitials = UserName //批注名称
  1869. }
  1870. } catch (e) {
  1871. this.OfficeUserName = this.obj.ActiveDocument.Application.UserName //保存office本身用户名以做还原用
  1872. this.obj.ActiveDocument.Application.UserName = UserName //痕迹名称
  1873. if (this.FileType != '.xls' && this.FileType != '.xlsx') {
  1874. this.obj.ActiveDocument.Application.UserInitials = UserName //批注名称
  1875. }
  1876. }
  1877. }
  1878. }
  1879. /* 设置域 */
  1880. this.ShowField = function() {
  1881. try {
  1882. this.obj.ActiveDocument.ActiveWindow.View.ShowDrawings = true
  1883. this.obj.ActiveDocument.ActiveWindow.View.ShowFieldCodes = false
  1884. return true
  1885. } catch (e) {
  1886. this.Status = '设置域失败,错误原因:' + e.description
  1887. return false
  1888. }
  1889. }
  1890. /* 区域保护 */
  1891. this.WebAreaProtect = function(BMarksName) {
  1892. if (this.FileType == '.doc' || this.FileType == '.docx') // word 保护模式
  1893. {
  1894. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  1895. var mMarksName = BMarksName.split(',')
  1896. var tag = ''
  1897. for (var i = 0; i <= mMarksName.length; i++) {
  1898. if (!this.obj.ActiveDocument.BookMarks.Exists(mMarksName[i])) {
  1899. tag += mMarksName[i]
  1900. continue
  1901. }
  1902. var range = this.obj.Range
  1903. range = this.obj.ActiveDocument.Bookmarks.Item(mMarksName[i]).Range
  1904. range.Select()
  1905. this.obj.ActiveDocument.bookmarks.Item(mMarksName[i]).range.editors.add(-1) // 常量:wdeditoreveryone=-1
  1906. }
  1907. this.obj.ActiveDocument.Protect(3, false, '123', false, false) // 常量:wdAllowOnlyReading=3
  1908. this.obj.ActiveDocument.Application.Selection.MoveLeft(Unit = 1,
  1909. Count = 1)
  1910. this.obj.ActiveDocument.ActiveWindow.View.ShadeEditableRanges = false // 取消"突出显示可编辑区域"
  1911. if (tag != '') {
  1912. this.Status = tag + '书签名不存在'
  1913. } else {
  1914. this.Status = '操作成功,书签区域可编辑'
  1915. }
  1916. return true
  1917. } else {
  1918. this.Status = '文档以被保护,请解除保护后操作!'
  1919. return false
  1920. }
  1921. } else {
  1922. this.Status = '非Office文档,无法执行区域保护操作!'
  1923. return false
  1924. }
  1925. }
  1926. /* 取消区域保护 */
  1927. this.WebAreaUnprotect = function(BMarksName) {
  1928. if (this.FileType == '.doc' || this.FileType == '.docx') {
  1929. var mMarksName = BMarksName.split(',')
  1930. for (var i = 0; i <= mMarksName.length; i++) {
  1931. if (this.obj.ActiveDocument.BookMarks.Exists(mMarksName[i])) // 判断是否存在该书签
  1932. {
  1933. try {
  1934. this.obj.ActiveDocument.Unprotect('123') // 解保护
  1935. var range = this.obj.Range
  1936. range = this.obj.ActiveDocument.Bookmarks.Item(mMarksName[i]).Range
  1937. range.Select() // 选定书签内容
  1938. this.obj.ActiveDocument.DeleteAllEditableRanges(-1) // 去掉突出显示
  1939. this.Status = '书签区域' + mMarksName[i] + '可以编辑'
  1940. return true
  1941. } catch (e) {
  1942. this.Status = '执行取消区域保护时出现错误,错误原因:' + e.description
  1943. return false
  1944. }
  1945. } else {
  1946. this.Status = '文档中不存在<' + mMarksName[i] + '>的书签'
  1947. return false
  1948. }
  1949. }
  1950. } else {
  1951. this.Status = '非Office文档,无法执行取消区域保护操作!'
  1952. return false
  1953. }
  1954. }
  1955. /* 获取焦点 */
  1956. this.Activate = function(blnValue) {
  1957. this.obj.Activate(blnValue)
  1958. }
  1959. /* 设置word的页码 */
  1960. this.WebPageCode = function() {
  1961. this.obj.ActiveDocument.Application.Dialogs.Item(294).Show()
  1962. }
  1963. /* 控制2015标题栏 */
  1964. this.ShowTitleBar = function(mValue) {
  1965. var style = this.obj.Style
  1966. style.ShowTitleBar = mValue
  1967. }
  1968. /* 控制2015自定义菜单栏 */
  1969. this.ShowCustomToolBar = function(mValue) {
  1970. var style = this.obj.Style
  1971. style.ShowCustomToolbar = mValue
  1972. }
  1973. /* 控制2015菜单栏 */
  1974. this.ShowMenuBar = function(mValue) {
  1975. var style = this.obj.Style
  1976. switch (mValue) {
  1977. case 0:
  1978. case false:
  1979. case '0':
  1980. style.ShowMenuBar = false
  1981. break //隐藏菜单栏
  1982. case 1:
  1983. case '1':
  1984. case true:
  1985. style.ShowMenuBar = true
  1986. break //显示菜单栏
  1987. default:
  1988. return
  1989. }
  1990. }
  1991. /* 控制Office工具栏 */
  1992. this.ShowToolBars = function(mValue) {
  1993. var style = this.obj.Style
  1994. style.ShowToolBars = mValue
  1995. style.ShowToolSpace = mValue
  1996. }
  1997. /* 控制2015状态栏 */
  1998. this.ShowStatusBar = function(mValue) {
  1999. var style = this.obj.Style
  2000. style.ShowStatusBar = mValue
  2001. }
  2002. /* 显示/隐藏手写签批工具栏 */
  2003. this.ShowCustomToolbar = function(bVal) {
  2004. this.obj.Style.ShowCustomToolbar = bVal
  2005. }
  2006. /* 显示和隐藏痕迹 隐藏痕迹时之前的痕迹不受影响 */
  2007. this.WebShow = function(blnValue) {
  2008. if (this.getDocType(this.FileType) == this.DocType.WORD) {
  2009. this.VBAShowRevisions(blnValue)
  2010. }
  2011. }
  2012. /* 是否启用iWebOffice对象内文档的保存功能 */
  2013. this.SaveEnabled = function(mBoolean) {
  2014. this.obj.SaveEnabled = mBoolean
  2015. }
  2016. /* 是否启用iWebOffice对象内文档的打印功能 */
  2017. this.PrintEnabled = function(mBoolean) {
  2018. this.obj.PrintEnabled = mBoolean
  2019. }
  2020. /* 解决在Firefox和chrome浏览器下调用iWebPlugin崩溃崩溃的问题需要在load()函数下加如下代码 */
  2021. this.HookEnabled = function() {
  2022. if (this.getDocType(this.FileType) == this.DocType.WORD) {
  2023. this.obj.Style.ShowToolSpace = true
  2024. this.obj.SelectionInformationEnabled = false
  2025. }
  2026. if (!((window.ActiveXObject != undefined)
  2027. || (window.ActiveXObject != null) || 'ActiveXObject' in window)) {
  2028. this.obj.HookEnabled = false
  2029. }
  2030. }
  2031. // ---------------------------------------------------对外接口-------------------------------------------------------------------//
  2032. // ******************************************************************************************************************************
  2033. // ******************************************************************************************************************************//
  2034. // ---------------------------------------------------内部方法-------------------------------------------------------------------//
  2035. /* 清理本地临时文件 */
  2036. this.ClearDirectory = function() {
  2037. var fs = this.obj.FileSystem
  2038. /*老版本插件临时目录*/
  2039. fs.ClearDirectory(this.DownFilePath())
  2040. fs.ClearDirectory(this.getFilePath()) //此接口无返回值
  2041. }
  2042. /* 删除本地文件 */
  2043. this.WebDelLocalFile = function(FileName) {
  2044. var fs = this.obj.FileSystem
  2045. fs.DeleteFile(FileName)
  2046. }
  2047. /* 获取json格式数据包 */
  2048. this.GetMessageString = function() {
  2049. return this.ht.toString()
  2050. }
  2051. /* 设置控件Ribbon */
  2052. this.WebSetRibbonUIXML = function(strCustomUI) {
  2053. this.obj.RibbonCustomUI = strCustomUI
  2054. }
  2055. /* 设置控件保存文档的限制 */
  2056. this.WebSetMaxFileSize = function(mFileName) {
  2057. if (this.WebFileSize(mFileName) > this.MaxFileSize * 1024) {
  2058. return false
  2059. } else {
  2060. return true
  2061. }
  2062. }
  2063. /* 设置临时目录路径(DOWN) */
  2064. this.DownFilePath = function() {
  2065. var fs = this.obj.FileSystem // 获取file对象
  2066. var NewDownFilePath
  2067. if (this.HiddenDirectory) //将文档保存在隐藏目录
  2068. {
  2069. NewDownFilePath = fs.GetSpecialFolderLocation(0x20) + this.DOWN
  2070. + fs.GetFolderEncryptCode(1) + '\\' // 设置临时路径
  2071. } else {
  2072. NewDownFilePath = fs.GetSpecialFolderPath(0x1a) + this.DOWN //设置临时路径
  2073. }
  2074. return NewDownFilePath
  2075. }
  2076. /* 设置临时目录路径(UP) */
  2077. this.getFilePath = function() {
  2078. var fs = this.obj.FileSystem // 获取file对象
  2079. var filePath
  2080. if (this.HiddenDirectory) //将文档保存在隐藏目录
  2081. {
  2082. filePath = fs.GetSpecialFolderLocation(0x20) + this.UP
  2083. + fs.GetFolderEncryptCode(1) + '\\' // 设置临时路径
  2084. } else {
  2085. filePath = fs.GetSpecialFolderLocation(0x1a) + this.UP
  2086. }
  2087. fs.CreateDirectory(filePath) // 创建路径
  2088. this.FilePath = filePath // 给对象赋值,方便删除和打开
  2089. return this.FilePath
  2090. }
  2091. /* 判断当前文档是否为空文档 */
  2092. this.WebSetAllowEmpty = function() {
  2093. if (this.FileType == '.doc' || this.FileType == '.docx') {
  2094. var WebText = this.WebObject.ActiveDocument.Content.Text //获取word文档内容
  2095. if (WebText.length != 1) {
  2096. return true //文档有内容
  2097. }
  2098. return false //文档没容
  2099. }
  2100. return true //不是word
  2101. }
  2102. /* 控制是否可以复制 */
  2103. this.NewCopyType = function(mValue) {
  2104. switch (mValue) {
  2105. case 0:
  2106. case false:
  2107. case '0':
  2108. this.obj.CopyEnabled = false
  2109. break //启用
  2110. case 1:
  2111. case '1':
  2112. case true:
  2113. this.obj.CopyEnabled = true
  2114. break //关闭
  2115. default:
  2116. return
  2117. }
  2118. }
  2119. /* 设置是否显示整个控件工具栏,包括OFFICE的工具栏 */
  2120. this.NewShowToolBar = function(mValue) {
  2121. var style = this.obj.Style
  2122. switch (mValue) {
  2123. case false :
  2124. case 0:
  2125. style.ShowCustomToolbar = false
  2126. style.ShowToolBars = true
  2127. break //自定义工具栏隐藏,office工具栏显示
  2128. case true :
  2129. case 1:
  2130. style.ShowCustomToolbar = true
  2131. style.ShowToolBars = true
  2132. break //自定义工具栏显示,office工具栏显示
  2133. case 2:
  2134. style.ShowCustomToolbar = false
  2135. style.ShowToolBars = false
  2136. break //自定义工具栏隐藏,office工具栏隐藏
  2137. case 3:
  2138. style.ShowCustomToolbar = true
  2139. style.ShowToolBars = false
  2140. break //自定义工具栏显示,office工具栏隐藏
  2141. }
  2142. }
  2143. /* 控制OFFICE另存为和保存功能 */
  2144. this.NewUIControl = function(mValue) {
  2145. var strCustomUI
  2146. switch (mValue) {
  2147. case false:
  2148. strCustomUI = '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="LoadImage"> \
  2149. <commands> \
  2150. <command idMso="FileSave" enabled="false" /> \
  2151. <command idMso="FileSaveAs" enabled="false" /> \
  2152. </commands> \
  2153. </customUI>'
  2154. break
  2155. case true:
  2156. strCustomUI = '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="LoadImage"> \
  2157. <commands> \
  2158. <command idMso="FileSave" enabled="true" /> \
  2159. <command idMso="FileSaveAs" enabled="true" /> \
  2160. </commands> \
  2161. </customUI>'
  2162. break
  2163. }
  2164. this.obj.RibbonCustomUI = strCustomUI
  2165. }
  2166. //禁用修订,更正
  2167. //ReviewShowMarkupMenu显示标记
  2168. //ReviewReviewingPaneMenu审阅窗格
  2169. //ReviewTrackChangesMenu修订
  2170. //ReviewAcceptChangeMenu接受
  2171. //ReviewRejectChangeMenu拒绝
  2172. //ReviewNewComment新建批注
  2173. //ReviewDeleteCommentsMenu删除批注
  2174. this.ModifyReview = function() {
  2175. var strCustomUI = '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="LoadImage"> \
  2176. <commands> \
  2177. <command idMso="ReviewReviewingPaneMenu" enabled="false"/> \
  2178. <command idMso="ReviewShowMarkupMenu" enabled="false"/> \
  2179. <command idMso="ReviewTrackChangesMenu" enabled="false"/> \
  2180. <command idMso="ReviewRejectChangeMenu" enabled="false"/> \
  2181. <command idMso="ReviewAcceptChangeMenu" enabled="false"/> \
  2182. <command idMso="ReviewNewComment" enabled="false"/> \
  2183. <command idMso="ReviewDeleteCommentsMenu" enabled="false"/> \
  2184. </commands> \
  2185. </customUI>'
  2186. for (i = 1; i <= this.obj.ActiveDocument.Application.CommandBars.Item("Track Changes").Controls.Count; i++) {
  2187. if (this.obj.ActiveDocument.Application.CommandBars.Item('Track Changes').Controls.Item(i).ID == 1715) {
  2188. this.obj.ActiveDocument.Application.CommandBars.Item('Track Changes').Controls.Item(i).Enabled = false
  2189. }
  2190. if (this.obj.ActiveDocument.Application.CommandBars.Item('Track Changes').Controls.Item(i).ID == 1716) {
  2191. this.obj.ActiveDocument.Application.CommandBars.Item('Track Changes').Controls.Item(i).Enabled = false
  2192. }
  2193. if (this.obj.ActiveDocument.Application.CommandBars.Item('Track Changes').Controls.Item(i).ID == 2041) {
  2194. this.obj.ActiveDocument.Application.CommandBars.Item('Track Changes').Controls.Item(i).Enabled = false
  2195. }
  2196. }
  2197. this.obj.RibbonCustomUI = strCustomUI
  2198. }
  2199. /* 禁用offcie小图标 */
  2200. this.OfficeFastUI = function() {
  2201. var strCustomUI = '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="LoadImage"> \
  2202. <commands> \
  2203. <command idMso="PrintPreviewAndPrint" enabled="false" /> \
  2204. <command idMso="TabReviewWord" enabled="false" /> \
  2205. <command idMso="FileSave" enabled="false" /> \
  2206. <command idMso="FileSaveAs" enabled="false" /> \
  2207. <command idMso="FileNewDefault" enabled="false" /> \
  2208. <command idMso="FileOpen" enabled="false" /> \
  2209. <command idMso="FilePrintQuick" enabled="false" /> \
  2210. <command idMso="RedoOrRepeat" enabled="false" /> \
  2211. <command idMso="Undo" enabled="false" /> \
  2212. </commands> \
  2213. </customUI>'
  2214. this.obj.RibbonCustomUI = strCustomUI
  2215. }
  2216. // startFromScratch不显示所有选项卡控制 false显示选项卡;true不显示选项卡
  2217. //TabReviewWord关闭视图工具栏//TabInsert关闭插入工具栏//TabHome关闭开始工具栏
  2218. this.WebSetRibbonUIXML = function() {
  2219. var strCustomUI = '<customUI xmlns="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoad" loadImage="LoadImage"> \
  2220. <ribbon startFromScratch="false"> \
  2221. <tabs> \
  2222. <tab idMso="TabReviewWord" visible="false" /> \
  2223. <tab idMso="TabInsert" visible="false" /> \
  2224. <tab idMso="TabHome" visible="false" /> \
  2225. </tabs> \
  2226. </ribbon> \
  2227. </customUI>'
  2228. this.obj.RibbonCustomUI = strCustomUI
  2229. /*
  2230. 最常用的内置选项卡名称
  2231. 选项卡名称 idMso(Excel) idMso(Word) idMso(Access)
  2232. 开始 TabHome TabHome TabHomeAccess
  2233. 插入 TabInsert TabInsert (none)
  2234. 页面布局 TabPageLayoutExcel TabPageLayoutWord (none)
  2235. 公式 TabFormulas (none) (none)
  2236. 数据 TabData (none) (none)
  2237. 审阅 TabReview TabReviewWord (none)
  2238. 创建 (none) (none) TabCreate
  2239. 外部数据 (none) (none) TabExternalData
  2240. 数据库工具 (none) (none) TabDatabaseTools
  2241. iWebOffice控件的RibbonUIXML属性,是基于OFFICE2007的RibbonX的应用。关于RibbonX的相关资料,需要自己另行查询。
  2242. */
  2243. }
  2244. /* 枚举显示系统和控件定义的相关对话框内容 */
  2245. this.ShowDialog =
  2246. {
  2247. DialogNew: 0, // 新建对象
  2248. DialogOpen: 1, // 打开
  2249. DialogSaveAs: 2, // 另存为
  2250. DialogSaveCopyAs: 3, // 另存为拷贝
  2251. DialogPrint: 4, // 打印
  2252. DialogPageSetup: 5, // 打印设置
  2253. DialogProperties: 6 // 文档属性
  2254. }
  2255. /* 设置2015对象 */
  2256. this.setObj = function(object) {
  2257. this.obj = object
  2258. this.WebObject = this.obj // 设置VBA调用对象
  2259. return true
  2260. }
  2261. /* 枚举所有文档类型这里只列举word 0,execl 1 */
  2262. this.DocType =
  2263. {
  2264. WORD: 0,
  2265. EXECL: 1,
  2266. PPT: 2,
  2267. PDF: 3,
  2268. OFD: 4
  2269. }
  2270. /* Http对象post方式 */
  2271. this.HttpMethod =
  2272. {
  2273. Get: 0, // Http对象get方式
  2274. Post: 1
  2275. }
  2276. /* 另存为pdf文件 */
  2277. this.SaveAsPdf = function(FilePath) {
  2278. var OfficeVersion = this.obj.ActiveDocument.Application.Version
  2279. if (OfficeVersion != '11.0') {
  2280. if ((this.FileType == '.doc') || (this.FileType == '.docx')
  2281. || (this.FileType == '.wps')) {
  2282. try {
  2283. //this.obj.ActiveDocument.ExportAsFixedFormat(FilePath, 17,true);
  2284. this.obj.ActiveDocument.ExportAsFixedFormat(FilePath, 17,
  2285. false, 0, 0, 1, 1, 0, true, true, 0, true, true, true)
  2286. this.Status = '保存PDF到本地成功'
  2287. return true
  2288. } catch (e) {
  2289. this.Status = e.description
  2290. alert('保存PDF异常,可能Office没有保存PDF功能,建议安装SaveAsPDFandXPS插件')
  2291. return false
  2292. }
  2293. } else if ((this.FileType == '.xls') || (this.FileType == '.xlsx') || (this.FileType == '.et')) {
  2294. try {
  2295. this.obj.ActiveDocument.Application.ActiveSheet.ExportAsFixedFormat(0, FilePath, 0)
  2296. this.Status = '保存PDF到本地成功'
  2297. return true
  2298. } catch (e) {
  2299. this.Status = e.description
  2300. alert('保存PDF异常,可能Office没有保存PDF功能,建议安装SaveAsPDFandXPS插件')
  2301. return false
  2302. }
  2303. } else {
  2304. }
  2305. } else {
  2306. this.Status = '保存PDF异常,Office没有保存PDF功能'
  2307. alert('保存PDF异常,Office没有保存PDF功能')
  2308. }
  2309. }
  2310. /* 保存为html */
  2311. this.SaveAsHtml = function(FilePath) {
  2312. if ((this.FileType == '.doc') || (this.FileType == '.docx')
  2313. || (this.FileType == '.wps')) {
  2314. try {
  2315. var ret = this.obj.ActiveDocument.SaveAs(FilePath, 8, false,
  2316. '', false, '', false, false, false, false, false, 0)
  2317. this.obj.ActiveDocument.Application.ActiveWindow.View.type = 3//3是页面视图
  2318. return true
  2319. } catch (e) {
  2320. this.Status = e.description
  2321. return false
  2322. }
  2323. }
  2324. }
  2325. /* 用来存储Http发送的表单数据 */
  2326. this.ArrayList = function() {
  2327. this.ObjArr = {} // 列表
  2328. this.Count = 0 // 数量
  2329. this.Add = function(key, value) // 添加
  2330. {
  2331. this.ObjArr[key] = value
  2332. this.Count++
  2333. return true
  2334. }
  2335. this.Get = function(key) {
  2336. return this.ObjArr[key]
  2337. }
  2338. this.Clear = function() // 清空
  2339. {
  2340. this.ObjArr = {}
  2341. this.Count = 0
  2342. }
  2343. // 按json格式输出
  2344. this.toString = function() {
  2345. var newArray = new Array() // 存储json字符串
  2346. var i = 0
  2347. for (var i in this.ObjArr) {
  2348. newArray.push('\'' + i + '\':\'' + this.ObjArr[i] + '\'')
  2349. }
  2350. return '{' + newArray + '}'
  2351. }
  2352. }
  2353. this.ht = new this.ArrayList()
  2354. /* 获取打开窗口的后缀 */
  2355. this.getOpenDocSuffix = function(fileType) {
  2356. if (fileType.length == 5) {
  2357. fileType = fileType.substring(0, 4)
  2358. }
  2359. var exts
  2360. exts = ''
  2361. if (this.isWPS() || !this.getOfficeVersion()) // 如果是office2003是不支持x格式的文档
  2362. {
  2363. exts += '*' + fileType + 'x|*' + fileType + 'x|'
  2364. }
  2365. exts += '*' + fileType + '|*' + fileType + '|'
  2366. exts += this.getOpenSuffixName(fileType) + '(*' + fileType
  2367. if (this.isWPS() || !this.getOfficeVersion()) // 如果是office2003是不支持x格式的文档
  2368. {
  2369. exts += ';*' + fileType + 'x'
  2370. }
  2371. exts += ')|*' + fileType
  2372. if (this.isWPS() || !this.getOfficeVersion()) // 如果是office2003是不支持x格式的文档
  2373. {
  2374. exts += ';*' + fileType + 'x'
  2375. }
  2376. exts += '|'
  2377. return exts
  2378. }
  2379. /* 对比文档里面所用到的 下载文档方法 */
  2380. this.WebDownloadFile_int = function(fn) {
  2381. this.Status = ''
  2382. var httpclient = this.obj.Http // 设置http对象
  2383. httpclient.Clear()
  2384. this.WebSetMsgByName('USERNAME', this.UserName) // 加载UserName
  2385. this.WebSetMsgByName('FILENAME', fn) // 加载FileName
  2386. this.WebSetMsgByName('FILETYPE', this.FileType) // 加载FileType
  2387. this.WebSetMsgByName('RECORDID', this.RecordID) // 加载RecordID
  2388. this.WebSetMsgByName('OPTION', 'LOADFILE') // 发送请求LOADFILE
  2389. httpclient.AddForm('FormData', this.GetMessageString()) // 这里是自定义json传输格式。
  2390. this.WebClearMessage() // 清除所有WebSetMsgByName参数
  2391. httpclient.ShowProgressUI = this.ShowWindow // 显示进度条
  2392. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) // 这里采用同步方式打开文档。
  2393. {
  2394. if (httpclient.Send()) {
  2395. if (httpclient.GetResponseHeader('MsgError') == '404') // 判断服务器是否存在文件
  2396. {
  2397. this.Status = '文档【' + fn + '】下载失败,请确认该文档在服务器上是否存在'
  2398. httpclient.Clear()
  2399. return false
  2400. }
  2401. httpclient.Clear()
  2402. if (this.hiddenSaveLocal(httpclient, this, false, false, fn)) // 下载成功时
  2403. {
  2404. this.Status = '文档下载成功'
  2405. return true
  2406. } else {
  2407. this.Status = '文档下载失败'
  2408. return false
  2409. }
  2410. }
  2411. }
  2412. }
  2413. /* 保存文件至服务 */
  2414. this.SAVEFILE = function(httpclient, FileName, header) // 与后台发生交互OPTION值为:SAVEFILE
  2415. {
  2416. // httpclient.AddForm("FormData", this.GetMessageString());
  2417. httpclient.AddFile('file', FileName) // 需要上传的文件
  2418. this.WebClearMessage()
  2419. httpclient.ShowProgressUI = this.ShowWindow // 隐藏进度条
  2420. this.WebUrl = this.ServerUrl + this.SaveServlet
  2421. if (httpclient.Open(this.HttpMethod.Post, this.WebUrl, false)) //true 异步方式 false同步
  2422. {
  2423. httpclient.setRequestHeader('Authorization', header)
  2424. if (!httpclient.Send()) {
  2425. //this.Status = "数据包发送失败!请检查链接<" + this.WebUrl + ">是否正确或网络是否畅通。";
  2426. this.Status = httpclient.status
  2427. return false
  2428. } else {
  2429. this.Status = httpclient.status
  2430. this.getResultJson = JSON.parse(httpclient.responseText)
  2431. console.log(this.getResultJson)
  2432. if (this.getResultJson.code == '302') {
  2433. return false
  2434. }
  2435. return true
  2436. }
  2437. } else {
  2438. //this.Status = "打开链接<" + this.WebUrl + ">失败!请检查网络是否畅通。";
  2439. this.Status = httpclient.status
  2440. return false
  2441. }
  2442. }
  2443. /* 加载服务上的文档 */
  2444. this.LOADFILE = function(httpclient) {
  2445. this.Status = ''
  2446. httpclient.ShowProgressUI = this.ShowWindow
  2447. this.WebUrl = this.ServerUrl + this.FileName
  2448. httpclient.Clear()
  2449. if (httpclient.Open(this.HttpMethod.Get, encodeURI(this.WebUrl, 'utf-8'), false)) // true 异步方式 false同步
  2450. {
  2451. if (httpclient.Send()) {
  2452. var aaa = httpclient.status
  2453. if (aaa == 404) {
  2454. this.CreateFile()
  2455. this.getOfficeVersion()// 打开文档后,判断当前office版本
  2456. httpclient.Clear()
  2457. return true
  2458. } else if (aaa == 405) {
  2459. this.CreateFile()
  2460. this.getOfficeVersion()// 打开文档后,判断当前office版本
  2461. httpclient.Clear()
  2462. return true
  2463. }
  2464. httpclient.Clear()
  2465. if (this.hiddenSaveLocal(httpclient, this, false, false)) {
  2466. var mSaveResult = this
  2467. .WebOpenLocalFile(this.DownloadedFileTempPathName)
  2468. if (mSaveResult == 0) { // 打开本地磁盘文件
  2469. this.getOfficeVersion()// 打开文档后,判断当前office版本
  2470. return true
  2471. } else if (mSaveResult == 1) {
  2472. this.obj.FuncExtModule.Alert('可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)!')
  2473. this.Status = '可能当前授权码错误,请确认iWebOffice2015.js的授权是否正确(或乱码)'
  2474. window.close()
  2475. return false
  2476. } else if (mSaveResult == 2) {
  2477. this.obj.FuncExtModule.Alert('没有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确!')
  2478. this.Status = '有找到文档,请确认WebOpenLocalFile打开文档的路径是否正确'
  2479. window.close()
  2480. return false
  2481. } else if (mSaveResult == 3) {
  2482. this.obj.FuncExtModule.Alert('没有权限导致文档打开失败,请用管理员身份运行浏览器后重试!')
  2483. this.Status = '没有权限导致文档打开失败,请用管理员身份运行浏览器后重试'
  2484. window.close()
  2485. return false
  2486. } else if (mSaveResult == 4) {
  2487. this.obj.FuncExtModule.Alert('文件可能损坏,请确定服务器文档是否已经损坏!')
  2488. this.Status = '文件可能损坏,请确定服务器文档是否已经损坏'
  2489. window.close()
  2490. return false
  2491. } else if (mSaveResult == 5) {
  2492. this.obj.FuncExtModule.Alert('未安装Office或者注册表有损坏!')
  2493. this.Status = '未安装Office或者注册表有损坏'
  2494. window.close()
  2495. return false
  2496. } else if (mSaveResult == 6) {
  2497. this.obj.FuncExtModule.Alert('文件被占用,请结束Office进程后重试!')
  2498. this.Status = '文件被占用,请结束Office进程后重试'
  2499. window.close()
  2500. return false
  2501. } else {
  2502. this.obj.FuncExtModule.Alert('打开文档时未知错误!错误码为: ' + mSaveResult)
  2503. this.Status = '打开文档时未知错误!错误码为: ' + mSaveResult
  2504. window.close()
  2505. return false
  2506. }
  2507. } else {
  2508. // 失败后,this.Status的值由hiddenSaveLocal返回
  2509. this.Status = '保存文档到本地 失败'
  2510. return false
  2511. }
  2512. } else {
  2513. alert('数据包发送失败!请检查链接<' + this.WebUrl + '>是否正确或网络是否畅通。')
  2514. this.Status = '数据包发送失败!请检查链接<' + this.WebUrl + '>是否正确或网络是否畅通。'
  2515. return false
  2516. }
  2517. } else {
  2518. alert('打开链接<' + this.WebUrl + '>失败!请检查网络是否畅通。')
  2519. this.Status = '打开链接<' + this.WebUrl + '>失败!请检查网络是否畅通。'
  2520. return false
  2521. }
  2522. }
  2523. /* 保存到本地 isHidden 是否隐藏文件;isInsertFile是否是插入文件 */
  2524. this.hiddenSaveLocal = function(httpclient, webOffice, isHidden,
  2525. isInsertFile, OtherName) {
  2526. try {
  2527. this.Status = ''
  2528. if (isHidden) {
  2529. httpclient.Hidden = true // 隐藏文件
  2530. }
  2531. var tempName = ''
  2532. var fs = webOffice.obj.FileSystem // WebOffice外面对象名称:
  2533. var filePath = this.DownFilePath() // 获取临时文件保存路径
  2534. fs.CreateDirectory(filePath) // 创建生成指定目录
  2535. this.FilePath = filePath // 这个保存的路径方便打开的时候再取。
  2536. if (isInsertFile == undefined || isInsertFile == true) {
  2537. tempName = 'temp' + webOffice.RecordID
  2538. this.tempInsertName = tempName + this.FileName
  2539. }
  2540. if (OtherName == undefined || OtherName == '') {
  2541. OtherName = this.FileName
  2542. OtherName = Math.random() * 100000 + this.FileType
  2543. }
  2544. this.DownloadedFileTempPathName = filePath + tempName + OtherName
  2545. httpclient.ResponseSaveToFile(this.DownloadedFileTempPathName)
  2546. httpclient.Clear()
  2547. return true
  2548. } catch (e) {
  2549. return false
  2550. }
  2551. }
  2552. /* office2003的接口和其他的不一样,所有保存到本地要区分开来 */
  2553. this.Save = function(FileName, is2003, FileType) {
  2554. if (this.getDocType(this.FileType) == this.DocType.PICTURE) {
  2555. if (this.obj.ActiveDocument.WebSaveLocalFile(FileName)) {
  2556. return 0
  2557. } else {
  2558. return -1
  2559. }
  2560. }
  2561. if (is2003) {
  2562. return this.obj.Save(FileName)
  2563. }
  2564. var SaveFalg = this.obj.Save(FileName, eval('this.DocTypeValue.' + FileType),
  2565. true)
  2566. if (SaveFalg == 80) {
  2567. return '文件路径无效'
  2568. } else if (SaveFalg == 81) {
  2569. return '参数无效'
  2570. } else if (SaveFalg == 82) {
  2571. return '文件创建失败'
  2572. } else {
  2573. return SaveFalg
  2574. }
  2575. }
  2576. /* 判断浏览器类型 */
  2577. this.blnIE = function() {
  2578. return (window.ActiveXObject != undefined)
  2579. || (window.ActiveXObject != null)
  2580. || ('ActiveXObject' in window)
  2581. }
  2582. /* 判断是否是WPS */
  2583. this.isWPS = function() {
  2584. return this.FileType.toUpperCase() == '.WPS'
  2585. || this.FileType.toUpperCase() == '.ET'
  2586. }
  2587. /* 获取office版本信息 */
  2588. this.getOfficeVersion = function() {
  2589. var getVersion = 0.0
  2590. try {
  2591. if (this.setVersion == -1) {
  2592. getVersion = parseFloat(this.obj.ActiveDocument.Application.Version)
  2593. this.setVersion = getVersion
  2594. } else {
  2595. getVersion = this.setVersion
  2596. }
  2597. if (getVersion == 11.0) {
  2598. return this.OfficeVersion.v2003
  2599. } else {
  2600. return this.OfficeVersion.vOther
  2601. }
  2602. } catch (e) {
  2603. return this.OfficeVersion.v2003
  2604. }
  2605. }
  2606. /* 获取文档类型 */
  2607. this.getDocType = function(fileType) {
  2608. if (fileType == '.doc' || fileType == '.docx' || fileType == '.wps') {
  2609. return this.DocType.WORD
  2610. }
  2611. if (fileType == '.xls' || fileType == '.xlsx' || fileType == '.et') {
  2612. return this.DocType.EXECL
  2613. }
  2614. if (fileType == '.tif' || fileType == '.jpg') {
  2615. return this.DocType.PICTURE
  2616. }
  2617. if (fileType == '.ppt' || fileType == '.pptx') {
  2618. return this.DocType.PPT
  2619. }
  2620. if (fileType == '.pdf') {
  2621. return this.DocType.PDF
  2622. }
  2623. if (fileType == '.ofd') {
  2624. return this.DocType.OFD
  2625. }
  2626. }
  2627. // 获取打开文档类型名称
  2628. this.getOpenSuffixName = function(fileType) {
  2629. var openSuffixName
  2630. switch (fileType) {
  2631. case this.DocType.WORD:
  2632. openSuffixName = 'Word Files'
  2633. break // 创建word后缀名称
  2634. case this.DocType.EXECL:
  2635. openSuffixName = 'Excel Files'
  2636. break // 创建execl后缀名称
  2637. default:
  2638. openSuffixName = 'Word Files'
  2639. break
  2640. }
  2641. return openSuffixName
  2642. }
  2643. /* 设置打开窗口的类型 */
  2644. this.setShowDialog = function(thisType, exts) {
  2645. switch (thisType) {
  2646. case this.ShowDialog.DialogOpen:
  2647. this.obj.ShowDialog(thisType, exts, 0)
  2648. break // 打开本地文档
  2649. case this.ShowDialog.DialogNew: // 新建对象
  2650. case this.ShowDialog.DialogPageSetup: // 打印设置
  2651. case this.ShowDialog.DialogPrint: // 打印
  2652. case this.ShowDialog.DialogProperties: // 文档属性
  2653. case this.ShowDialog.DialogSaveCopyAs: // 另存为拷贝
  2654. case this.ShowDialog.DialogSaveAs: // 另存为
  2655. this.obj.ShowDialog(thisType)
  2656. break // 打开窗口
  2657. default:
  2658. break
  2659. }
  2660. }
  2661. /* 设置文档的保护状态 */
  2662. this.setEditType = function(type) {
  2663. try {
  2664. switch (type) {
  2665. case 0:
  2666. case '0':
  2667. this.VBAProtectDocument(this.getDocType(this.FileType), '123')
  2668. break
  2669. case 1:
  2670. case '1':
  2671. this.WebShow(false)
  2672. break
  2673. case 2:
  2674. case '2':
  2675. this.WebShow(true)
  2676. break
  2677. default:
  2678. }
  2679. } catch (e) {
  2680. return false
  2681. }
  2682. }
  2683. /* 返回当前编辑器 */
  2684. this.getEditVersion = function() {
  2685. return this.obj.AppName
  2686. }
  2687. /* 设置手写签批用户 */
  2688. this.SetUser = function(username) {
  2689. this.obj.User = username
  2690. }
  2691. /* 检测异常文件的接口 */
  2692. this.CheckFile = function(vaul) {
  2693. this.obj.bCheckFile = vaul
  2694. }
  2695. /* 禁用wps混合签章按钮 */
  2696. this.EnableSignature = function(vaul) {
  2697. try {
  2698. this.obj.ActiveDocument.Application.COMAddIns
  2699. .Item('iSignatureWord.WordApp').Connect = vaul
  2700. } catch (e) {
  2701. return
  2702. }
  2703. }
  2704. /* --------------------------------------------水印功能 --------------------------------------------*/
  2705. /* 添加水印 */
  2706. this.AddWaterMark = function(WaterMarkNmae) {
  2707. if (this.FileType == '.doc' || this.FileType == '.docx') {
  2708. if (this.blnIE()) {
  2709. var intPageTotal = this.WebObject.ActiveDocument.Application.ActiveDocument.BuiltInDocumentProperties(14)
  2710. } else {
  2711. var intPageTotal = this.WebObject.ActiveDocument.Application.ActiveDocument.BuiltInDocumentProperties.Item(14).Value()
  2712. }
  2713. intPage = parseInt(intPageTotal)
  2714. var selection = this.WebObject.ActiveDocument.Application.Selection
  2715. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  2716. this.DelWaterMark(WaterMarkNmae)
  2717. for (var i = 1; i <= intPage; i++) {
  2718. selection.GoTo(What = 1, Which = 1, Count = i)
  2719. try {
  2720. //插入水印前需更改视图样式为页眉视图
  2721. this.WebObject.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 9 //wdSeekCurrentPageHeader
  2722. this.WebObject.ActiveDocument.Application.Selection.ClearFormatting() //去页面横线
  2723. //由于一个文档中只允许添加一个水印,因此在添加水印之前,需检测文档中是否存在水印,如果存在,则先删除
  2724. //设置插入水印,语法:表达式.AddTextEffect(预设文字效果【0..49】, 文字内容, 字体名, 字体大小, 是否粗体, 是否斜体, 左侧位置, 顶部位置)
  2725. selection.HeaderFooter.Shapes.AddTextEffect(0, '金格科技', '宋体', 36, false, false, 0, 0).Select()
  2726. var shapeRange = selection.ShapeRange
  2727. shapeRange.Name = WaterMarkNmae + i //水印对象名
  2728. shapeRange.TextEffect.NormalizedHeight = false //文字效果
  2729. shapeRange.Line.Visible = false //线条是否可见
  2730. shapeRange.Fill.Visible = true //填充是否可见
  2731. shapeRange.Fill.Solid() //填充类型(本例为纯色)
  2732. shapeRange.Fill.ForeColor.RGB = 0x0000FF //设定填充的颜色RGB值
  2733. shapeRange.Fill.Transparency = 0.5 //设置透明度50%
  2734. shapeRange.Rotation = -45 //设置旋转角度
  2735. shapeRange.LockAspectRatio = true //锁定纵横比
  2736. //shapeRange.Height = WebOffice.WebObject.ActiveDocument.Application.CentimetersToPoints(2); //高度
  2737. //shapeRange.Width = WebOffice.WebObject.ActiveDocument.Application.CentimetersToPoints(16); //宽度
  2738. shapeRange.Height = 2 * 72
  2739. shapeRange.Width = 8 * 72
  2740. shapeRange.WrapFormat.AllowOverlap = true //是否允许重叠
  2741. shapeRange.WrapFormat.Side = 3 //是否设置文字环绕(wdWrapNone)
  2742. shapeRange.WrapFormat.type = 3 //设置折回样式(本例设为不折回)
  2743. //设置水平位置与纵向页边距关联 wdRelativeVerticalPositionMargin
  2744. shapeRange.RelativeHorizontalPosition = 0
  2745. //设置垂直位置与横向页边距关联 wdRelativeVerticalPositionMargin
  2746. shapeRange.RelativeVerticalPosition = 0
  2747. //水平居中 wdShapeCenter
  2748. shapeRange.Left = -999995
  2749. //垂直居中
  2750. shapeRange.Top = -999995
  2751. //恢复视图样式到原来样式
  2752. this.WebObject.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 0 //wdSeekMainDocument
  2753. this.Status = '插入水印成功'
  2754. } catch (e) {
  2755. this.Status = '插入水印失败' + e.description
  2756. return false
  2757. }
  2758. }
  2759. return true
  2760. } else {
  2761. this.Status = '文档被锁定,插入水印失败'
  2762. return false
  2763. }
  2764. }
  2765. this.Status = '非Word文档,插入水印失败'
  2766. return false
  2767. }
  2768. /* 删除水印 */
  2769. this.DelWaterMark = function(WaterMarkNmae) {
  2770. if (this.FileType == '.doc' || this.FileType == '.docx') {
  2771. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  2772. this.WebObject.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 9
  2773. var selection = this.WebObject.ActiveDocument.Application.Selection
  2774. //查找文档中是否存在名称为【WaterMarkObjectName】的水印对象,如果存在,则删除
  2775. var WaterCount = selection.HeaderFooter.Shapes.Count
  2776. if (WaterCount > 0) {
  2777. for (var i = WaterCount; i >= 1; i--) {
  2778. if (selection.HeaderFooter.Shapes.Item(i).Name = WaterMarkNmae + i) {
  2779. selection.HeaderFooter.Shapes.Item(i).Delete()
  2780. }
  2781. }
  2782. }
  2783. this.WebObject.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 0
  2784. this.Status = '删除水印成功'
  2785. return true
  2786. }
  2787. this.Status = '文档被锁定,删除水印失败'
  2788. return false
  2789. }
  2790. this.Status = '非Word文档,删除水印失败'
  2791. return false
  2792. }
  2793. /* 插入图片水印 */
  2794. this.AddGraphicWaterMark = function(WaterMarkNmae) {
  2795. if (this.FileType == '.doc' || this.FileType == '.docx') {
  2796. if (this.blnIE()) {
  2797. var intPageTotal = this.WebObject.ActiveDocument.Application.ActiveDocument.BuiltInDocumentProperties(14)
  2798. } else {
  2799. var intPageTotal = this.WebObject.ActiveDocument.Application.ActiveDocument.BuiltInDocumentProperties.Item(14).Value()
  2800. }
  2801. intPage = parseInt(intPageTotal)
  2802. var selection = this.WebObject.ActiveDocument.Application.Selection
  2803. if (this.obj.ActiveDocument.ProtectionType == '-1') {
  2804. this.DelWaterMark(WaterMarkNmae)
  2805. for (var i = 1; i <= intPage; i++) {
  2806. selection.GoTo(What = 1, Which = 1, Count = i)
  2807. try {
  2808. this.WebObject.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 9 //wdSeekCurrentPageHeader
  2809. this.WebObject.ActiveDocument.Application.Selection.ClearFormatting() //去页面横线
  2810. /////获取服务器上的图片///////
  2811. var ImagePath = this.DownFilePath() //项目路径下Document的"WaterMark.jpg"
  2812. var ImageName = 'WaterMark.jpg'
  2813. this.DownloadToFile(ImageName, ImagePath)
  2814. /////获取服务器上的图片///////
  2815. selection.HeaderFooter.Shapes.AddPicture(ImagePath + ImageName, false, true).Select() //水印位置
  2816. var shapeRange = selection.ShapeRange
  2817. shapeRange.Name = WaterMarkNmae + i //水印对象名
  2818. shapeRange.PictureFormat.Brightness = 0.85
  2819. shapeRange.PictureFormat.Contrast = 0.15
  2820. shapeRange.LockAspectRatio = true
  2821. shapeRange.Height = 60.95 * 72 //高度
  2822. shapeRange.Width = 40.63 * 72 //宽度
  2823. shapeRange.WrapFormat.AllowOverlap = true
  2824. shapeRange.WrapFormat.Side = 3 //wdWrapNone
  2825. shapeRange.WrapFormat.Type = 3
  2826. shapeRange.RelativeHorizontalPosition = 0 //wdRelativeVerticalPositionMargin
  2827. shapeRange.RelativeVerticalPosition = 0 //wdRelativeVerticalPositionMargin
  2828. shapeRange.Left = -999995 //wdShapeCenter
  2829. shapeRange.Top = -999995 //wdShapeCenter
  2830. this.WebObject.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = 0 //wdSeekMainDocument
  2831. this.Status = '水印添加成功'
  2832. } catch (e) {
  2833. this.Status = '水印添加成功' + e.description
  2834. return false
  2835. }
  2836. }
  2837. return true
  2838. } else {
  2839. this.Status = '文档被锁定,插入水印失败'
  2840. return false
  2841. }
  2842. }
  2843. this.Status = '非Word文档,插入水印失败'
  2844. return false
  2845. }
  2846. //设置段落
  2847. this.ParagraphSettings = function() {
  2848. var paragraphFormat = this.WebObject.ActiveDocument.Application.Selection.ParagraphFormat
  2849. paragraphFormat.Alignment = 3 //常规:对齐方式,0:左对齐,1:居中,2:右对齐,以此类推
  2850. paragraphFormat.OutlineLevel = 10 //常规:大纲级别,值为1-10,10为正文文本,
  2851. //paragraphFormat.LeftIndent = 28.3 / 2; //缩进:左侧,28.3等于1cm需要多少根据比例乘/除
  2852. //paragraphFormat.RightIndent = 28.3 * 2; //缩进:右侧,28.3等于1cm需要多少根据比例乘/除
  2853. //paragraphFormat.FirstLineIndent = 28.3 * 2; //缩进:缩进值,28.3等于1cm需要多少根据比例乘/除
  2854. paragraphFormat.CharacterUnitLeftIndent = 0//缩进:左侧,按照字符缩进
  2855. paragraphFormat.CharacterUnitRightIndent = 0//缩进:右侧,按照字符缩进
  2856. paragraphFormat.CharacterUnitFirstLineIndent = 0//缩进:缩进值,按照字符缩进
  2857. paragraphFormat.MirrorIndents = false //缩进:对称缩进设置false不勾选true勾选
  2858. paragraphFormat.AutoAdjustRightIndent = true //缩进:如果定义了文档网格,则自动调整右缩进 false不勾选true勾选
  2859. //paragraphFormat.SpaceBefore = 2.5; //间距段前 :按照磅设置
  2860. //paragraphFormat.SpaceBeforeAuto = false; //设置间距段前非自动,改ture的话间距段前设置无效默认为自动
  2861. //paragraphFormat.SpaceAfter = 2.5;//间距:段后 :按照磅设置
  2862. //paragraphFormat.SpaceAfterAuto = false; //间距:断后非自动,改ture的话间距段后设置无效默认为自动
  2863. paragraphFormat.LineUnitBefore = 0//间距:段前:按照行设置
  2864. paragraphFormat.LineUnitAfter = 0//间距:段后:按照行设置
  2865. paragraphFormat.LineSpacingRule = 1 // 设置行距,0:单行,1:1.5倍,2:2倍,3:最小,以此类推
  2866. paragraphFormat.DisableLineHeightGrid = false //间距:如果定义了文档网格,则对齐到网格 false勾选true不勾选
  2867. paragraphFormat.WidowControl = false //分页:弧形控制 false不勾选true勾选
  2868. paragraphFormat.KeepWithNext = false //分页:与下段同页 false不勾选true勾选
  2869. paragraphFormat.KeepTogether = false //分页:段中不分页 false不勾选true勾选
  2870. paragraphFormat.PageBreakBefore = false //分页:段前分页 false不勾选true勾选
  2871. paragraphFormat.NoLineNumber = false //格式化例外向:取消行号 false不勾选true勾选
  2872. paragraphFormat.Hyphenation = true //格式化例外向:取消断字 false勾选true不勾选
  2873. paragraphFormat.FarEastLineBreakControl = true//换行:按中文习惯控制尾首字符 false不勾选true勾选
  2874. paragraphFormat.WordWrap = true//换行:允许西文在单词中间换行 false勾选true不勾选
  2875. paragraphFormat.HangingPunctuation = true //换行:允许标点溢出边界 true勾选false不勾选
  2876. paragraphFormat.HalfWidthPunctuationOnTopOfLine = false //字符间距:允许行首标点压缩true勾选false不勾选
  2877. paragraphFormat.AddSpaceBetweenFarEastAndAlpha = true//字符间距:自动调整中文与西文的间距 true勾选false不勾选
  2878. paragraphFormat.AddSpaceBetweenFarEastAndDigit = true//字符间距:自动调整中文与数字的间距 true勾选false不勾选
  2879. paragraphFormat.BaseLineAlignment = 4 //字符间距:文本对齐方式, 0:顶端 ,1:居中,2:基线,以此类推
  2880. this.WebObject.ActiveDocument.Application.Selection.MoveLeft(Unit = 1, Count = 1) //返回定位最前端 ;
  2881. }
  2882. //清理底纹
  2883. this.CleanBackground = function() {
  2884. this.WebObject.ActiveDocument.Application.Selection.WholeStory() //选中全文
  2885. //清理文字
  2886. var sfShading = this.WebObject.ActiveDocument.Application.Selection.Font.Shading
  2887. sfShading.Texture = 0
  2888. sfShading.ForegroundPatternColor = -16777216
  2889. sfShading.BackgroundPatternColor = -16777216
  2890. //清理段落
  2891. var pfShading = this.WebObject.ActiveDocument.Application.Selection.ParagraphFormat.Shading
  2892. pfShading.Texture = 0
  2893. pfShading.ForegroundPatternColor = -16777216
  2894. pfShading.BackgroundPatternColor = -16777216
  2895. this.WebObject.ActiveDocument.Application.Selection.MoveLeft(Unit = 1, Count = 1) //返回定位最前端 ;
  2896. }
  2897. //Word字体设置
  2898. this.WordFontSet = function() {
  2899. if (this.FileType == '.doc' || this.FileType == '.docx') {
  2900. var sFont = this.WebObject.ActiveDocument.Application.Selection.Font
  2901. sFont.Name = '微软雅黑' //设置字体
  2902. sFont.Size = 10.5 //字号
  2903. sFont.Bold = false //加粗
  2904. sFont.Italic = false //倾斜
  2905. sFont.Underline = 0 // 下划线线行
  2906. sFont.UnderlineColor = 0//下划线颜色
  2907. sFont.StrikeThrough = false //删除线
  2908. sFont.DoubleStrikeThrough = false //双删除线
  2909. sFont.Hidden = false //隐藏
  2910. sFont.SmallCaps = false //小型大写字母
  2911. sFont.AllCaps = false //全部大写字母
  2912. sFont.Color = -16777216//字体颜色 255红色
  2913. sFont.Superscript = false //上标
  2914. sFont.Subscript = false //下标
  2915. sFont.Spacing = 0 //磅值b
  2916. sFont.Scaling = 100 //缩放 100%
  2917. sFont.Position = 0 //磅值y
  2918. sFont.DisableCharacterSpaceGrid = false //如果定义了文档网格,则对齐到网格 false勾选,true不勾选
  2919. sFont.EmphasisMark = 0 //看重号,下拉框往下一个值+1
  2920. sFont.Ligatures = 0 //连字,下拉框往下一个值+1
  2921. sFont.NumberSpacing = 0//数字间距,下拉框往下一个值+1
  2922. sFont.NumberForm = 0//数字形式,下拉框往下一个值+1
  2923. sFont.StylisticSet = 0 //样式集 ,下拉框往下一个值+1
  2924. sFont.ContextualAlternates = 0 //使用上下文替换 0不勾选,1勾选
  2925. this.WebObject.ActiveDocument.Application.Selection.MoveLeft(Unit = 1, Count = 1) //返回定位最前端 ;
  2926. } else {
  2927. this.Status = '文档不是word类型'
  2928. }
  2929. }
  2930. //删除文档链接
  2931. this.HyperDelete = function() {
  2932. if (this.FileType == '.doc' || this.FileType == '.docx') {
  2933. var selection = this.WebObject.ActiveDocument.Application.Selection
  2934. selection.WholeStory()//选中全文
  2935. var HyperCount = this.WebObject.ActiveDocument.Hyperlinks.Count //获取连接数量
  2936. for (var i = 1; i <= HyperCount; i++) {
  2937. this.WebObject.ActiveDocument.Hyperlinks.Item(1).Delete() //删除连接
  2938. }
  2939. selection.MoveLeft(Unit = 1, Count = 1) //返回定位最前端
  2940. } else if (this.FileType == '.xls' || this.FileType == '.xlsx') {
  2941. this.WebObject.ActiveDocument.Application.Cells.Hyperlinks.Delete() //excel删除连接
  2942. }
  2943. }
  2944. /* ----------------------------------------------水印功能end----------------------------------------*/
  2945. /* 关闭文档 */
  2946. this.Close = function() {
  2947. if (this.obj.Close() != 0) {
  2948. return false
  2949. }
  2950. return true
  2951. }
  2952. // ******************************************************************************************************************************//
  2953. // ******************************************************************************************************************************//
  2954. // ******************************************************************************************************************************//
  2955. /** ****以下是打开本地窗口代码***** */
  2956. /** ****End 打开本地窗口代码***** */
  2957. /* 2015自带有窗口的页面设置 */
  2958. this.WebPageSetup = function() {
  2959. this.setShowDialog(this.ShowDialog.DialogPageSetup)
  2960. }
  2961. /* 2015自带有窗口的打印设置 */
  2962. this.WebOpenPrint = function() {
  2963. this.setShowDialog(this.ShowDialog.DialogPrint)
  2964. }
  2965. /* 打印预览 */
  2966. this.PrintPreview = function() {
  2967. this.obj.PrintPreview()
  2968. }
  2969. /* 退出打印预览 */
  2970. this.PrintPreviewExit = function() {
  2971. this.obj.PrintPreviewExit()
  2972. this.obj.ActiveDocument.ActiveWindow.View.ShowFieldCodes = false
  2973. }
  2974. /* 增加自定义工具栏按钮 */
  2975. this.AppendTools = function(Index, Caption, Icon) {
  2976. parseInt(Index)
  2977. var customtoolbar = this.obj.CustomToolbar
  2978. customtoolbar.AddToolButton(Index, Caption, Icon, Caption, 0) //Icon为图片路径
  2979. }
  2980. /* 按钮是否有效 */
  2981. this.DisableTools = function(Caption, Flag) {
  2982. var customtoolbar = this.obj.CustomToolbar
  2983. customtoolbar.DisableToolsButton(Caption, Flag)
  2984. this.obj.Style.Invalidate()
  2985. }
  2986. /* 自定义工具栏按钮是否显示 */
  2987. this.VisibleTools = function(Caption, Flag) {
  2988. var customtoolbar = this.obj.CustomToolbar
  2989. customtoolbar.VisibleToolsButton(Caption, Flag)
  2990. this.obj.Style.Invalidate()
  2991. }
  2992. /* 增加菜单 */
  2993. var MenuFile
  2994. this.AppendMenu = function(Index, Caption) {
  2995. var custommenu = this.obj.CustomMenu
  2996. if (MenuFile == undefined || MenuFile == null) {
  2997. custommenu.Clear()
  2998. MenuFile = custommenu.CreatePopupMenu()
  2999. custommenu.Add(MenuFile, '文件(&F)')
  3000. }
  3001. custommenu.AppendMenu(MenuFile, Index, false, Caption)
  3002. custommenu.Update()
  3003. }
  3004. this.AddCustomMenu = function() {
  3005. var custommenu = this.obj.CustomMenu
  3006. //创建文件菜单的条目
  3007. var menufile = custommenu.CreatePopupMenu()
  3008. var menufilelv2 = custommenu.CreatePopupMenu()
  3009. custommenu.AppendMenu(menufilelv2, 6, false, '自定义二级菜单一')
  3010. custommenu.AppendMenu(menufilelv2, 7, false, '自定义二级菜单二')
  3011. custommenu.AppendMenu(menufilelv2, 0, false, '-')
  3012. var menufilelv3 = custommenu.CreatePopupMenu()
  3013. custommenu.AppendMenu(menufilelv3, 8, false, '自定义三级菜单一')
  3014. custommenu.AppendMenu(menufilelv3, 0, false, '-')
  3015. custommenu.AppendMenu(menufilelv3, 9, false, '自定义三级菜单二')
  3016. custommenu.AppendMenu(menufilelv2, menufilelv3, true, '自定义三级菜单')
  3017. custommenu.AppendMenu(menufilelv2, 10, false, '自定义二级菜单三')
  3018. custommenu.AppendMenu(menufile, menufilelv2, true, '自定义二级菜单')
  3019. //将文件菜单添加到顶级主菜单
  3020. custommenu.AppendMenu(menufile, 17, false, '启用保存')
  3021. custommenu.AppendMenu(menufile, 18, false, '禁止保存')
  3022. custommenu.AppendMenu(menufile, 0, false, '-')
  3023. custommenu.AppendMenu(menufile, 19, false, '启用打印')
  3024. custommenu.AppendMenu(menufile, 20, false, '禁止打印')
  3025. custommenu.Add(menufile, '编辑(&E)')
  3026. //创建语言
  3027. /* var menuLang = custommenu.CreatePopupMenu();
  3028. custommenu.AppendMenu(menuLang, 22, false, "简体中文");
  3029. custommenu.AppendMenu(menuLang, 23, false, "繁体中文(TW)");
  3030. custommenu.AppendMenu(menuLang, 24, false, "繁体中文(HK)")
  3031. custommenu.AppendMenu(menuLang, 25, false, "英文");
  3032. custommenu.Add(menuLang, "多语言(&N)");*/
  3033. //通知系统更新菜单
  3034. custommenu.Update()
  3035. }
  3036. /* 获取当前文档打开类型,以后缀名来区别 */
  3037. this.WebGetDocSuffix = function() {
  3038. try {
  3039. var docType = this.getDocType(this.FileType) // 判断是文档还是表格
  3040. var FileTypeValue = 0 // 判断打开文档的值 0:doc,12:docx,51:xls,56:xlsx
  3041. if (docType == this.DocType.WORD) // word 获取vba值的方法
  3042. {
  3043. this.Activate(true)
  3044. FileTypeValue = this.obj.ActiveDocument.SaveFormat
  3045. }
  3046. if (docType == this.DocType.EXECL) { // Execl 获取方法
  3047. this.obj.ExitExcelEditMode() // 退出当前编辑模式
  3048. FileTypeValue = this.obj.ActiveDocument.FileFormat
  3049. if (FileTypeValue < 0) { // 2003不支持该属性
  3050. FileTypeValue = 56
  3051. }
  3052. }
  3053. return this.DocSuffixType[FileTypeValue]
  3054. } catch (e) {
  3055. return this.FileType
  3056. }
  3057. }
  3058. /* iWebOffice打开的文档全路径 */
  3059. this.WebFullName = function() {
  3060. return this.obj.FullName
  3061. }
  3062. /* 更加书签插入图片 */
  3063. this.InsertImageByBookMark = function(Transparent, ZOrder) {
  3064. if (this.obj.ActiveDocument.BookMarks.Exists(this.BookMark)) {
  3065. this.obj.ActiveDocument.Bookmarks.Item(this.BookMark).Select()
  3066. }
  3067. var SelectionImage = this.obj.ActiveDocument.Application.Selection.InlineShapes.AddPicture(this.DownloadedFileTempPathName)
  3068. SelectionImage.Select()
  3069. SelectionImage.PictureFormat.TransparentBackground = Transparent //是否透明处理
  3070. var ShapeImage = SelectionImage.ConvertToShape() // 转为浮动型
  3071. ShapeImage.WrapFormat.Type = 3
  3072. ShapeImage.ZOrder(ZOrder) // 5:衬于文字下方 4:浮于文字上方
  3073. return true
  3074. }
  3075. /* 下载文档 */
  3076. this.DownloadToFile = function(DownFileName, SavePathName) {
  3077. var httpclient = this.obj.Http
  3078. var URL = this.WebUrl.substring(0, this.WebUrl.lastIndexOf('/'))
  3079. httpclient.ShowProgressUI = this.ShowWindow// 隐藏进度条
  3080. if (httpclient.Open(this.HttpMethod.Get, URL + '/Document/'
  3081. + DownFileName, false)) { // 指定下载模板的名称
  3082. if (httpclient.Send()) {
  3083. if (httpclient.Status == 200) {
  3084. httpclient.ResponseSaveToFile(SavePathName + DownFileName)
  3085. httpclient.Clear()
  3086. return true
  3087. }
  3088. }
  3089. }
  3090. httpclient.Close()
  3091. return false
  3092. }
  3093. /* 手写签批 */
  3094. this.HandWriting = function(penColor, penWidth) {
  3095. var handwritting = this.obj.Handwritting
  3096. var handsetting = handwritting.DrawingSetting
  3097. handsetting.PenThicker = penWidth
  3098. handsetting.PenColor = penColor
  3099. handwritting.AnnotateDraw()
  3100. this.ShowMenuBar(false) // 签批时隐藏菜单栏
  3101. this.ShowToolBars(false) // 签批时隐藏工具栏
  3102. }
  3103. /* 停止手写签批 */
  3104. this.StopHandWriting = function() {
  3105. var handwritting = this.obj.Handwritting
  3106. handwritting.StopAnnotate()
  3107. this.ShowMenuBar(true) // 停止签批时显示菜单栏
  3108. this.ShowToolBars(true) // 停止签批时显示工具栏
  3109. }
  3110. /* 文字签名 */
  3111. this.TextWriting = function() {
  3112. var handwritting = this.obj.Handwritting
  3113. var textsetting = handwritting.TextSetting
  3114. textsetting.TextSize = 32
  3115. textsetting.TextColor = 0xbb00ff
  3116. textsetting.FontName = '宋体'
  3117. handwritting.AnnotateText()
  3118. this.ShowMenuBar(false) // 签批时隐藏菜单栏
  3119. this.ShowToolBars(false) // 签批时隐藏工具栏
  3120. }
  3121. /* 图形签批 */
  3122. this.ShapeWriting = function() {
  3123. var handwritting = this.obj.Handwritting
  3124. var shapesetting = handwritting.ShapeSetting
  3125. shapesetting.ShapeType = 0
  3126. shapesetting.BackgroundColor = 0xffffff
  3127. shapesetting.BorderColor = 0xff0000
  3128. shapesetting.BorderWidth = 6
  3129. handwritting.AnnotateShape()
  3130. this.ShowMenuBar(false) // 签批时隐藏菜单栏
  3131. this.ShowToolBars(false) // 签批时隐藏工具栏
  3132. }
  3133. /* 取消上一次签批 */
  3134. this.RemoveLastWriting = function() {
  3135. var handwritting = this.obj.Handwritting
  3136. handwritting.RemoveLast()
  3137. }
  3138. /* 显示某用户的签批 */
  3139. this.ShowWritingUser = function(bVal, username) {
  3140. var strxml = this.obj.GetAnnotations()
  3141. var json = eval('(' + strxml + ')')
  3142. if (username != '' && username != null && username != undefined) {
  3143. for (var i = 0; i < json.Annotations.length; i++) {
  3144. if (json.Annotations[i].Annotation.User != username) {
  3145. var id = json.Annotations[i].Annotation.ID
  3146. this.obj.GetAnnotationByID(id).Visible = bVal
  3147. }
  3148. }
  3149. } else {
  3150. for (var i = 0; i < json.Annotations.length; i++) {
  3151. var id = json.Annotations[i].Annotation.ID
  3152. this.obj.GetAnnotationByID(id).Visible = bVal
  3153. }
  3154. }
  3155. }
  3156. /* 得到服务器setMsgByName的值并发送到前台 */
  3157. this.GetDataToSend = function() {
  3158. var httpclient = this.obj.Http // 设置http对象
  3159. httpclient.Clear()
  3160. var ReturnValue = httpclient.GetResponseHeader('RName')// 获取返回值
  3161. var jsonObj = eval('(' + ReturnValue + ')')
  3162. for (var i in jsonObj) {
  3163. this.WebSetMsgByName(i, jsonObj[i])
  3164. }
  3165. }
  3166. //手写签批控件属性和方法
  3167. this.IWR = null
  3168. /* 创建手写签批控件对象 */
  3169. this.CreateRevision = function() {
  3170. //判断iWebOffice2015对象是否存在
  3171. if (this.obj == null) {
  3172. this.Status = 'iWebOffice2015对象未初始化'
  3173. return false
  3174. }
  3175. //判断手写签批控件是否已创建
  3176. if (this.IWR != null) {
  3177. this.Status = '手写组件对象已存在'
  3178. return false
  3179. }
  3180. //创建手写签批控件
  3181. var ret = this.obj.CreateNew('iWebRevision.iWebRevisionCtrl.1')
  3182. if (ret != 0) {
  3183. this.Status = '创建手写组件对象失败'
  3184. return false
  3185. }
  3186. //隐藏标题栏、状态栏、菜单栏、自定义工具栏
  3187. this.ShowTitleBar(false)
  3188. this.ShowMenuBar(false)
  3189. this.ShowStatusBar(false)
  3190. this.ShowCustomToolbar(false)
  3191. this.obj.Style.BorderStyle = 0
  3192. //获取手写控件对象
  3193. this.IWR = this.obj.Application
  3194. return true
  3195. }
  3196. /* 解决打印预览里打印按钮没反应问题 */
  3197. this.OleDialogPrint = function(OLEFlag, bCancel) {
  3198. if (OLEFlag == 1) {
  3199. this.obj.ShowDialog(0) //新建文档
  3200. } else if (OLEFlag == 2) {
  3201. var exts
  3202. exts = 'Word Files(*.doc;*.docx;*.docm;*.dot;*.dotx;*.dotm;*.rtf)|*.doc;*.docx;*.docm;*.dot;*.dotx;*.dotm;*.rtf'
  3203. exts += '|Excel Files(*.xls;*.xlsx;*.xlsm;*.xlt;*.xltx;*.xltm)|*.xls;*.xlsx;*.xlsm;*.xlt;*.xltx;*.xltm'
  3204. exts += '|PowerPoint Files(*.ppt;*.pptx;*.pptm;*.pot;*.potx;*.potm)|*.ppt;*.pptx;*.pptm;*.pot;*.potx;*.potm'
  3205. exts += '|Project Files(*.mpp;*.mpt)|*.mpp;*.mpt'
  3206. exts += '|Visio Files(*.vsd;*.vdx;*.vss;*.vsx;*.vst;*.vtx;*.vsw;*.vdw;*.vsdx;*.vssx;*.vstx;*.vsdm;*.vssm;*.vstm)|*.vsd;*.vdx;*.vss;*.vsx;*.vst;*.vtx;*.vsw;*.vdw;*.vsdx;*.vssx;*.vstx;*.vsdm;*.vssm;*.vstm'
  3207. exts += '|All File(*.*)|*.*'
  3208. exts += '||'
  3209. this.obj.ShowDialog(1, exts, 0)//打开本地文档(弹窗)
  3210. } else if (OLEFlag == 4) {
  3211. this.obj.ShowDialog(2) //另存为本地文档
  3212. } else if (OLEFlag == 8) {
  3213. this.obj.ShowDialog(3) //另存为拷贝
  3214. } else if (OLEFlag == 16) {
  3215. this.obj.ShowDialog(4) //打印
  3216. } else if (OLEFlag == 32) {
  3217. this.obj.ShowDialog(5) //打印设置
  3218. } else if (OLEFlag == 64) {
  3219. this.obj.ShowDialog(6) //文档属性
  3220. } else if (OLEFlag == 128) {
  3221. this.obj.ActiveDocument.PrintPreview() //打印预览
  3222. }
  3223. }
  3224. //避免谷歌浏览器Alert被插件挡住
  3225. this.Alert = function(value) {
  3226. this.obj.FuncExtModule.Alert(value)
  3227. }
  3228. //隐藏插件避免在非ie浏览器弹出窗口被挡住问题。 0隐藏,1显示
  3229. this.HidePlugin = function(value) {
  3230. if (!this.blnIE()) {
  3231. this.obj.HidePlugin(value)
  3232. }
  3233. }
  3234. }
  3235. //////////////////////////////////////////////////////////////////////////////KGBrowser
  3236. function basePath() {
  3237. //获取当前网址,如: http://localhost:8080/ems/Pages/Basic/Person.jsp
  3238. var curWwwPath = window.document.location.href
  3239. //获取主机地址之后的目录,如: /ems/Pages/Basic/Person.jsp
  3240. var pathName = window.document.location.pathname
  3241. var pos = curWwwPath.indexOf(pathName)
  3242. //获取主机地址,如: http://localhost:8080
  3243. var localhostPath = curWwwPath.substring(0, pos)
  3244. //获取带"/"的项目名,如:/ems
  3245. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1)
  3246. //获取项目的basePath http://localhost:8080/ems/
  3247. var basePath = localhostPath + projectName + '/'
  3248. return basePath
  3249. }
  3250. /*
  3251. * url: 相对地址 : /sampes/OpenAndSave/word.jsp
  3252. * param: 跟随在url后面的get形式的参数: ?key1=value1&key2=value2&key3=value3
  3253. * onlyONE: true:如果有已经打开的弹出窗口就返回提示信息,并终止本次弹窗; false:
  3254. */
  3255. function KGBrowser() {
  3256. var kgbrowser = this
  3257. this.uuid = ''
  3258. this.getUUID = function() {
  3259. if (this.uuid == '') {
  3260. this.uuid = this.kg_uuid(16, 32)
  3261. }
  3262. return this.uuid
  3263. }
  3264. this.openWindowSPE = function(url, param, onlyONE) { // speed up 不做安装检测 , 好像效果不明显
  3265. if (onlyONE == undefined) {
  3266. onlyONE = true
  3267. }
  3268. //var strParam = '$parent_uuid=' + kgbrowser.kg_uuid;
  3269. //strParam += param;
  3270. var link = 'KGBrowser://$link:' + basePath() + url + param
  3271. // alert("link: " + link);
  3272. location.href = link
  3273. this.LongConnect()
  3274. }
  3275. this.openWindow = function(url, param, onlyONE) {
  3276. if (onlyONE == undefined) {
  3277. onlyONE = true
  3278. }
  3279. //var strParam = '$parent_uuid=' + kgbrowser.kg_uuid;
  3280. //strParam += param;
  3281. // 检测KGBrowser是否安装
  3282. $.ajax({
  3283. type: 'get',
  3284. async: false,
  3285. url: 'http://' + document.location.hostname + ':9588/QueryOpen', //此代码ip固定,端口号与Edit页面该方法一致,其他固定。
  3286. jsonp: 'hookback',
  3287. dataType: 'jsonp',
  3288. success: function(data) {
  3289. var jsonobj = eval(data)
  3290. if (jsonobj.ret == 'none' || onlyONE == false) {
  3291. var link = 'KGBrowser://$link:' + basePath() + url + param
  3292. // alert("link: " + link);
  3293. location.href = link
  3294. kgbrowser.LongConnect()
  3295. } else {
  3296. alert('有已打开的金格浏览器!')
  3297. }
  3298. },
  3299. error: function() {
  3300. var answer = confirm('未安装支持多浏览器应用程序是否点击安装\n提示:安装的时候360全部点击允许程序所有操作')
  3301. if (answer) {//判断是否点击确定
  3302. var curPath = window.document.location.href
  3303. var pathName = window.document.location.pathname
  3304. var pos = curPath.indexOf(pathName)
  3305. var localhostPath = curPath.substring(0, pos)
  3306. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1)
  3307. var webPath = localhostPath + projectName
  3308. window.location.href = webPath + '/KGBrowserSetup.exe' //安装KGBrower
  3309. }
  3310. }
  3311. })
  3312. // ie 8+, chrome and some other browsers
  3313. var head = document.head || $('head')[0] || document.documentElement// code from jquery
  3314. var script = $(head).find('script')[0]
  3315. script.onerror = function(evt) {
  3316. var answer = confirm('未安装支持多浏览器应用程序是否点击安装\n提示:安装的时候360全部点击允许程序所有操作')
  3317. if (answer) {//判断是否点击确定
  3318. var curPath = window.document.location.href
  3319. var pathName = window.document.location.pathname
  3320. var pos = curPath.indexOf(pathName)
  3321. var localhostPath = curPath.substring(0, pos)
  3322. var projectName = pathName.substring(0, pathName.substr(1).indexOf('/') + 1)
  3323. var webPath = localhostPath + projectName
  3324. window.location.href = webPath + '/KGBrowserSetup.exe' //安装KGBrower
  3325. }
  3326. // do some clean
  3327. // delete script node
  3328. if (script.parentNode) {
  3329. script.parentNode.removeChild(script)
  3330. }
  3331. // delete jsonCallback global function
  3332. var src = script.src || ''
  3333. var idx = src.indexOf('hookback=')
  3334. if (idx != -1) {
  3335. var idx2 = src.indexOf('&')
  3336. if (idx2 == -1) {
  3337. idx2 = src.length
  3338. }
  3339. var hookback = src.substring(idx + 13, idx2)
  3340. delete window[hookback]
  3341. }
  3342. }
  3343. }
  3344. this.LongConnect = function() {
  3345. var strUrl = 'http://' + document.location.hostname + ':9588/LongListen?id=' + kgbrowser.uuid
  3346. $.ajax({
  3347. type: 'get',
  3348. async: false,
  3349. url: strUrl, //此代码ip固定,端口号与Edit页面该方法一致,其他固定。
  3350. jsonp: 'hookback',
  3351. dataType: 'jsonp',
  3352. success: function(data) {
  3353. var jsonobj = eval(data)
  3354. console.log(jsonobj.ret)
  3355. if (jsonobj.ret == 'save') { //此判断处理Edit页面Msg传过来的值,判断之后下面做响应处理即可
  3356. //alert("save");
  3357. setTimeout('location.reload();', 100)
  3358. } else if (jsonobj.ret == 'returnlist') { //此判断处理Edit页面Msg传过来的值,判断之后下面做响应处理即可
  3359. alert('returnlist')
  3360. setTimeout('location.reload();', 100)
  3361. } else if (jsonobj.ret == 'none' || jsonobj.ret == 'unload') {
  3362. kgbrowser.LongConnect() //这里一定要调用,不可删除
  3363. } else {
  3364. //console.log(data);
  3365. console.log(jsonobj.ret)
  3366. //var jsonobj2 = eval('(' + jsonobj.ret + ')');
  3367. var jsonobj2 = eval(jsonobj.ret)
  3368. console.log(jsonobj2.action)
  3369. console.log(jsonobj2.func)
  3370. if (jsonobj2.action == 'save') {
  3371. setTimeout('location.reload();', 100)
  3372. } else if (jsonobj2.action == 'CallParentFunc') {
  3373. alert(jsonobj2.action)
  3374. alert(jsonobj2.func)
  3375. eval(jsonobj2.func)
  3376. kgbrowser.LongConnect()
  3377. } else if (jsonobj2.action == 'ReturnList') {
  3378. alert(jsonobj2.action)
  3379. setTimeout('location.reload();', 100)
  3380. }
  3381. }
  3382. },
  3383. error: function(a, b, c) {
  3384. }
  3385. })
  3386. }
  3387. this.kg_uuid = function(len, radix) {
  3388. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
  3389. var uuid = [], i
  3390. radix = radix || chars.length
  3391. if (len) {
  3392. // Compact form
  3393. for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * radix]
  3394. } else {
  3395. // rfc4122, version 4 form
  3396. var r
  3397. // rfc4122 requires these characters
  3398. uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
  3399. uuid[14] = '4'
  3400. // Fill in random data. At i==19 set the high bits of clock sequence as
  3401. // per rfc4122, sec. 4.1.5
  3402. for (i = 0; i < 36; i++) {
  3403. if (!uuid[i]) {
  3404. r = 0 | Math.random() * 16
  3405. uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]
  3406. }
  3407. }
  3408. }
  3409. return uuid.join('')
  3410. }
  3411. }
  3412. export { WebOffice2015 }