function print_onclick() { //打开一个新的工作区        ExcelSheet = new ActiveXObject("Excel.Sheet"); ExcelSheet.Application.Visible=true; dsoCJ.recordset.moveFirst(); dsoNAME.recordset.moveFirst();//设置列宽 ExcelSheet.ActiveSheet.Columns("A:A").ColumnWidth = 3.38;//写头       ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Merge(true); ExcelSheet.ActiveSheet.Cells(c_row,1).Value=" 学 生 成 绩 总 表"; ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Font.Name="隶书"; ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Font.Size=17; ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Font.Bold = 1; ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).HorizontalAlignment=3;  ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Merge(true);                                 ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).WrapText=true; ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Font.Bold = 1; ExcelSheet.ActiveSheet.Cells(c_row,1).Value="";ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Merge(true);                                 ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).WrapText=true; ExcelSheet.ActiveSheet.Range("A"+c_row+":J"+c_row).Font.Bold = 1; ExcelSheet.ActiveSheet.Cells(c_row,1).Value="学号:"+dsoNAME.recordset("STUDENTNO").value +"    姓名:"+dsoNAME.recordset("NAME").value+"            学院: "+dsoNAME.recordset("SCHOOLNAME").value;ExcelSheet.ActiveSheet.Range("F"+c_row+":J"+c_row).Merge(true);   ExcelSheet.ActiveSheet.Cells(c_row,6).Value="             ----续---  " xurow=c_row; ExcelSheet.ActiveSheet.Cells(c_row+1,6).Value="类别"; ExcelSheet.ActiveSheet.Cells(c_row+1,6).Font.Size=11; ExcelSheet.ActiveSheet.Cells(c_row+1,6).Font.Bold=1; ExcelSheet.ActiveSheet.Cells(c_row+1,7).Value="     课程名称"; ExcelSheet.ActiveSheet.Cells(c_row+1,7).Font.Size=11; ExcelSheet.ActiveSheet.Cells(c_row+1,7).Font.Bold=1; ExcelSheet.ActiveSheet.Cells(c_row+1,8).Value="学分"; ExcelSheet.ActiveSheet.Cells(c_row+1,8).Font.Size=11; ExcelSheet.ActiveSheet.Cells(c_row+1,8).Font.Bold=1; ExcelSheet.ActiveSheet.Cells(c_row+1,9).Value="成 绩"; ExcelSheet.ActiveSheet.Cells(c_row+1,9).Font.Size=11; ExcelSheet.ActiveSheet.Cells(c_row+1,9).Font.Bold=1; ExcelSheet.ActiveSheet.Cells(c_row+1,10).Value="重 修"; ExcelSheet.ActiveSheet.Cells(c_row+1,10).Font.Size=11; ExcelSheet.ActiveSheet.Cells(c_row+1,10).Font.Bold=1;中间可以参考//画表格ExcelSheet.ActiveSheet.Range(ExcelSheet.ActiveSheet.Cells(firstrow,1),ExcelSheet.ActiveSheet.Cells(stoprow-1,10)).Borders.ColorIndex = 1;}主要部分已经全部包含!

解决方案 »

  1.   

    我是直接从datagrid导出的,应该怎么做?
      

  2.   

    DataGrid1.AllowPaging = False
            Dim oView As New DataView(Gdt)
            ''
            DataGrid1.DataSource = oView
            ataGrid1.DataBind()
            DataGrid1.AllowPaging = True        Response.ContentType = "application/vnd.ms-excel"
            Response.AppendHeader("Content-Disposition", "attachment;filename=" + "bookl.xls")
            '' 从Content-Type header中去除charset设置
            Response.Charset = "utf-8"
            '' 关闭 ViewState
            Me.EnableViewState = False
            Dim tw As New System.IO.StringWriter()
            Dim hw As New System.Web.UI.HtmlTextWriter(tw)
            '' 获取control的HTML
            DataGrid1.RenderControl(hw)
            '' 把HTML写回浏览器
            Response.Write(tw.ToString())
            Response.End()
            ExportGrid(DataGrid1, Gdt)
      

  3.   

    我该用C#写,找不到ExportGrid()这个方法
      

  4.   

    有个owc控件是微软.net自带的操作office控件
      

  5.   

    这个我已经引用了,但还是不能使用ExportGrid()