回复 1楼frankch的帖子
你好,
测试代码如下:
- private void 自适应ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- int spreadW = this.fpSpread1.Width;
- int spreadH = this.fpSpread1.Height;
- //垂直滚动条宽度
- int vScrollBar = SystemInformation.VerticalScrollBarWidth;
- //水平滚动条高度
- int hScrollBar = SystemInformation.HorizontalScrollBarHeight;
- //列头高度
- float columnHeaderH = 0;
- for (int i = 0; i < this.fpSpread1.ActiveSheet.ColumnHeader.RowCount; i++)
- {
- columnHeaderH += this.fpSpread1.ActiveSheet.ColumnHeader.Rows[i].Height+1;
- }
- //行头宽度
- float rowHeaderW = 0;
- for (int i = 0; i < this.fpSpread1.ActiveSheet.RowHeader.ColumnCount; i++)
- {
- rowHeaderW += this.fpSpread1.ActiveSheet.RowHeader.Columns[i].Width+1;
- }
- //剩余宽度和高度
- int leftWidth = spreadW - vScrollBar - Convert.ToInt32(rowHeaderW);
- int leftHeight = spreadH - hScrollBar - Convert.ToInt32(columnHeaderH);
- //计算并设置平均列宽
- int averageColWidth = leftWidth / this.fpSpread1.ActiveSheet.ColumnCount;
- for (int i = 0; i < this.fpSpread1.ActiveSheet.ColumnCount; i++)
- {
- this.fpSpread1.ActiveSheet.Columns[i].Width = averageColWidth;
- }
- //计算并设置平均行高
- int averageRowHeight = leftHeight/ this.fpSpread1.ActiveSheet.RowCount;
- for (int i = 0; i < this.fpSpread1.ActiveSheet.RowCount; i++)
- {
- this.fpSpread1.ActiveSheet.Rows[i].Height = averageRowHeight;
- }
- }
复制代码
为了给你提供更优质的服务,请对本次服务进行评分。我们会认真对待你提出的宝贵意见,谢谢 |