2021年4月22日 星期四

Delphi Ole excel container, Save Xlsx file

 
uses ComObj, Excel;

var Excel: OleVariant;
Excel := CreateOleObject('EXCEL.Application');
Excel.Application.Workbooks.Add;
Excel.Application.Workbooks[1].SaveAs('c:\test.xlsx', xlWorkbookDefault); // or xlOpenXMLWorkbook (51)
Excel.Application.Quit;

-----------------------------------------

unit Excel;

interface

uses Windows, Activex;
// originally from Excel97.pas
// XlFileFormat constants

type
  XlFileFormat = TOleEnum;
const
  xlAddIn = $00000012;
  xlCSV = $00000006;
  xlCSVMac = $00000016;
  xlCSVMSDOS = $00000018;
  xlCSVWindows = $00000017;
  xlDBF2 = $00000007;
  xlDBF3 = $00000008;
  xlDBF4 = $0000000B;
  xlDIF = $00000009;
  xlExcel2 = $00000010;
  xlExcel2FarEast = $0000001B;
  xlExcel3 = $0000001D;
  xlExcel4 = $00000021;
  xlExcel5 = $00000027;
  xlExcel7 = $00000027;
  xlExcel9795 = $0000002B;
  xlExcel4Workbook = $00000023;
  xlIntlAddIn = $0000001A;
  xlIntlMacro = $00000019;
  xlWorkbookNormal = $FFFFEFD1;
  xlSYLK = $00000002;
  xlTemplate = $00000011;
  xlCurrentPlatformText = $FFFFEFC2;
  xlTextMac = $00000013;
  xlTextMSDOS = $00000015;
  xlTextPrinter = $00000024;
  xlTextWindows = $00000014;
  xlWJ2WD1 = $0000000E;
  xlWK1 = $00000005;
  xlWK1ALL = $0000001F;
  xlWK1FMT = $0000001E;
  xlWK3 = $0000000F;
  xlWK4 = $00000026;
  xlWK3FM3 = $00000020;
  xlWKS = $00000004;
  xlWorks2FarEast = $0000001C;
  xlWQ1 = $00000022;
  xlWJ3 = $00000028;
  xlWJ3FJ3 = $00000029;
  xlExcel12 =50;
  xlExcel8 = 56;
  xlHtml = 44;
  xlOpenXMLAddIn = 55;
  xlOpenXMLTemplate = 54;
  xlOpenXMLTemplateMacroEnabled = 53;
  xlOpenXMLWorkbook = 51;
  xlOpenXMLWorkbookMacroEnabled = 52;
  xlTemplate8 = 17;
  xlUnicodeText = 42;
  xlWebArchive = 45;
  xlWorkbookDefault = 51;
  xlXMLSpreadsheet = 46;

implementation
end.

轉貼至 https://stackoverflow.com/questions/9067053/delphi-ole-excel-container-save-file


XlFileFormat 枚举 (Excel)

指定保存工作表时的文件格式。

