您好,
实现的思路是将WordWrap设置为false,在将Width设置为GetPreferredColumnWidth。
- private void Form4_Load(object sender, EventArgs e)
- {
- string conStr = "Provider=Microsoft.JET.OLEDB.4.0;data source= " + Application.StartupPath + "\\NWind_CHS.mdb";
- string sqlStr = "SELECT * FROM 产品";
- System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(conStr);
- DataSet ds = new DataSet();
- System.Data.OleDb.OleDbDataAdapter da = new System.Data.OleDb.OleDbDataAdapter(sqlStr, conn);
- fpSpread1.ActiveSheet.DataAutoSizeColumns = true;
- fpSpread1.ActiveSheet.DataMember = "产品";
- da.Fill(ds);
- fpSpread1.ActiveSheet.DataSource = ds;
- MaxNum = ds.Tables[0].Columns.Count;
- FarPoint.Win.Spread.CellType.EnhancedColumnHeaderRenderer ecr = new FarPoint.Win.Spread.CellType.EnhancedColumnHeaderRenderer();
- ecr.WordWrap = false;
- fpSpread1.ActiveSheet.ColumnHeader.DefaultStyle.Renderer = ecr;
- }
复制代码
- private void button1_Click(object sender, EventArgs e)
- {
- float len_txt = 0;
- for (int i = 0; i < MaxNum; i++)
- {
- len_txt = fpSpread1.ActiveSheet.GetPreferredColumnWidth(i);
- fpSpread1.ActiveSheet.Columns[i].Width = len_txt;
- }
- }
复制代码
直接加载
2015-08-27_112126.jpg
(44.12 KB, 下载次数: 262)
|