openrowset怕是做不了,你需要用程序来做了

解决方案 »

  1.   

    我的脚本::<SCRIPT LANGUAGE="javascript"> 
     
    function AutomateExcel() 

    // new excel try {
          var oXL    = new ActiveXObject ( "Excel.Application" );
         }
     catch(e) 
         {
    alert( "***** 错误提示:您的电脑没有安装Excel软件;或者你的浏览器“ActiveX 控件”被禁用;请在浏览器的【安全设置】中启用“ActiveX控件和插件”! ");
    return "";
         }// new book
    var oWB = oXL.Workbooks.Add(); 
    var oSheet = oWB.ActiveSheet; 
    var table = document.all.data; 
    var tabletop = document.all.tabletop;
    var tablebuttom = document.all.tablebuttom;var hang = table.rows.length; 
    var lie = table.rows(0).cells.length; // Add table headers going cell by cell. 
    // oSheet.Cells(i+1,j+1).Font.Italic = False; // 斜体
    // oSheet.Cells(i+1,j+1).Interior.ColorIndex=15; // 15:背景色深;2:白色;
    // oSheet.Cells(i+1,j+1).Font.ColorIndex = 3; //字体颜色
    // oSheet.Range("A1:B1").merge();  // 合并单元格区域 A1:B1//1: 标题oSheet.Range("A1:G1").merge();  // 合并单元格区域 A1:G1
    oSheet.Range("A2:G2").merge();  
    oSheet.Range("A3:G3").merge();  
    oSheet.rows(1).RowHeight = 40; // 设置行高
    oSheet.Cells(1,1).Font.Bold = true;  //粗体
    oSheet.Cells(1,1).Font.Size = 20; // 字体大小
    oSheet.Cells(1,1).HorizontalAlignment=3;  // 1:右对齐;2:左对齐 3:水平居中
    oSheet.Cells(1,1).value="出库扫码品牌统计汇总表";    // 标题//2: 表头oSheet.Cells(3,1).Font.Size = 11; // 字体大小
    oSheet.rows(3).RowHeight = 40; // 设置行高
    oSheet.Cells(3,1).value=tabletop.rows(2).cells(0).innerText;//3: 表格内容
    for (i=3;i<hang+3;i++) 

    for (j=0;j<lie;j++) 

       if (i==3) 
         {oSheet.Cells(i+1,j+1).Interior.ColorIndex=15; 
          oSheet.rows(i+1).RowHeight = 25;}              // 设置行高
       else 
         {oSheet.Cells(i+1,j+1).Interior.ColorIndex=0;
          oSheet.rows(i+1).RowHeight = 20;}             // 设置行高   oSheet.cells(i+1,j+1).Borders.LineStyle=1;    // 单元格加边框
       oSheet.Cells(i+1,j+1).EntireColumn.AutoFit;   // 列自动宽度
      
       oSheet.Cells(i+1,j+1).Font.Size = 11;         // 字体大小
       oSheet.Cells(i+1,j+1).HorizontalAlignment=2;  // 1:右对齐;2:左对齐 3:水平居中   oSheet.Cells(i+1,j+1).value = table.rows(i-3).cells(j).innerText; // 注意:页面table.rows(0).cells(0)对应 excel下标(1,1)} 
    } //4: 表格合计oSheet.Rows(hang+4).RowHeight = 25;                      // 设置行高
    oSheet.Rows(hang+4).HorizontalAlignment=2; 
    oSheet.Rows(hang+4).Font.Size = 11;
    oSheet.Rows(hang+4).Range("A1:C1").merge();              // 合并单元格区域 A1:C1
    oSheet.Rows(hang+4).Range("A1:C1").Borders.LineStyle=1;  // 合并区域 加框
    oSheet.Cells(hang+4,1).HorizontalAlignment=3; 
    oSheet.Cells(hang+4,1).Interior.ColorIndex=15;
    oSheet.Cells(hang+4,1).value=tablebuttom.rows(0).cells(0).innerText;for (j=4;j<=7;j++)
    {oSheet.Cells(hang+4,j).Interior.ColorIndex=15;
    oSheet.cells(hang+4,j).Borders.LineStyle=1;    // 单元格加边框
    oSheet.Cells(hang+4,j).value=tablebuttom.rows(0).cells(j-3).innerText;}oXL.Visible = true; 
    oXL.UserControl = true;  //不能省略,不然会出问题 意思是excel交由用户控制
    // oXL.Workbooks.Close();  //关闭BOOK
    // oXL.Quit();             //退出EXCEL
    } </SCRIPT> 
      

  2.   

    不错。下来试试,谢谢。可openrowset不没有办法吗?它既然有hdr为何就没有别的办法吗?