XLSX-Workbook-Class icon indicating copy to clipboard operation
XLSX-Workbook-Class copied to clipboard

SaveGridToWorkbook support alignment

Open DougHennig opened this issue 6 months ago • 0 comments

SaveGridToWorkbook doesn't support the Alignment setting of a column. I tried to implement it using this code but for some reason it didn't work (starting at line 212):

IF toGrid.HeaderHeight > 0                                                    && Change recommendation by Doug Hennig (if no headers, start in first row)
	lnRow = tnBegRow
	FOR lnCol=1 TO lnColCount
		loColumn = toGrid.Columns(laColOrder[lnCol, 2])
*** DH 2023-12-04: don't assume the header object is named Header1
*				this.SetCellValue(lnWB, lnSh, lnRow, lnCol+tnBegCol-1, loColumn.Header1.Caption)
		loHeader = loColumn.Controls[1]
		this.SetCellValue(lnWB, lnSh, lnRow, lnCol+tnBegCol-1, loHeader.Caption)
*** DH 2023-12-04: end of change
		this.SetCellStyle(lnWB, lnSh, lnRow, lnCol+tnBegCol-1, loGrid.Columns(laColOrder[lnCol, 2]).HeaderStyleId)
		this.SetColumnWidth(lnWB, lnSh, lnCol+tnBegCol-1, this.ConvertPixelsToExcelUnits(loColumn.Width))
*** DH 2024-05-26: handle cell alignment. Note: doesn't work
		if inlist(loColumn.Alignment, 1, 2)
			This.SetCellAlignment(lnWB, lnSh, lnRow, lnCol + tnBegCol - 1, iif(loColumn.Alignment = 1, CELL_HORIZ_ALIGN_RIGHT, CELL_HORIZ_ALIGN_CENTER))
		endif inlist(loColumn.Alignment, 1, 2)
*** DH 2024-05-26: end of change
	ENDFOR

Also, around line 312:

this.SetCellStyle(lnWB, lnSh, lnRow, lnCol+tnBegCol-1, lnCellXfsId)
*** DH 2024-05-26: handle cell alignment. Note: doesn't work
if inlist(loColumn.Alignment, 1, 2)
	This.SetCellAlignment(lnWB, lnSh, lnRow, lnCol + tnBegCol - 1, iif(loColumn.Alignment = 1, CELL_HORIZ_ALIGN_RIGHT, CELL_HORIZ_ALIGN_CENTER))
endif inlist(loColumn.Alignment, 1, 2)
*** DH 2024-05-26: end of change

DougHennig avatar Aug 15 '24 21:08 DougHennig