Code:
/**
* <p> Title: Export content to word by replacing word bookmarks</p>
* <p> Description: **</p>
* <p> Copyright: Copyright (c) 2007-2010 </p>
* <p> Company: ** </p>
* @author zhu
* @version 1.0
*/
var baseVoListObj = function(){
= new Array();
= new Array();
= new Array();
}
var WordApp = function(wordTplPath){
var wordObj = new ActiveXObject("");
if(wordObj==null){
alert( "No Word object can be created!");
}
=false;
= wordObj;
= (getRootPath() + wordTplPath);
}
= function(){
if ( !=null){
();
}
}
= function(strName,content,type){
if ((strName)) {
if (type != null && type == "pic") {//Pic
var objDoc = (strName).();
var objSelection = ;
();
//alert(getRootPath()+content);
var objShape = (getRootPath()+content);
}
else {
(strName).();
= content;
}
}else{
//alert("tag does not exist");
}
}
= function(voObj){
if(typeof voObj != "object"){
alert("Please enter the correct vo object");
}else{
for(var i in voObj){
(i,voObj[i]);
}
}
}
= function(voObj){
if(typeof voObj !="object"){
alert("Please enter the correct vo object");
}else{
for(var i in voObj){
(i,voObj[i],"pic");
}
}
}
= function(strName,voListObj){
if(typeof voListObj != "object"){
alert("The parameter should be array type");
}else{
var row = ;
var col = ;
var objDoc = (strName).Range;
var objTable = (objDoc,row,col) ;//Insert the table
for (var i = 0; i < row; i++) {
for(var j=0; j<col; j++){
//Todo If there is an image type in the list that does not support it, you need to judge it
(i+1,j+1).([i][[j]]);
var width = [j];
if(("px")!=-1){
(i+1,j+1).Width = ((0,-2)/100) * 28.35;//1 cm = 28.35 lbs
}
}
}
//(16);
= 1
= 0;
}
}
= function(formName,arrayObj){//The second parameter can be empty, and when not filled in, it defaults to all elements in the form
var formObj = [formName];
if(formObj!=null){
if(arrayObj!=null){
if(arrayObj instanceof Array){
var vo = {};
for(var i=0;i<;i++){
if([arrayObj[i]]!= undefined ){
eval("vo." + arrayObj[i] + " = [arrayObj[i]].value;");
}
}
//alert(objToString(vo));
return vo;
}else{
alert("The two parameters of my brother should be array type");
}
}else{
var vo = {};
for(var i=0;i<;i++){
eval("vo." + [i].name + " = [i].value;");
}
return vo;
}
}else{
alert("The form represented by the first parameter does not exist");
return null;
}
}
= function (formName,arrayObj){//Form name, attribute array (can be empty)
//var formArray = [formName];
var formArray = (formName);
if (formArray != null) {
if (arrayObj instanceof Array) {
var voListObj = new baseVoListObj();
for(var i=0;i<;i++){
var vo = {};
for(var j=0;j<;j++){
if(formArray[i].elements[arrayObj[j]]!= undefined ){
eval("vo."+arrayObj[j]+" = formArray[i].elements[arrayObj[j]].value;");
if(i==0){//Define the valid attributes and widths at the first time
(arrayObj[j]);
(formArray[i].elements[arrayObj[j]].);
}
}
}
(vo);
}
return voListObj;
}else{
var voListObj = new baseVoListObj();
for(var i=0;i<;i++){
var vo = {};
for(var j=0;j<formArray[i].;j++){
eval("vo."+formArray[i].elements[j].name+" = formArray[i].elements[j].value;");
if(i==0){//Define the width at the first time
(formArray[i].elements[j].name);
(formArray[i].elements[j].);
}
}
(vo);
}
return voListObj;
}
}else{
return null;
}
}
function objToString(obj){
if(obj instanceof Array){
var str="";
for(var i=0;i<;i++){
str+="[";
for(var j in obj[i]){
str+=j+"="+obj[i][j]+" ";
}
str+="]\n";
}
return str;
}else if(obj instanceof Object){
var str="";
for(var i in obj){
str+=i+"="+obj[i]+" ";
}
return str;
}
}
function getRootPath()
{
var location=;
if ("file:" == ) {
var str = ();
return (("/").reverse()[0], "");
}
var pathName=("/");
return +"//"++"/"+pathName[1]+"/";
}
Let’s talk about this first, and update it in the future. I hope it will be useful to everyone.