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;
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~