This commit is contained in:
2026-06-29 09:56:10 +02:00
parent 0f95522bb4
commit 2d52113aaa
6 changed files with 193 additions and 43 deletions

View File

@@ -1248,11 +1248,60 @@ Public Class cProgramFunctions
End If
'If fitCellsToContent Then
' wb.Worksheets(0).Columns().AdjustToContents()
' ' wb.Worksheets(0).Rows().AdjustToContents() ' weglassen
'End If
If fitCellsToContent Then
wb.Worksheets(0).Columns().AdjustToContents()
wb.Worksheets(0).Rows().AdjustToContents()
Dim ws = wb.Worksheets(0)
For i As Integer = 0 To dt.Columns.Count - 1
Dim maxLen As Integer = dt.Columns(i).ColumnName.Length
For Each dr As DataRow In dt.Rows
If Not IsDBNull(dr(i)) Then
maxLen = Math.max(maxLen, dr(i).ToString.Length)
End If
Next
ws.Column(i + 1).Width = Math.min(Math.max(maxLen * 1.1, 8), 60)
Next
End If
'If fitCellsToContent Then
' Dim ws = wb.Worksheets(0)
' For Each col In ws.ColumnsUsed()
' 'Header berücksichtigen
' Dim width As Double = col.FirstCell().GetString().Length + 2
' 'zusätzlich einige Stichproben aus den Daten
' Dim lastRow As Integer = Math.min(ws.LastRowUsed().RowNumber(), 500)
' For r As Integer = 2 To lastRow Step 25
' Dim txt = col.Cell(r).GetFormattedString()
' If txt.Length + 2 > width Then
' width = txt.Length + 2
' End If
' Next
' 'Mindest- und Maximalbreite
' width = Math.max(width, 8)
' width = Math.min(width, 60)
' col.Width = width
' Next
'End If
If Landscape Then
wb.Worksheets(0).PageSetup.PageOrientation = XLPageOrientation.Landscape
Else