<!DOCTYPE html>
<html>
<head>
    
<title>vbscript/javascript output excel</title>
    
<script language="vbscript">
        
Function SaveToExcel()
            
Set objXL = CreateObject("Excel.Application")
            objXL.Visible 
= True
            objXL.WorkBooks.Add()
            
Set objTB = document.getElementById("gdvSchedulePlan")'document.all("gdvSchedulePlan")
                      
            
For x=1 To objTB.rows.length
                 
For y = 1 To objTB.rows(x-1).cells.length
                     objXL.Cells(x,y).value 
= objTB.rows(x-1).cells(y-1).innerTEXT
                 
Next
            
Next
        
End Function
    
</script>
    
    
<script language="javascript">
        
function sample()
        {
            
// Declare the variables
            var Excel, Book;

            
// Create the Excel application object.
            Excel = new ActiveXObject("Excel.Application");

            
// Make Excel visible.
            Excel.Visible = true;

            
// Create a new work book.
            Book = Excel.Workbooks.Add()

            
// Place some text in the first cell of the sheet.
            Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";
            
            
//Book.ActiveSheet.Range(Book.ActiveSheet.Cells(1,1), Book.ActiveSheet.Cells(1,2)).MergeCells=true;
            // Save the sheet.
            //Book.SaveAs("C:\\TEST.XLS");

            
// Close Excel with the Quit method on the Application object.
            //Excel.Application.Quit();

        }
    
        
function JsSaveToExcel()
        {
            
var exlApp = new ActiveXObject("Excel.Application");
            
var exlWorkbooks = exlApp.workbooks.add();
            
var exlWorksheets = exlWorkbooks.worksheets.add();
            exlApp.DisplayAlerts 
= false;
            exlApp.visible 
= true;
            
            
var table = document.getElementById("gdvSchedulePlan");
            
            
var colIndexArr = new Array();
            
var rowSpanArr = new Array();
            
            
for(var i=0; i<table.rows.length; i++)
            {
                
for(var j=0; j<table.rows[i].cells.length; j++)
                {
                    exlWorksheets.cells(i
+1, j+1).value = table.rows[i].cells[j].innerText;
                    
var mergeCol = table.rows[i].cells[j].getAttribute("colspan");
                    
//var mergeRow = table.rows[i].cells[j].getAttribute("rowspan");
                    exlWorksheets.Range(exlWorksheets.cells(i+1, j+1), exlWorksheets.cells(i+1, j+1 + mergeCol - 1)).MergeCells = true;
                }
            }
        }
        
        
function toExcel()
        {
            
var objTable = document.getElementById("gdvSchedulePlan");
            
            
var wraper = document.getElementById("wraper1119");
            
if (wraper == null)
            {
                
var wraper = document.createElement("table");
                wraper.id 
= "wraper1119";
                
//wraper.style.display = "none";
                document.body.insertBefore(wraper);
            }
            
            
//clear row
            while (wraper.rows.length>0)
            {
                wraper.deleteRow(
0);
            }
            
            
//copy attribute
            for(var i=0; i<objTable.attributes.length; i++)
            {
                
var oAttr = objTable.attributes.item(i);
                wraper.setAttribute(oAttr.nodeName, oAttr.nodeValue);
                
//alert(oAttr.nodeName + ": " + oAttr.nodeValue);
            }
            
            
//copy rows
            //alert(objTable.children.item(0).tagName)
            var tempRow = wraper.insertRow();
            
for(var i=0; i<objTable.rows.length; i++)
            {
                
var row0 = objTable.rows(i).cloneNode(true);
                wraper.tBodies(
0).appendChild(row0);
            }
            wraper.deleteRow(
0);//delete temp row
            return;
            
            
            
var row = wraper.insertRow();
            
var cell = row.insertCell();
            
            
var tempTable = objTable.cloneNode(true);
            cell.appendChild(tempTable);

            
//cleanup
            
            
var oControlRange = document.body.createControlRange(); 
            oControlRange.add(wraper,
0);                 
            oControlRange.select(); 
            document.execCommand(
"Copy"); 

            
var xls;
            
try
            { 
                xls 
= new ActiveXObject( "Excel.Application" ); 
            }
            
catch(e)
            { 
                alert( 
"Excel没有安装或浏览器设置不正确.请启用所有Active控件和插件"); 
                
return false
            } 

            xls.visible 
= true
            
var xlBook = xls.Workbooks.Add; 
            
var xlsheet = xlBook.Worksheets(1); 
            xlBook.Worksheets(
1).Activate; 
            
for(var i=0;i<objTable.rows(0).cells.length;i++)
            { 
                xlsheet.Columns(i
+1).ColumnWidth=15;               
            } 
            xlsheet.Paste; 
            xls
=null
        }
        
        
//把html table的数据导入到Excel中。
        function toExcel2()
        {
            
var objTable = document.getElementById("ctl00_contentBody_gdvSchedulePlan");
            
            
var tempTable = objTable.cloneNode(true);
            tempTable.removeAttribute(
"id");
            tempTable.style.display 
= "none";
            tempTable.id
="tempTable1119"
            document.body.insertBefore(tempTable);
            
            
//cleanup
            for(var i=0; i<tempTable.rows.length; i++)
            {
                
for(var j=tempTable.rows[i].cells.length-1; j>=0; j--)
                {
                    
var cell = tempTable.rows[i].cells[j];
                    
if (cell.style.display.toLowerCase() == "none")
                    {
                        tempTable.rows[i].removeChild(cell);
                        
continue;
                    }
                    removeHiddenElement(tempTable.rows[i].cells[j]);
                }
            }
            
            
var oControlRange = document.body.createControlRange(); 
            oControlRange.add(tempTable,
0);                 
            oControlRange.select(); 
            document.execCommand(
"Copy"); 
            
            document.body.removeChild(tempTable);

            
var xls;
            
try
            { 
                xls 
= new ActiveXObject( "Excel.Application" ); 
            }
            
catch(e)
            { 
                alert( 
"Excel没有安装或浏览器设置不正确.请启用所有Active控件和插件"); 
                
return false
            } 

            xls.visible 
= true
            
var xlBook = xls.Workbooks.Add; 
            
var xlsheet = xlBook.Worksheets(1); 
            xlBook.Worksheets(
1).Activate; 
            
for(var i=0;i<objTable.rows(0).cells.length;i++)
            { 
                xlsheet.Columns(i
+1).ColumnWidth=15;               
            } 
            xlsheet.Paste; 
            xls
=null
        }
        
        
//递归,遍历每个单元格,只保留文字资料,删除input,image,以及隐藏的元素
        function removeHiddenElement(parentElement)
        {
            
if (parentElement != null)
            {
                
for(var i=parentElement.children.length-1; i >= 0; i--)
                {
                    
var cld = parentElement.children(i);
                    
if (cld.tagName.toLowerCase() == "input" 
                        
|| cld.tagName.toLowerCase() == "img" )
                    {
                        parentElement.removeChild(cld);
                        
continue;
                    }
                    
                    
if (cld.style.display.toLowerCase() == "none")
                    {
                        parentElement.removeChild(cld);
                        
continue;
                    }
                    
                    
if (cld.children.length > 0)
                    {
                        removeHiddenElement(cld);
                    }
                }
            }
        }

    
</script>
</head>
<body>
<input id="btnDownloadToExcel" type="button" value="DownToExcel" onclick="toExcel2()" />
<style>
.tbclass th 
{ color:blue; }
</style>
<table id="gdvSchedulePlan" class="tbclass" border="1" style="border-collapse:collapse;">
    
<tr>
        
<th>
            
<span>Project</span>
            
<span></span>
        
</th>
        
<th>
            
<span>Item 1st</span>
            
<span></span>
        
</th>
        
<th>
            
<span>Item 2nd</span>
            
<span></span>
        
</th>
        
<th>
            
<span>Owner</span>
            
<span></span>
        
</th>
    
</tr>
    
<tr>
        
<td rowspan="8">
            
<div>
                
<span style="display:none;">be61a85a-6da3-4876-85f7-2958d17efd97</span>
                
<span>-</span>
                
<span style="display:none;">true</span>
                
<span>[Machine Shop]委托查询日历.100719</span>
                
<span style="display:none;">be61a85a-6da3-4876-85f7-2958d17efd97</span>
                
<span></span>
                
<img src="http://bisdev28.corpnet.auo.com/pmp/client_support/icons/page_white.png" />
            
</div>
        
</td>
        
<td>
            
<div>
                
<span style="display:none;">be61a85a-6da3-4876-85f7-2958d17efd97</span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span>制定工作计划</span>
                
<span style="display:none;">bbbb</span>
                
<span style="display:none;"></span>
                
<href="#">
                    
<img border="0" src="http://bisdev28.corpnet.auo.com/pmp/client_support/icons/link.png" />
                
</a>
            
</div>
        
</td>
        
<td>
            
<div>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
            
</div>
        
</td>
        
<td>
            
<div>
                
<span></span>
                
<span style="display:none;">DEXTRYS018</span>
                
<span style="display:none;">be61a85a-6da3-4876-85f7-2958d17efd97</span>
                
<span style="display:none;">2a3449cc-126c-4123-bc05-0152dc78f544</span>
                
<span style="display:none;">2010-07-23</span>
                
<span style="display:none;">2010-7-23 0:00:00</span>
                
<span style="display:none;">2010-07-23</span>
                
<span style="display:none;">2010-7-23 0:00:00</span>
                
<span style="display:none;">1</span>
                
<span style="display:none;"></span>
                
<span style="display:none;">c9c18648-acdd-4371-8ea5-07d25d8e0538</span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
           
</div>
        
</td>
    
</tr>
    
<tr>
        
<td>系统分析,需求理解,搭建开发环境</td>
        
<td></td>
        
<td>Bisdev01</td>
    
</tr>
    
<tr>
        
<td>需求确认</td>
        
<td></td>
        
<td>
            
<div>
                
<span></span>
                
<span style="display:none;">DEXTRYS018</span>
                
<span style="display:none;">be61a85a-6da3-4876-85f7-2958d17efd97</span>
                
<span style="display:none;">2a3449cc-126c-4123-bc05-0152dc78f544</span>
                
<span style="display:none;">2010-07-23</span>
                
<span style="display:none;">2010-7-23 0:00:00</span>
                
<span style="display:none;">2010-07-23</span>
                
<span style="display:none;">2010-7-23 0:00:00</span>
                
<span style="display:none;">1</span>
                
<span style="display:none;"></span>
                
<span style="display:none;">c9c18648-acdd-4371-8ea5-07d25d8e0538</span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
                
<span style="display:none;"></span>
           
</div>
        
</td>
    
</tr>
    
<tr>
        
<td rowspan="3">编码</td>
        
<td>查询/委托查询(表格)页面</td>
        
<td>Bisdev01</td>
    
</tr>
    
<tr>
        
<td>管理功能/委托管理</td>
        
<td>Bisdev01</td>
    
</tr>
    
<tr>
        
<td>查询委托查询(日历)</td>
        
<td>Bisdev01</td>
    
</tr>
    
<tr>
        
<td colspan="2">测试</td>
        
<td>Bisdev01</td>
    
</tr>
    
<tr>
        
<td>发布</td>
        
<td></td>
        
<td>Bisdev01</td>
    
</tr>
    
<tr>
        
<td>R12 Report 开发</td>
        
<td>制定工作计划、需求分析</td>
        
<td></td>
        
<td>bisdev01</td>
    
</tr>
</table>
<hr />

<table class="scheduleNew_gdv" cellspacing="0" rules="all" QueryMode="Normal" SelectedColumnIndex border="1" id="ctl00_contentBody_gdvSchedulePlan" style="border-collapse:collapse;">
    
<tr>
        
<th class="scheduleNew_gdvItem" cellExpanded="Y" cellIndex="0" scope="col">Project</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="Y" cellIndex="1" scope="col">Item 1st</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="Y" cellIndex="2" scope="col">Item 2nd</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="Y" cellIndex="3" scope="col" style="display:none;">Item 3rd</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="Y" cellIndex="4" scope="col" style="display:none;">Item 4th</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="Y" cellIndex="5" scope="col">Owner</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="Y" cellIndex="6" scope="col">Progress</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="N" cellIndex="7" scope="col">BeginDate</th>
        
<th class="scheduleNew_gdvItem" cellExpanded="N" cellIndex="8" scope="col">EndDate</th>
        
<th>10-11-12</th>
        
<th>10-11-13</th>
        
<th>10-11-14</th>
        
<th>10-11-15</th>
        
<th>10-11-16</th>
        
<th>10-11-17</th>
        
<th>10-11-18</th>
        
