将后台数据读取到前台的EXCEL文件中去,用javascript实现.(发一个原创)

来源:互联网 发布:怎样查看淘宝买家信誉 编辑:程序博客网 时间:2024/05/12 06:57

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">

<%
    Response.Write(
"请加入信任站点");
 
%>
        
<script language="javascript" type="text/javascript">
             
var xlApp,xlBook,xlSheet;
             xlApp 
= new ActiveXObject("Excel.Application");
             xlBook 
= xlApp.Workbooks.Add();
             xlBook.Worksheets.Add();
             xlBook.Worksheets.Add();
             
var quArray = new Array(" ","1","2","3","4","5");    
             
var i;
             
for( i=1;i<quArray.length;i++)
            {
                  xlSheet 
= xlBook.Worksheets(i);
                  xlSheet.Name 
= quArray[i];
             }
               
         
<%
              
for(int j=1;j<=5;j++)
              {               
         
%>
               xlSheet 
= xlBook.Worksheets(quArray[<%=j%>]);
               i
=1;
               xlSheet.Cells(i
++,1).Value = "小名";
               xlSheet.Cells(
1,2).Value = "d";
               xlSheet.Cells(
1,3).Value = "a";
               xlSheet.Cells(
1,4).Value = "c";
               
               
var con = i-1;        
               xlSheet.Rows(
"1:"+con).Font.Size = 9;
               xlSheet.Rows(
"1:"+con).RowHeight = 15;
               xlSheet.Range(
"A1:D1").Interior.ColorIndex = 15;
               xlSheet.Range(
"A1:D1").Interior.Pattern = 1;
               xlSheet.Range(
"A1:D1").Font.ColorIndex = 1;
               xlSheet.Range(
"A1:D1").HorizontalAlignment = 3;   
               xlSheet.Range(
"A1:D"+con).Borders.Weight = 2;
               xlSheet.Range(
"A1:D"+con).Borders.ColorIndex = 1;
               xlSheet.Columns(
"A:D").EntireColumn.AutoFit;               

<%
     }
%>
              
    xlApp.Visible 
= true;
    idTmr 
= window.setInterval("Cleanup();",1);
function Cleanup() {
   window.clearInterval(idTmr);
   CollectGarbage();
 }
  window.opener
=null;
window.close();
            
        
</script>

    
</form>
</body>
</html>