找回密码
 立即注册

QQ登录

只需一步,快速开始

haitun1227

中级会员

16

主题

90

帖子

540

积分

中级会员

积分
540

活字格认证

haitun1227
中级会员   /  发表于:2013-8-28 11:51  /   查看:17251  /  回复:23
1.c1FlexGrid控件导入excel数据少的时候,会显示如图所示的灰色背景,如何将整个框都充满单元格,像excel那样。
2.导入时如何显示excel中的行号ABC。。和列号123。。。


代码如下
  // choose file
            OpenFileDialog dlg = new OpenFileDialog();
            dlg.DefaultExt = "xls";
            dlg.FileName = "*.xls";
            if (dlg.ShowDialog() != DialogResult.OK)
                return;

            // clear date source
            c1FlexGrid1.DataSource = null;
            string[] sheets = c1FlexGrid1.LoadExcelSheetNames(dlg.FileName);
            Console.WriteLine("Found {0} sheets in this book.", sheets.Length);
            foreach (string sheet in sheets)
            {
                Console.WriteLine("- {0}", sheet);
            }

            // load the first sheet in the book
            FileFlags flags = (checkBox1.Checked) ? FileFlags.IncludeFixedCells : FileFlags.None;
            c1FlexGrid1.LoadGrid(dlg.FileName, FileFormatEnum.Excel, flags);
            dlg.RestoreDirectory = true;

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x

23 个回复

倒序浏览
gw0506
超级版主   /  发表于:2013-8-28 12:09:00
沙发
1. 需要手动补齐空行。
2. 设置行列的Caption。
  1.             this.c1FlexGrid1.Cols[1].Caption = "列标题";
  2.             this.c1FlexGrid1.Rows[1].Caption = "行标题";
复制代码
回复 使用道具 举报
haitun1227
中级会员   /  发表于:2013-8-28 12:39:00
板凳
回复 2楼gw0506的帖子

谢谢你的回复。
但我想实现的是excel中的列显示A,B。。。。。。行显示1,2。。。。。
this.c1FlexGrid1.Cols[1].Caption = "列标题";
这条语句是自己给列设置标题。我想在读入excel时自动把excel的行列显示在flexgrid控件中
回复 使用道具 举报
haitun1227
中级会员   /  发表于:2013-8-28 12:41:00
地板
如图所示

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 使用道具 举报
gw0506
超级版主   /  发表于:2013-8-28 13:51:00
5#
读取时不能读入行头列头信息,需要你自己设置。
回复 使用道具 举报
haitun1227
中级会员   /  发表于:2013-8-28 14:09:00
6#
回复 5楼gw0506的帖子

那我怎么设置列头,从A到z
回复 使用道具 举报
gw0506
超级版主   /  发表于:2013-8-28 14:56:00
7#
刚才设置Caption的代码就可以设置列头。
  1. this.c1FlexGrid1.Cols[1].Caption = "A";
复制代码
回复 使用道具 举报
haitun1227
中级会员   /  发表于:2013-8-28 15:47:00
8#
回复 7楼gw0506的帖子

谢谢你的回复!我已经解决这个问题
回复 使用道具 举报
gw0506
超级版主   /  发表于:2013-8-28 16:06:00
9#
你是怎么做的?愿意分享一下吗?
回复 使用道具 举报
haitun1227
中级会员   /  发表于:2013-8-29 17:43:00
10#
不好意思昨天一直忙着,今天才看到。
// 将字母转换为ASCII码
            string zm = "A";
            System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
            int intAsciiCode = (int)asciiEncoding.GetBytes(zm)[0];

         
            // 增加空白行列
            c1FlexGrid1.Cols.Add(4);
            c1FlexGrid1.Rows.Add(5);

            // 设定每一列的列号
            for (int i = 1; i <= colCount +3; i++ )
            {
              int num =  intAsciiCode + i - 1;
              byte[] btNumber = new byte[] { (byte)num };
              string colname =  asciiEncoding.GetString(btNumber);
              this.c1FlexGrid1.Cols.Caption =colname;
            }
方法不是很好,如果你要有好想法,我们可以继续交流。谢谢!
回复 使用道具 举报
123下一页
您需要登录后才可以回帖 登录 | 立即注册
返回顶部