翻譯|使用教程|編輯:李顯亮|2020-08-31 10:50:54.053|閱讀 547 次
概述:HTML文檔是用超文本標記語言(HTML)編寫的。它用于創建相對簡單但設計精美的文檔。在本文中,將介紹如何從Delphi / C ++ Builder / Lazarus創建HTML / HTML5分層文件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
報表生成器FastReport VCL是用于在軟件中集成商務智能的現代解決方案。它提供了可視化模板設計器,可以訪問最受歡迎的數據源,報告引擎,預覽,將過濾器導出為30多種格式,并可以部署到云,Web,電子郵件和打印中。
近日,FastReport VCL更新至v6.7,在新版本中,添加了對最新版本IDE的支持,簡化了用于付款標準的條形碼的創建,新增從預覽窗口直接編輯RichView的功能,同時修復了多個Bug問題。歡迎下載體驗。(點擊下方按鈕下載)
"如何從Delphi中以HTML文件格式保存?"、"如何從Delphi中創建HTML 5文件?"、"如何從Lazarus中創建HTML 5文件?" - 這些問題經常在開發人員中出現。
HTML文件是用超文本標記語言(HTML)編寫的。它的作用是創建相對簡單但設計精美的文檔。從一開始就談論HTML是沒有意義的。但值得糾結的是一些功能--HTML可以是不同的--有表格和分層布局,HTML 4和HTML 5標準。
由于HTML5,網頁已經學會了在用戶的瀏覽器中本地存儲數據,這允許你拒絕HTTP cookie。內容的傳遞更快、更安全。HTML5還簡化了跨瀏覽器的過程,增加了對矢量圖形的支持,無需Silverlight或Flash等第三方程序。
①如果你只需要顯示一個頁面一次,而且格式不是很重要,那么最好的選擇是使用標簽--前提是至少在你的腦海中已經建立了整個生成的HTML文件的模型。,
- 太簡單了! 甚至可以使用 writeln(...)! 這種方法的優點是,你可以立即將文件上傳到FTP,它將出現在網站上,任何瀏覽器都能打開它。但也有缺點--這個文件不是用來打印的(!),而且每個瀏覽器的顯示方式都不一樣,甚至同一個瀏覽器的屏幕分辨率也不一樣。
②專門的庫。delphihtmlcomponents有一個可視化編輯器,并宣稱完全支持HTML 4.1和CSS 3.但目前來看在HiDPI上并不好看。
③使用FastReport VCL將Delphi中的內容立即保存為HTML。我們創建任何種類和大小的文檔,多頁,多尺寸,我們可以立即看到并評估文檔,然后再以HTML格式保存。還有大量的附加對象--條形碼、地圖、圖片、圖形基元。現在你可以把它發送到HTML/HTML5 Layered!
我們到底應該用Delphi創建哪種HTML?表格式還是分層式?HTML還是HTML5?讓我們仔細看看它們的設置。
此時,我們應該已經組裝好了一個帶有導出組件的項目。啟動、查看并從預覽中保存它。現在是時候從預覽中調用導出并選擇所需的格式了。
導出參數足夠豐富。我們可以保存整個文檔,而不是只保存一個HTML頁面。它將包括樣式、同一文件夾中的附加文件、導航器等很多很多。
這里的特殊之處在于,導出本身可以由多個文件組成,它支持圖片,并將其保存為不同的文件,但外觀和文件大小非常依賴于報表模板。
下面是每種格式的設置,可以進行比較。
FastReport工具可以幫助我們選擇要導出文檔的哪些頁面、特定頁面或范圍。導出設置包括:
我們還可以指定文件的發送位置--保存在本地存儲或上傳到云端或FTP,或者以電子郵件的形式發送。
最后,導出后打開--導出后生成的文件將立即被默認的HTML瀏覽器打開。設置完畢后,我們終于可以按 "確定 "按鈕了。準備好了!
好了,這里我們已經介紹了如何從Delphi中保存一個HTML / HTML5分層文件。
Export to HTML
procedure TForm1.Button1Click(Sender: TObject); begin {Generate a report. The report must be generated before exporting} frxReport1.PrepareReport(); {Set the range of pages to export. By default, all pages of the generated report are exported} frxHTMLExport1.PageNumbers := '2-3'; {Set whether to export styles} frxHTMLExport1.ExportStyles := True; { Set whether to export images to the same directory with the resulting html file, or place the images in a separate directory} frxHTMLExport1.PicsInSameFolder := False; {Set whether to add navigation buttons to the resulting html file} frxHTMLExport1.Navigator := False; {Set whether to export with a fixed column width or whether the report will be displayed according to the browser window width} frxHTMLExport1.FixedWidth := True; {Set whether to export each page to a separate html file} frxHTMLExport1.Multipage := False; {Set whether to export the background of the generated report} frxHTMLExport1.Background := False; {Set whether to export pictures} frxHTMLExport1.ExportPictures := True; {Set in which format to export pictures} //uses frxImageConverter; // TfrxPictureType = (gpPNG, gpBMP, gpJPG {$IFNDEF FPC}, gpGIF, gpEMF, gpWMF{$ENDIF}) frxHTMLExport1.PictureType := gpPNG; {Set whether to open the resulting file after export} frxHTMLExport1.OpenAfterExport := False; {Set whether to display export progress (show which page is currently being exported)} frxHTMLExport1.ShowProgress := False; {Set whether to display the export filter settings dialog box} frxHTMLExport1.ShowDialog := False; {Set the name of the resulting file.} {Please note that if you do not set the file name and disable the export filter dialog box,} {the file name selection dialog will still be displayed} frxHTMLExport1.FileName := 'C:\Output\test.html'; {Export the report} frxReport1.Export(frxHTMLExport1); end;
Export to HTML (Layered)
procedure TForm1.Button2Click(Sender: TObject); begin {Generate a report. The report must be generated before exporting} frxReport1.PrepareReport(); {Set the range of pages to export. By default, all pages of the generated report are exported} frxHTML5DivExport1.PageNumbers := '2-3'; {Set whether to export styles} frxHTML5DivExport1.EmbeddedCSS := True; {Set whether to convert all images in accordance with PictureFormat:} {if the image in the report is in BMP format and the PictureFormat is PNG, then BMP will be saved in PNG format} frxHTML5DivExport1.UnifiedPictures := True; {Set whether to format the HTML source text (increases the size of the resulting file)} frxHTML5DivExport1.Formatted := False; {Set whether to export pictures} frxHTML5DivExport1.EmbeddedPictures := True; {Set whether to export each page to a separate HTML5Div file} frxHTML5DivExport1.Multipage := False; {Set whether to add navigation buttons to the resulting HTML5Div file} frxHTML5DivExport1.Navigation := False; {Set in which format to export pictures} //uses frxExportHelpers; // TfrxPictureFormat = (pfPNG, {$IFNDEF FPC}pfEMF,{$ENDIF} pfBMP, pfJPG);) frxHTML5DivExport1.PictureFormat := pfPNG; {Set whether to open the resulting file after export} frxHTML5DivExport1.OpenAfterExport := False; {Set whether to display export progress (show which page is currently being exported)} frxHTML5DivExport1.ShowProgress := False; {Set whether to display the export filter settings dialog box} frxHTML5DivExport1.ShowDialog := False; {Set the name of the resulting file.} {Please note that if you do not set the file name and disable the export filter dialog box,} {the file name selection dialog will still be displayed} frxHTML5DivExport1.FileName := 'C:\Output\test.html'; {Export the report} frxReport1.Export(frxHTML5DivExport1); end;
這些是已保存的HTML和HTML5文件的屬性。這些文件的大小是顯而易見的。導出為HTML格式的文檔基本上比HTML5小2倍。現在讓我們比較瀏覽器中保存的文檔的外觀:
普通的HTML文件不會顯示諸如框架及其陰影框陰影之類的元素。
如果使文檔更復雜,則這種區別將更加明顯。讓我提醒您,此導出不只支持不同的標準-我們正在處理創建HTML的不同方法。在第一種情況下,使用的是固定表-當然,這個示例更面向表。例如,如果我們需要帶有插圖的報告,則結果將大不相同。
讓我們看一下在FastReport報表中使用地圖的示例。區別很明顯!
讓我們看看HTML頁面的另一面,并出于說明目的查看其代碼。
還想要更多嗎?您可以點擊閱讀【FastReport 報表2020最新資源盤點】,查找需要的教程資源。如果您有任何疑問或需求,請隨時加入FastReport技術交流群(783996712),我們很高興為您提供查詢和咨詢。
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn