//--------------------------------------导出WORD部分----------------------------------------------------------------------
var doc = null;
var oDC = null;
function __wordPrintCore($tableId,$title,$Orientation,$username,$wordtime) {
//获得table
var table = __get($tableId);
if(table==null){
alert("无法取得要导出的表格,请确认表格ID正确性");
return;
}
var rowLen = table.rows.length;
var colLen = table.rows(0).cells.length;
if(rowLen<=4) { //没有记录或者只有一条记录时
if(table.rows(1).cells(0).innerText=="没有记录" || table.rows(2).cells(0).innerText=="没有记录"){
alert("对不起,没有数据要导出到WORD");
return;
}
}
//创建word应用程序对象
try {
if(doc==null){
doc = new ActiveXObject("Word.Application");
}
}catch(e) {
alert("不能正确调用Word,请确认是否已经将网站设置为安全站点、Word已安装且设置浏览器允许ActiveX运行");
return;
}
try{
oDC = doc.Documents.Add("",0,1);//创建空白Word文档
}catch(e){
doc = new ActiveXObject("Word.Application");
oDC = doc.Documents.Add("",0,1);//创建空白Word文档
}
//doc的属性
doc.ActiveDocument.ActiveWindow.View.Type=3;//设定显示为页面视图状态
doc.ActiveWindow.View.TableGridlines = false;//表格不可见
//标题
doc.Selection.ParagraphFormat.Alignment=0; //1居中对齐,2为居右 ,0为居左
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=16;
doc.Selection.TypeText("专呈:"+$username+"同志");
doc.Selection.TypeParagraph();//插入段落
//副标题
doc.Selection.ParagraphFormat.Alignment=1; //1居中对齐,0为居右
//doc.Selection.MoveRight("1");//光标右移字符
doc.Selection.TypeParagraph();//
doc.Selection.Font.Size=16;
doc.Selection.TypeText($title);
doc.Selection.TypeParagraph();
doc.Selection.TypeParagraph();
doc.Selection.ParagraphFormat.Alignment=0; //1居中对齐,0为居右
for(var i=1;i<rowLen-1;i++){//标题栏没取
for(var j=0;j<colLen-1;j++) {//最后一栏没取
if(j==0){
var text = table.rows(i).cells(j).innerText;//获取每一单元格的内容
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=16;
doc.Selection.TypeText(text);
doc.Selection.TypeParagraph();//插入段落
}else{
var text = table.rows(i).cells(j).innerText+" ";//获取每一单元格的内容
//此为加粗显示(若格式出现错误可注释该代码)
var text1 = "";
var text2 = "";
var text3 = "";
var text4 = "";
var text5 = "";
var text6 = "";
if(text!=null){
var num = text.indexOf("\r\n");
text1 = text.substr(0,num);//第一行内容
text2 = text.substr(num,text.length);//第二行内容
if(text1!=null){
var num1 = text1.indexOf("同志");
text3 = text1.substr(0,num1+2);//加粗内容
text4 = text1.substr(num1+2,text1.length);//不加粗内容
}
if(text2!=null){
var num2 = text2.indexOf("同志");
text5 = text2.substr(0,num2+2);
text6 = text2.substr(num2+2,text2.length);
}
}
//第一行
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=14;
doc.Selection.TypeText(text3);
doc.Selection.Font.Bold=false;
doc.Selection.Font.Size=13;
doc.Selection.TypeText(text4);
//第二行
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=14;
doc.Selection.TypeText(text5);
doc.Selection.Font.Bold=false;
doc.Selection.Font.Size=13;
doc.Selection.TypeText(text6);
//此为不加粗显示
}
}
doc.Selection.TypeParagraph();
}
doc.Selection.ParagraphFormat.Alignment=2;
doc.Selection.TypeText($wordtime);
doc.Application.Visible = true;//导出的文档是否可见(放在最后当加载完数据再显示word)
}
var doc = null;
var oDC = null;
function __wordPrintCore($tableId,$title,$Orientation,$username,$wordtime) {
//获得table
var table = __get($tableId);
if(table==null){
alert("无法取得要导出的表格,请确认表格ID正确性");
return;
}
var rowLen = table.rows.length;
var colLen = table.rows(0).cells.length;
if(rowLen<=4) { //没有记录或者只有一条记录时
if(table.rows(1).cells(0).innerText=="没有记录" || table.rows(2).cells(0).innerText=="没有记录"){
alert("对不起,没有数据要导出到WORD");
return;
}
}
//创建word应用程序对象
try {
if(doc==null){
doc = new ActiveXObject("Word.Application");
}
}catch(e) {
alert("不能正确调用Word,请确认是否已经将网站设置为安全站点、Word已安装且设置浏览器允许ActiveX运行");
return;
}
try{
oDC = doc.Documents.Add("",0,1);//创建空白Word文档
}catch(e){
doc = new ActiveXObject("Word.Application");
oDC = doc.Documents.Add("",0,1);//创建空白Word文档
}
//doc的属性
doc.ActiveDocument.ActiveWindow.View.Type=3;//设定显示为页面视图状态
doc.ActiveWindow.View.TableGridlines = false;//表格不可见
//标题
doc.Selection.ParagraphFormat.Alignment=0; //1居中对齐,2为居右 ,0为居左
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=16;
doc.Selection.TypeText("专呈:"+$username+"同志");
doc.Selection.TypeParagraph();//插入段落
//副标题
doc.Selection.ParagraphFormat.Alignment=1; //1居中对齐,0为居右
//doc.Selection.MoveRight("1");//光标右移字符
doc.Selection.TypeParagraph();//
doc.Selection.Font.Size=16;
doc.Selection.TypeText($title);
doc.Selection.TypeParagraph();
doc.Selection.TypeParagraph();
doc.Selection.ParagraphFormat.Alignment=0; //1居中对齐,0为居右
for(var i=1;i<rowLen-1;i++){//标题栏没取
for(var j=0;j<colLen-1;j++) {//最后一栏没取
if(j==0){
var text = table.rows(i).cells(j).innerText;//获取每一单元格的内容
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=16;
doc.Selection.TypeText(text);
doc.Selection.TypeParagraph();//插入段落
}else{
var text = table.rows(i).cells(j).innerText+" ";//获取每一单元格的内容
//此为加粗显示(若格式出现错误可注释该代码)
var text1 = "";
var text2 = "";
var text3 = "";
var text4 = "";
var text5 = "";
var text6 = "";
if(text!=null){
var num = text.indexOf("\r\n");
text1 = text.substr(0,num);//第一行内容
text2 = text.substr(num,text.length);//第二行内容
if(text1!=null){
var num1 = text1.indexOf("同志");
text3 = text1.substr(0,num1+2);//加粗内容
text4 = text1.substr(num1+2,text1.length);//不加粗内容
}
if(text2!=null){
var num2 = text2.indexOf("同志");
text5 = text2.substr(0,num2+2);
text6 = text2.substr(num2+2,text2.length);
}
}
//第一行
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=14;
doc.Selection.TypeText(text3);
doc.Selection.Font.Bold=false;
doc.Selection.Font.Size=13;
doc.Selection.TypeText(text4);
//第二行
doc.Selection.Font.Bold=true;
doc.Selection.Font.Size=14;
doc.Selection.TypeText(text5);
doc.Selection.Font.Bold=false;
doc.Selection.Font.Size=13;
doc.Selection.TypeText(text6);
//此为不加粗显示
}
}
doc.Selection.TypeParagraph();
}
doc.Selection.ParagraphFormat.Alignment=2;
doc.Selection.TypeText($wordtime);
doc.Application.Visible = true;//导出的文档是否可见(放在最后当加载完数据再显示word)
}