C# winfrom中要把窗体改成XP窗体的样式!!
C# winfrom中导出DataGrid表生成csv,xls文件!以下这个不要!
// public virtual void ExcelMethod()
// {
// DataTable DT = (DataTable)this.dataGrid1.DataSource;
// int intRows = DT.Rows.Count;
// if(intRows == 0)
// {
// return;
// }
//
// this.Cursor = Cursors.WaitCursor ;
//
// try
// {
// int intCols = DT.Columns.Count;
// Excel.ApplicationClass xlsApp = new Excel.ApplicationClass ();
// xlsApp.Workbooks.Add("");
// DataGridTableStyle dts1 = this.dataGrid1.TableStyles[0];
//
// for(int j=0; j<intCols; j++)
// {
// xlsApp.Cells[1,j+1] = dts1.GridColumnStyles[j].HeaderText.ToString ();
// }
//
// for(int i=0; i<intRows; i++)
// {
// for(int j=0; j<intCols; j++)
// {
// xlsApp.Cells[i+2,j+1] = DT.Rows[i][j].ToString ();
// }
// }
// xlsApp.Visible = true;
// }
// finally
// {
// this.Cursor = Cursors.Default ;
// }
// }

解决方案 »

  1.   

    1、加manifest样式文件
    2、你嵌入个Excel表格再把datagrid表里的内容生成Excel文件,再导出不就生成了么
      

  2.   

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?><assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"><assemblyIdentityversion="1.0.0.0"processorArchitecture="X86"name="CompanyName.ProductName.YourApp"type="win32"/><description>Your application description here.</description><dependency><dependentAssembly><assemblyIdentitytype="win32"name="Microsoft.Windows.Common-Controls"version="6.0.0.0"processorArchitecture="X86"publicKeyToken="6595b64144ccf1df"language="*"/></dependentAssembly></dependency></assembly>以上保存為文件,文件名為:你的程序名.EXE.manifest把該文件放在你的程序所在的目錄,運行你的程序看看,是不是ok了
      

  3.   

    有2个问题哦!给2个例子吧!发到我油箱吧!!([email protected])这种文字说明就免了
      

  4.   

    是窗体应用程序winfrom 不是ASP.net
      

  5.   

    ghtyan() 这是界面问题吗
      

  6.   

    是Winform的界面樣式,不過前提是你軟件運行的操作系統必須是XP才會有xp效果
      

  7.   

    我現在用的是win2000,無法測試
    我發那個文件給你了,你試一下
      

  8.   

    ^_^那就不清楚了,原來我的是Delphi WinFrom程序是可以的
    那個文件是調用系統桌面主題樣式的,桌面主題改變,程序的樣式也改變
    難道C# Winform不支持?關注......
      

  9.   

    你的意思是不是把datagrid数据导出到excel中呀,如果是这样我到是有,按流写的。asp.net用过winfrom没试过,不过我觉得应该可以。如果是的话我就放上
      

  10.   

    asp.net我也写过啊!这我就不会了
    private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection cn=new SqlConnection("server=127.0.0.1;uid=sa;pwd=sa;database=pubs");
    SqlDataAdapter da=new SqlDataAdapter("select * from jobs",cn);
    DataSet ds=new DataSet();
    da.Fill(ds,"jobs");
    this.DataGrid1.DataSource=ds.Tables["jobs"].DefaultView;
    this.DataGrid1.DataBind();
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion private void Button1_Click(object sender, System.EventArgs e)
    {
    Response.Clear(); 
    Response.Buffer= true; 
    Response.Charset="GB2312"; 
    Response.AppendHeader("Content-Disposition","attachment;filename=Excel.xls");  
    Response.ContentEncoding=System.Text.Encoding.GetEncoding("GB2312");
    Response.ContentType = "application/ms-excel"; 
    this.EnableViewState = false;    
    System.IO.StringWriter oStringWriter = new System.IO.StringWriter(); 
    System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);   
    DataGrid1.RenderControl(oHtmlTextWriter);    
    Response.Write(oStringWriter.ToString());    
    Response.End(); 
    }
    }
    就OK了