1 //传入一个table的id,将table的全部内容导出excel文件
2 function AutomateExcel(objTable)
3 {
4 // Start Excel and get Application object.
5 var oXL = new ActiveXObject("Excel.Application");
6 // Get a new workbook.
7 var oWB = oXL.Workbooks.Add();
8 var oSheet = oWB.ActiveSheet;
9 var hang = objTable.rows.length;
10
11 var lie = objTable.rows(0).cells.length;
12
13 // Add table headers going cell by cell.
14 for (var i=0;i<hang;i++)
15 {
16 for (var j=0;j<lie;j++)
17 {
18 oSheet.Cells(i+1,j+1).value = objTable.rows(i).cells(j).innerText;
19 }
20
21 }
22 oXL.Visible = true;
23 oXL.UserControl = true;
24 }
25
26 //描述:将固定格式的xml文件导出excel文件
27 //strXml:传入的xml字符串,一般为dataset直接getxml得到的就可以;
28 //xmlField:要导入的字段和对应的中文名称,格式如下:
29 //var xmlField="<FIELDLIST><TITLE>主题</TITLE><KEYWORD>关键词</KEYWORD><TYPE>报题来源</TYPE><CREATE_DATE>创建日期</CREATE_DATE><COLUMN_NAME>所属栏目</COLUMN_NAME></FIELDLIST>";
30 function ExpXmlToExcel(strXml,xmlField)
31 {
32 //导入xml字符串
33 var xmlDoc = new XmlDoc();
34 xmlDoc.loadXML(strXml);
35 var nodesList = xmlDoc.documentElement.childNodes;
36
37 //导入字段列表;
38 var xmlDocField = new XmlDoc();
39 xmlDocField.loadXML(xmlField);
40 var fieldList = xmlDocField.documentElement.childNodes;
41
42 // Start Excel and get Application object.
43 var oXL = new ActiveXObject("Excel.Application");
44 // Get a new workbook.
45 var oWB = oXL.Workbooks.Add();
46 var oSheet = oWB.ActiveSheet;
47 var hang = nodesList.length;
48 var lie = fieldList.length;
49 //插入表头
50
51 for (var j=0;j<lie;j++)
52 {
53 oSheet.Cells(1,j+1).value =fieldList[j].text;
54 }
55
56 // Add table headers going cell by cell.
57 for (var i=0;i<hang;i++)
58 {
59 for (var j=0;j<lie;j++)
60 {
61 oSheet.Cells(i+2,j+1).value = nodesList[i].selectSingleNode(fieldList[j].nodeName).text;
62 }
63 }
64 oXL.Visible = true;
65 oXL.UserControl = true;
66 }
67
68 //指定页面区域内容导入Word
69 //eDiv:要导出具体内容的div
70 function ExpHtmlToWord(eDiv)
71 {
72 var oWD = new ActiveXObject("Word.Application");
73 var oDC = oWD.Documents.Add("",0,1);
74 var oRange =oDC.Range(0,1);
75 var sel = document.body.createTextRange();
76
77 sel.moveToElementText(eDiv);
78 sel.select();
79 sel.execCommand("Copy");
80 oRange.Paste();
81 oWD.Application.Visible = true;
82 }
2 function AutomateExcel(objTable)
3 {
4 // Start Excel and get Application object.
5 var oXL = new ActiveXObject("Excel.Application");
6 // Get a new workbook.
7 var oWB = oXL.Workbooks.Add();
8 var oSheet = oWB.ActiveSheet;
9 var hang = objTable.rows.length;
10
11 var lie = objTable.rows(0).cells.length;
12
13 // Add table headers going cell by cell.
14 for (var i=0;i<hang;i++)
15 {
16 for (var j=0;j<lie;j++)
17 {
18 oSheet.Cells(i+1,j+1).value = objTable.rows(i).cells(j).innerText;
19 }
20
21 }
22 oXL.Visible = true;
23 oXL.UserControl = true;
24 }
25
26 //描述:将固定格式的xml文件导出excel文件
27 //strXml:传入的xml字符串,一般为dataset直接getxml得到的就可以;
28 //xmlField:要导入的字段和对应的中文名称,格式如下:
29 //var xmlField="<FIELDLIST><TITLE>主题</TITLE><KEYWORD>关键词</KEYWORD><TYPE>报题来源</TYPE><CREATE_DATE>创建日期</CREATE_DATE><COLUMN_NAME>所属栏目</COLUMN_NAME></FIELDLIST>";
30 function ExpXmlToExcel(strXml,xmlField)
31 {
32 //导入xml字符串
33 var xmlDoc = new XmlDoc();
34 xmlDoc.loadXML(strXml);
35 var nodesList = xmlDoc.documentElement.childNodes;
36
37 //导入字段列表;
38 var xmlDocField = new XmlDoc();
39 xmlDocField.loadXML(xmlField);
40 var fieldList = xmlDocField.documentElement.childNodes;
41
42 // Start Excel and get Application object.
43 var oXL = new ActiveXObject("Excel.Application");
44 // Get a new workbook.
45 var oWB = oXL.Workbooks.Add();
46 var oSheet = oWB.ActiveSheet;
47 var hang = nodesList.length;
48 var lie = fieldList.length;
49 //插入表头
50
51 for (var j=0;j<lie;j++)
52 {
53 oSheet.Cells(1,j+1).value =fieldList[j].text;
54 }
55
56 // Add table headers going cell by cell.
57 for (var i=0;i<hang;i++)
58 {
59 for (var j=0;j<lie;j++)
60 {
61 oSheet.Cells(i+2,j+1).value = nodesList[i].selectSingleNode(fieldList[j].nodeName).text;
62 }
63 }
64 oXL.Visible = true;
65 oXL.UserControl = true;
66 }
67
68 //指定页面区域内容导入Word
69 //eDiv:要导出具体内容的div
70 function ExpHtmlToWord(eDiv)
71 {
72 var oWD = new ActiveXObject("Word.Application");
73 var oDC = oWD.Documents.Add("",0,1);
74 var oRange =oDC.Range(0,1);
75 var sel = document.body.createTextRange();
76
77 sel.moveToElementText(eDiv);
78 sel.select();
79 sel.execCommand("Copy");
80 oRange.Paste();
81 oWD.Application.Visible = true;
82 }