private void AutoColumnsWidth(SheetView Sheet, int startcolumn, int endcolumn, AutoSizeFlags flags, int Minimum) { int start = startcolumn < 0 ? 0 : startcolumn; int end = endcolumn > Sheet.ColumnHeader.Columns.Count ? Sheet.ColumnHeader.Columns.Count - 1 : endcolumn; int temp; if (start > end) { temp = start; end = temp; start = end; } Graphics g = FpSpread.CreateGraphics(); if (flags == AutoSizeFlags.Header) { for (int i = start; i <= end; i++) { SizeF sizef = g.MeasureString(Sheet.ColumnHeader.Columns[i].Label, FpSpread.Font); float WideWidth = (sizef.Width + 50 < Minimum ? Minimum : sizef.Width + 50); Sheet.ColumnHeader.Columns[i].Width = WideWidth; } } else { for (int i = start; i <= end; i++) { float Width = 0; for (int j = 0; j < Sheet.Rows.Count; j++) { SizeF TextSize = g.MeasureString(Sheet.Cells[j, i].Text, FpSpread.Font); if (TextSize.Width > Width) { Width = TextSize.Width; } } float WideWidth = (Width < Minimum ? Minimum : Width); Sheet.ColumnHeader.Columns[i].Width = WideWidth; } } g.Dispose(); }
private void AutoColumnsWidth(SheetView Sheet, AutoSizeFlags flags, int Minimum) { AutoColumnsWidth(Sheet, 0, Sheet.ColumnHeader.Columns.Count - 1, flags, Minimum); }