FastReport VCL 2024.1.1在导出xls格式时,部分单元格内容没显示出来,以下方法是网友“海”让我分享给大家的,感谢“海”的分享!
1、frxExportMatrix.pas
TfrxIEMStyle 增加StretchMode:TfrxStretchMode;
2、frxExportMatrix.pas
function TfrxIEMatrix.AddStyle(Obj: TfrxView): integer;
3、frxExportMatrix.pas
function TfrxIEMatrix.AddStyleInternal(Style: TfrxIEMStyle): integer;
4、frxExportXML.pas
procedure TfrxXMLExport.ExportPage(Stream: TStream);
增加:
heightstr:='<Row ss:Height="' + frFloat2Str(drow, 2) + '">';//20241125 yanghai //20241125 yanghai 判断是否smMaxHeight i := FMatrix.GetCell(0, y); if (i <> -1) then begin if (FMatrix.GetStyleById(FMatrix.GetObjectById(i).StyleIndex).StretchMode=smMaxHeight) then begin heightstr:='<Row ss:AutoFitHeight="1" ss:Height="' + frFloat2Str(drow, 2) + '">'; end; end; //20241125 WriteExpLn(heightstr); //注释
5、导出之后,因为有些是不需要自适应的,设了自适应之后,就变小了,用fpspreadsheet还原。
用fpspreadsheet把自适应变小的设置一下高度,memo我是设置0.88英寸对应24磅
procedure ChangeExcelFileSheetName(strFullName:string;sheetName:string); var MyWorkbook: TsWorkbook; MyWorksheet: TsWorksheet; MyWorkGrid: TsWorkSheetGrid; iSheetCount:integer; iRow,iRowCount,iCol:integer; dHeight:double; HType:TsRowHeightType; begin if not FileExists(strFullName) then exit; MyWorkGrid:=TsWorkSheetGrid.Create(nil); MyWorkbook:=TsWorkbook.Create; try MyWorkbook.ReadFromFile(strFullName,sfExcelXML); if MyWorkbook.GetWorksheetCount>0 then begin MyWorksheet := MyWorkbook.GetWorksheetByIndex(0); MyWorkGrid.LoadFromWorkbook(MyWorkbook); MyWorkGrid.SelectSheetByIndex(0); iRowCount:=MyWorkGrid.RowCount; for iRow:=0 to iRowCount-1 do begin //20240718 设置固定高度 dHeight:=MyWorksheet.GetRowHeight(iRow,suPoints); if (ESimpleRoundto(dHeight,-2)<=24.17) and (MyWorksheet.GetRowHeightType(iRow)=rhtAuto) then MyWorksheet.WriteRowHeight(iRow,24,suPoints); end; MyWorksheet.Name := sheetName; end; finally MyWorkbook.WriteToFile(strFullName,sfExcelXML,True); MyWorkbook.free; end; end;