XLFILEFORMAT 枚举 (EXCEL)
名称说明扩展名
xlAddIn18Microsoft Excel 97-2003 外接程序*.xla
xlAddIn818Microsoft Excel 97-2003 外接程序*.xla
xlCSV6CSV*.csv
xlCSVMac22Macintosh CSV*.csv
xlCSVMSDOS24MSDOS CSV*.csv
xlCSVUTF862UTF8 CSV*.csv
xlCSVWindows23Windows CSV*.csv
xlCurrentPlatformText-4158当前平台文本*.txt
xlDBF27Dbase 2 格式*.dbf
xlDBF38Dbase 3 格式*.dbf
xlDBF411Dbase 4 格式*.dbf
xlDIF9数据交换格式*.dif
xlExcel1250Excel 二进制工作簿*.xlsb
xlExcel216Excel 版本 2.0 (1987)*.xls
xlExcel2FarEast27Excel 版本 2.0 中文 (1987)*.xls
xlExcel329Excel 版本 3.0 (1990)*.xls
xlExcel433Excel 版本 4.0 (1992)*.xls
xlExcel4Workbook35Excel 版本 4.0 工作簿格式 (1992)*.xlw
xlExcel539Excel 版本 5.0 (1994)*.xls
xlExcel739Excel 95(版本 7.0)*.xls
xlExcel856Excel 97-2003 工作簿*.xls
xlExcel979543Excel 版本 95 和 97*.xls
xlHtml44HTML 格式.htm;.html
xlIntlAddIn26国际外接程序无文件扩展名
xlIntlMacro25国际宏无文件扩展名
xlOpenDocumentSpreadsheet60OpenDocument 电子表格*.ods
xlOpenXMLAddIn55Open XML 外接程序*.xlam
xlOpenXMLStrictWorkbook61 (&H3D)Strict Open XML 文件*.xlsx
xlOpenXMLTemplate54Open XML 模板*.xltx
xlOpenXMLTemplateMacroEnabled53启用 Open XML 模板宏*.xltm
xlOpenXMLWorkbook51Open XML 工作簿*.xlsx
xlOpenXMLWorkbookMacroEnabled52启用 Open XML 工作簿宏*.xlsm
xlSYLK2符号链接格式*.slk
xlTemplate17Excel 模板格式*.xlt
xlTemplate817模板 8*.xlt
xlTextMac19Macintosh 文本*.txt
xlTextMSDOS21MSDOS 文本*.txt
xlTextPrinter36打印机文本*.prn
xlTextWindows20Windows 文本*.txt
xlUnicodeText42Unicode 文本无文件扩展名;*.txt
xlWebArchive45Web 档案.mh;.mhtml
xlWJ2WD114日语 1-2-3*.wj2
xlWJ340日语 1-2-3*.wj3
xlWJ3FJ341日语 1-2-3 格式*.wj3
xlWK15Lotus 1-2-3 格式*.wk1
xlWK1ALL31Lotus 1-2-3 格式*.wk1
xlWK1FMT30Lotus 1-2-3 格式*.wk1
xlWK315Lotus 1-2-3 格式*.wk3
xlWK3FM332Lotus 1-2-3 格式*.wk3
xlWK438Lotus 1-2-3 格式*.wk4
xlWKS4Lotus 1-2-3 格式*.wks
xlWorkbookDefault51默认工作簿*.xlsx
xlWorkbookNormal-4143常规工作簿*.xls
xlWorks2FarEast28Microsoft Works 2.0 两端对齐格式*.wks
xlWQ134Quattro Pro 格式*.wq1
xlXMLSpreadsheet46XML 电子表格*.xml


轉貼至:https://docs.microsoft.com/zh-cn/office/vba/api/excel.xlfileformat

2021年4月20日 星期二

Load a stream containing HTML code into a TWebBrowser

procedure LoadStream(WebBrowser: TWebBrowser; Stream: TStream);
var
  PersistStreamInit: IPersistStreamInit;
  StreamAdapter: IStream;
  MemoryStream: TMemoryStream;
begin
  {Load empty HTML document into Webbrowser to make "Document" a valid HTML document}
  WebBrowser.Navigate('about:blank');
  {wait until finished loading}
  repeat
    Application.ProcessMessages;
    Sleep(0);
  until
    WebBrowser.ReadyState = READYSTATE_COMPLETE;
  {Get IPersistStreamInit - Interface}
  if WebBrowser.Document.QueryInterface(IPersistStreamInit, PersistStreamInit) = S_OK then
  begin
    {Clear document}
    if PersistStreamInit.InitNew = S_OK then
    begin
      {Make local copy of the contents of Stream if you want to use Stream directly,
                        you have to consider, that StreamAdapter will destroy it automatically}
      MemoryStream := TMemoryStream.Create;
      try
        MemoryStream.CopyFrom(Stream, 0);
        MemoryStream.Position := 0;
      except
        MemoryStream.Free;
        raise;
      end;
      {Use Stream-Adapter to get IStream Interface to our stream}
      StreamAdapter := TStreamAdapter.Create(MemoryStream, soOwned);
      {Load data from Stream into WebBrowser}
      PersistStreamInit.Load(StreamAdapter);
    end;
  end;
end;

參考至 http://www.devsuperpage.com/Articles/views/Delphi/Art_1-2146.asp