<th>10-11-19</th>
        
<th>10-11-20</th>
        
<th>10-11-21</th>
        
<th>10-11-22</th>
        
<th>10-11-23</th>
        
<th>10-11-24</th>
        
<th>10-11-25</th>
        
<th>10-11-26</th>
        
<th>10-11-27</th>
        
<th>10-11-28</th>
        
<th>10-11-29</th>
        
<th>10-11-30</th>
        
<th>10-12-01</th>
        
<th>10-12-02</th>
    
</tr>
    
<tr>
        
<td class="scheduleNew_gdvItem" isExpanded="true" canPublish="false" rowspan="8">[Machine Shop]委託查詢日曆.100719</td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" columnIndex="1" rowspan="1">制定工作计划</td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" rowspan="1"></td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" rowspan="1" style="display:none;"></td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" rowspan="1" style="display:none;"></td>
        
<td class="scheduleNew_gdvItem"></td>
        
<td class="scheduleNew_gdvItem">100%</td>
        
<td class="scheduleNew_gdvItem">2010-07-23</td>
        
<td class="scheduleNew_gdvItem">2010-07-23</td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_9"></span></td>
        
<td class="scheduleNew_gdvItemWeekend"><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_10"></span></td>
        
<td class="scheduleNew_gdvItemWeekend"><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_11"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_12"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_13"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_14"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_15"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_16"></span></td>
        
<td class="scheduleNew_gdvItemWeekend"><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_17"></span></td>
        
<td class="scheduleNew_gdvItemWeekend"><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_18"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_19"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_20"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_21"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_22"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_23"></span></td>
        
<td class="scheduleNew_gdvItemWeekend"><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_24"></span></td>
        
<td class="scheduleNew_gdvItemWeekend"><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_25"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_26"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_27"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_28"></span></td>
        
<td><span id="ctl00_contentBody_gdvSchedulePlan_ctl02_lblWorkHours_29"></span></td>
    
</tr>
    
<tr class="scheduleNew_gdvRow">
        
<td class="scheduleNew_gdvItem" isExpanded="true" canPublish="false" isHiddenSpan="true" style="display:none;">
            
<div id="ctl00_contentBody_gdvSchedulePlan_ctl03_divItem0" style="width:90px;display:;">
                
<span id="ctl00_contentBody_gdvSchedulePlan_ctl03_lblRequirementName">[Machine Shop]委託查詢日曆.100719 </span>
            
</div>
        
</td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" onclick="e_.Cell_Click(1,1);" oncontextmenu="e_.CellIssue_RightClick(this, 1 );return false;" onmousemove="$_ddn('ddnIssueMenu').mouseOut();" columnIndex="1" rowspan="1">
            
<div id="ctl00_contentBody_gdvSchedulePlan_ctl03_divItem1" style="width:125px;display:;">
                
<span id="ctl00_contentBody_gdvSchedulePlan_ctl03_lblItem1st" style="display:inline;">系统分析,需求理解,搭建开发环境</span>
            
</div>
        
</td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" rowspan="1">
            
<div id="ctl00_contentBody_gdvSchedulePlan_ctl03_divItem2" style="width:130px;display:;">
                
<span id="ctl00_contentBody_gdvSchedulePlan_ctl03_lblItem2st"></span>
            
</div>
        
</td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" rowspan="1" style="display:none;">
            
<div id="ctl00_contentBody_gdvSchedulePlan_ctl03_divItem3" style="width:125px;display:;">
                
<span id="ctl00_contentBody_gdvSchedulePlan_ctl03_lblItem3st"></span>
            
</div>
        
</td>
        
<td class="scheduleNew_gdvItem" isExpanded="true" rowspan="1" style="display:none;">
            
<div id="ctl00_contentBody_gdvSchedulePlan_ctl03_divItem4" style="width:115px;display:;">
                
<span id="ctl00_contentBody_gdvSchedulePlan_ctl03_lblItem4st"></span> 
            
</div>
        
</td>
        
<td></td>
        
<td>100%</td>
        
<td>2010-07-26</td>
        
<td>2010-07-27</td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
        
<td></td>
    
</tr>
</table>
</body>
</html>

 

 

posted on 2010-11-19 15:52  Louis.Lu.Sz  阅读(694)  评论(0编辑  收藏  举报