找回密码
 立即注册

QQ登录

只需一步,快速开始

moriya

论坛元老

78

主题

189

帖子

4万

积分

论坛元老

积分
42318

活字格认证

moriya
论坛元老   /  发表于:2013-5-10 11:54  /   查看:4395  /  回复:3
你好 因為某些原因對時間欄位進行處理 代碼如下
  for (int i = 0; i < dv.Table.Rows.Count; i++)
            {
                for (int j = 0; j < dv.Table.Columns.Count; j++)
                {

                    //if (dv.Table.Columns[j].ColumnName.ToString() != &quotriceEffectiveDate" || dv.Table.Columns[j].ColumnName.ToString() != "EFFECTIVEDATE")
                    //{
                        fpsDailyMain_Sheet1.Cells[i, j].Value = dv.Table.Rows[j].ToString();
                    //}
                }
            }

以上代碼是所有欄位都為字符型
隨后我又對時間類型的欄位進行處理

        //短日期類型:生效日&失效日
        public static FarPoint.Win.Spread.CellType.DateTimeCellType shortdatetype
        {
            get
            {
                FarPoint.Win.Spread.CellType.DateTimeCellType _shortdate = new FarPoint.Win.Spread.CellType.DateTimeCellType();
                _shortdate.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.ShortDate;
                return _shortdate;
            }
        }

fpsDailyMain_Sheet1.Columns[PublicMethod.GetIndexByLable(fpsDailyMain_Sheet1, &quotriceEffectiveDate")].CellType = FarpointMethod.shortdatetype;

3 个回复

倒序浏览
山水
初级会员   /  发表于:2013-5-10 14:00:00
沙发
1楼好,
从您的帖子标题看您似乎遇到了一些時間欄位排序問題, 但从您的帖子内容中,我们无法看到您遇到了社么问题...
您能否给予更多的信息?
回复 使用道具 举报
moriya
论坛元老   /  发表于:2013-5-10 15:00:00
板凳
哦 ,就是使用fpsDailyMain_Sheet1.Cells[i, j].Value = dv.Table.Rows[j].ToString();
這句對時間欄位處理過后,farpoint就認為他是string類型,后邊再對其使用
fpsDailyMain_Sheet1.Columns[PublicMethod.GetIndexByLable(fpsDailyMain_Sheet1, &quotriceEffectiveDate")].CellType = FarpointMethod.shortdatetype 來設置屬性; 設置CellType 為時間類型不起作用 ,因此才導致該欄位排序有問題
回复 使用道具 举报
山水
初级会员   /  发表于:2013-5-10 16:44:00
地板
您好,
      如果您用的Table中的日期是数据库标准的DateTime类型,不应当有此问题。请试如下例子代码:
        private void button1_Click(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add(new DataColumn("date", typeof(DateTime)));
            table.Rows.Add(DateTime.Now);
            table.Rows.Add(new DateTime(2010,5,18));
            for (int i = 0; i < table.Rows.Count; i++)
            {
                for (int j = 0; j < table.Columns.Count; j++)
                {
                    this.fpSpread1.ActiveSheet.Cells[i, j].Value = table.Rows[j].ToString();
                }
            }

            FarPoint.Win.Spread.CellType.DateTimeCellType _shortdate = new FarPoint.Win.Spread.CellType.DateTimeCellType();
            _shortdate.DateTimeFormat = FarPoint.Win.Spread.CellType.DateTimeFormat.ShortDate;

            this.fpSpread1.ActiveSheet.Columns[0].CellType = _shortdate;
            this.fpSpread1.ActiveSheet.Columns[0].AllowAutoSort = true;
        }

      当然最简洁的方法是: 把该DataTable设为Spread的数据源,Spread会把表中DateTime类型的数据自动转化成DateTimeCellType,并且DateTimeCellType缺省就是ShortDate格式:
    fpsDailyMain_Sheet1.DataSource = dv.Table;

      如果您的问题还没有解决,建议您做一个简单的例子说明您需要解决的问题的细节,附加在该帖子上,这样我们能精确地定位您的问题,帮您快速地解决问题。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部