RT

解决方案 »

  1.   

    //==========================================
    css可以控制一些
    //==========================================
    http://blog.csdn.net/net_lover/archive/2004/07/06/35228.aspx
    //==================================================
    将DATAGRID放到DIV层中
    通过打印DIV层来打印DATAGRID的例子
    //========================================================
    <input id="BtnPrint" onclick="printpage()" type="image" alt="印刷" src="IMG\btnPrintOriko.gif"><div id="printdiv"><asp:datagrid id="DataGrid1" style="Z-INDEX: 102; LEFT: 6px; POSITION: absolute; TOP: 94px" runat="server" Width="2700px">
    <SelectedItemStyle BackColor="#FF0066"></SelectedItemStyle>
    <AlternatingItemStyle HorizontalAlign="Center" VerticalAlign="Middle" BackColor="#33CCFF"></AlternatingItemStyle>
    <ItemStyle HorizontalAlign="Center" Width="100%" VerticalAlign="Middle" BackColor="#66CC99"></ItemStyle>
    <HeaderStyle HorizontalAlign="Center" Width="100%" VerticalAlign="Middle" BackColor="#FF9966"></HeaderStyle>
    </asp:datagrid></div><script language="javascript">

    function printpage()
    {
    var aaa = document.all.printdiv.innerHTML;
    var printOpen
    printOpen=window.open('printForm.aspx','open1','width=600,height=390,top=100,left=100');
    printOpen.document.body.innerHTML = aaa;
    printOpen.window.print(document.Print);
    printOpen.close(); 
    }
    </script>都是在HTML的页上的代码通过测试好用
    :)
      

  2.   

    webform打印,不是winform打印啊,刚才忘说了,楼上的我看看
      

  3.   

    你可以dataset 导入 excel参考
    http://community.csdn.net/Expert/topic/3077/3077526.xml?temp=.8746912
    http://www.dev-club.com/club/bbs/showEssence.asp?id=26350http://dev.csdn.net/Develop/article/18/18623.shtm
    http://community.csdn.net/Expert/topic/3112/3112296.xml?temp=.926861
    http://dotnet.aspx.cc/ShowDetail.aspx?id=BF0A54F9-C7C7-4200-BD9A-802AC1F5DE50
    http://expert.csdn.net/Expert/TopicView1.asp?id=2928057www.foxhis.com/powermjtest/
    原文代码:
    private void Button1_Click(object sender, System.EventArgs e)
    {
      //写入Excel的方法:
      //定义需要参数。
      string SourceFile="Data.XLS";                                //源文件名称。
      string TemplatePath=Server.MapPath("ExcelTemplate");    //存放源文件的文件夹路径。
      string DownloadPath=Server.MapPath("ExcelDownload");    //副本的文件夹路径。
      //副本的文件名。
      string TempFileName = DateTime.Now.ToString("yyyyMMdd") + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second + ".XLS";  
      object missing = System.Reflection.Missing.Value;
      Excel.Application myExcel=new Excel.Application();
      //打开新文件
      myExcel.Application.Workbooks.Open(TemplatePath+"\\"+SourceFile,missing,missing,missing,missing,
    missing,missing,missing,missing,missing,missing, missing,missing); 
      Excel.Workbook myBook=myExcel.Workbooks[1];
      Excel.Worksheet curSheet = (Excel.Worksheet)myBook.Sheets[2];

      string DownloadFilePath=DownloadPath+"\\"+TempFileName;

      int i=0;
      while (i<=10)
      {
        myExcel.Cells[4+i,2]=i.ToString();
        myExcel.Cells[4+i,3]=i.ToString();
        myExcel.Cells[4+i,4]=i.ToString();
        myExcel.Cells[4+i,5]=i.ToString();
        myExcel.Cells[4+i,6]=i.ToString();
        i++;
      }   

      myBook.Saved=true;
      //myBook.SaveAs(DownloadFilePath,missing,"","",false,false,Excel.XlSaveAsAccessMode.xlNoChange,1,false,missing,missing);

      myBook.PrintPreview(0);
      //myBook.PrintOut(missing,missing,missing,missing,missing,missing,missing,missing);
      myBook.Close(false, null,null);
      myExcel.Quit();
      System.Runtime.InteropServices.Marshal.ReleaseComObject(myBook);
      System.Runtime.InteropServices.Marshal.ReleaseComObject(myExcel);
      myBook = null;
      myExcel = null;
      GC.Collect();
      //Response.Redirect("ExcelDownload//"+TempFileName); //下载文件
    }
      

  4.   

    http://dotnet.aspx.cc/ShowDetail.aspx?id=8A4CBF47-B888-4832-3389-ED3A3A3C8AAB
      

  5.   

    带星的高手们,导入EXCEL早就有了,有导入到WORD和PDF的吗?我加200分
      

  6.   

    我也在找,这是刚刚在CSDN记录中搜索,可以导入Excel和Word,不知道如何导入Pdf。
    在某个button事件中添加:   Response.Clear(); 
       Response.Buffer= true; 
       if (Session["Language"]!=null && Session["Language"].ToString()!="EN")
       {
          Response.Charset="GB2312";
       }
       Response.AppendHeader("Content-Disposition","attachment;filename=FileName.xls"); //根据后面的输出格式设置文件后缀
       if (Session["Language"]!=null && Session["Language"].ToString()!="EN")
       {
          Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
       }//设置输出流为简体中文
       Response.ContentType = "application/ms-excel";//设置设置输出文件类型
       //可以是  application/ms-word || application/ms-txt || application/ms-html || 或其他浏览器可直接支持文档    this.EnableViewState = false; 
       System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN",true);
       System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad); 
       System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
       DataGrid1.RenderControl(oHtmlTextWriter); //DataGrid1为DataGrid控件,也可以是动态生成的HtmlTable  <---唯一需要修改的地方
       Response.Write(oStringWriter.ToString());
       Response.End();
      

  7.   

    不好意思,有分了再给kes2000(云之雾)  goody9807()