找回密码
 立即注册

QQ登录

只需一步,快速开始

wanghaibo
论坛元老   /  发表于:2014-10-23 18:29  /   查看:5167  /  回复:3
我知道启始行号、列号,如何给其中的单元格,一次性赋属性值,就是背景颜色,边框什么的,我现在用的是循环,效率比较慢
   for (int sheet = 0; sheet < this.fspMain.Sheets.Count; sheet++)//表单
                {
                    _reportSize = lstReportSize.FindLast(obj => obj.RSheet == sheet);

                    //if (dateTimeSpan > _reportSize.RSheetRecordsRows)
                    //{
                    //    MessageBox.Show("时间跨度不能大于当前页允许的最大记录数" + _reportSize.RSheetRecordsRows.ToString());
                    //    return;
                    //}

                    this.fspMain.Sheets[sheet].RowCount = _reportSize.RRowCount + dateTimeSpan + 1;

                    if (dateTimeSpan > 0)
                    {
                        //this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount, 0, this.fspMain.Sheets[sheet].Rows.Count - 1, 0].BackColor = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, 0].BackColor;
                        //this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount, 0, this.fspMain.Sheets[sheet].Rows.Count - 1, 0].Border = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, 0].Border;
                        //this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount, 0, this.fspMain.Sheets[sheet].Rows.Count - 1, 0].Font = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, 0].Font;
                        this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount, 0, this.fspMain.Sheets[sheet].Rows.Count - 1, 0].CellType = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, 0].CellType;
                        //this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount, 0, this.fspMain.Sheets[sheet].Rows.Count - 1, 0].HorizontalAlignment = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, 0].HorizontalAlignment;
                        //this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount, 0, this.fspMain.Sheets[sheet].Rows.Count - 1, 0].VerticalAlignment = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, 0].VerticalAlignment;

                        //curProgressBar.Visible = true;
                        //curProgressBar.Value = 0;
                        //curProgressBar.Maximum = this.fspMain.Sheets[sheet].ColumnCount + 1;

                        for (int i = 1; i < this.fspMain.Sheets[sheet].ColumnCount; i++)
                        {
                            //curProgressBar.Value = curProgressBar.Value + 1;

                            //this.fspMain.Sheets[sheet].Columns.BackColor = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, i].BackColor;
                            //this.fspMain.Sheets[sheet].Columns.Border = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, i].Border;
                            //this.fspMain.Sheets[sheet].Columns.Font = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, i].Font;
                            //this.fspMain.Sheets[sheet].Columns.CellType = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, i].CellType;
                            //this.fspMain.Sheets[sheet].Columns.HorizontalAlignment = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, i].HorizontalAlignment;
                            //this.fspMain.Sheets[sheet].Columns.VerticalAlignment = this.fspMain.Sheets[sheet].Cells[_reportSize.RRowCount - 1, i].VerticalAlignment;
                        }

                     

                        this.fspMain.Sheets[sheet].Rows[_reportSize.RRowCount, this.fspMain.Sheets[sheet].Rows.Count - 1].Locked = true;

                        //curProgressBar.Visible = false;
                    }
                }

3 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2014-10-24 14:58:00
沙发
回复 1楼wanghaibo的帖子

您好,

给cellrange设置,目前只能遍历单元格设置。无法直接给区域单元格设置格式。
不过我看您的代码是通过获取其他单元格属性来设置的样式,这样反复取cell对象的样式属性也会消耗性能。建议通过 NamedStyle 类来设置。至少能减少一半的性能损耗。

为了给你提供更优质的服务,请对本次服务进行评分。我们会认真对待你提出的宝贵意见

谢谢

评分

参与人数 1满意度 +5 收起 理由
wanghaibo + 5 1

查看全部评分

回复 使用道具 举报
wanghaibo
论坛元老   /  发表于:2014-10-29 09:58:00
板凳
回复 2楼iceman的帖子

已经解决
回复 使用道具 举报
iceman
社区贡献组   /  发表于:2014-10-29 13:38:00
地板
回复 3楼wanghaibo的帖子

好的,感谢您反馈问题结果。
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部