建议你将其中的数据倒入到doc文件中,然后让他们想怎么打就这么打

解决方案 »

  1.   

    不知道这段代码对你有没有用?
    说明;
    1。首先你要在你的项目里添加对Microsoft Excel object library的引用;
    2。在当前的Form里加入一个progressBar1;
    3。假设你已经得到了数据(DataSet ds)并且绑定到了你的DataGrid1,而且DataGrid1里面加入了CheckBox(假设为第一列);
    4。那么下面的代码你可以仿照写一下,应该就没问题了。
    private void btExport_Click(object sender, System.EventArgs e)
    {
    if(DataGrid1.VisibleRowCount==0)return;
    this.Cursor =Cursors.WaitCursor;  
    Excel.Application myExcel=new Excel.Application();
    myExcel.Application.Workbooks.Add(true);Excel.Workbook myBook=myExcel.Workbooks[1];
    Excel.Worksheet mySheet=(Excel.Worksheet)myBook.Worksheets[1];progressBar1.Visible =true;
    int j=0,k=0;
    progressBar1.Value=0;
    progressBar1.Maximum =ds.Tables[0].Rows.Count;
    for(j=0;j<ds.Tables[0].Rows.Count;j++)
    {
    if (DataGrid1[j,0])//判断是否选中本条记录
       {
    myExcel.Cells[j,k]=ds.Tables[0].Rows[j][k] ;
    progressBar1.Value +=1;
    progressBar1.Refresh;
    }
    }
    progressBar1.Visible =false;
    this.Cursor =Cursors.Default;MessageBox.Show("数据导出完成!",this.Text);
    myExcel.Visible=true;
      

  2.   

    上面的代码的作用在于将dataGrid1中选中的记录导出到Excel中
      

  3.   

    倒入到excel中也可以阿,
    不过我一般就是自己写.csv文件,这样的话可以想倒入什么就倒入什么。
      

  4.   

    在段代码我用过,可以的:
    Response.Clear(); 
    Response.Buffer= true; 
    Response.Charset="GB2312";    
    Response.AppendHeader("Content-Disposition","attachment;filename=FileName.htm"); 
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
    Response.ContentType =" text/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);
    this.DataGrid1.RenderControl(oHtmlTextWriter); 
    Response.Write(oStringWriter.ToString());
    Response.End();
      

  5.   

    同意楼上,格式的种类比较多Select Case lcase(Right(flName, 4))
        Case ".asf"
         ContentType = "video/x-ms-asf"
        Case ".avi"
         ContentType = "video/avi"
        Case ".doc"
         ContentType = "application/msword"
        Case ".zip"
         ContentType = "application/zip"
        Case ".xls"
         ContentType = "application/vnd.ms-excel"
    或者     ContentType = "application/vnd.ms-xls"     
        Case ".gif"
         ContentType = "image/gif"
        Case ".jpg", "jpeg"
         ContentType = "image/jpeg"
        Case ".wav"
         ContentType = "audio/wav"
        Case ".mp3"
         ContentType = "audio/mpeg3"
        Case ".mpg", "mpeg"
         ContentType = "video/mpeg"
        Case ".rtf"
         ContentType = "application/rtf"
        Case ".htm", "html"
         ContentType = "text/html"
        Case ".txt"
         ContentType = "text/plain"
        Case ".pdf"
         ContentType = "application/pdf"
        Case Else
         ContentType = "application/octet-stream"
       End Select