已经实现简单公式的定义,但是如果参数为区域类型时的处理仍没解决, 代码公布如下,希望对大家有帮助unit F1AddInUnit;interface uses windows,dialogs,Sysutils,TTF160_TLB;const F1_E_NULL = $80040001; // #NULL! F1_E_DIVZERO = $80040002; // #DIV/0! F1_E_VALUE = $80040003; // #VALUE! F1_E_REF = $80040004; // #REF! F1_E_NAME = $80040005; // #NAME? F1_E_NUM = $80040006; // #NUM! F1_E_NA = $80040007; // #N/A F1ADDIN_ARRAY = 0; // Not implemented in Formula One 6.1 F1ADDIN_AREA = 1; F1ADDIN_AREA3D = 2; F1ADDIN_REGION = 3;type TOleVariantArray=array[0..1024] of OleVariant; pOleVariantArray=^TOleVariantArray; TF1ADDIN_FUNCTION = function(var pResult: OleVariant; nReserved: Integer; nArgs: Integer; pArgs: pOleVariantArray): HRESULT stdcall; TF1AddInRegisterFunctionProc = function(pwszName: LPCWSTR; nReserved: Integer; pFunction: TF1ADDIN_FUNCTION; nArgs: Integer): HRESULT stdcall; TF1AddINRegisterInfoProc = function(pwszName,pwszDescription: LPCWSTR; nReserved1,nReserved2: Integer): HRESULT stdcall; function MakeErrorResult(var pResult: OleVariant; hrEval: HRESULT = S_OK): HRESULT; function F1AddInInit(RegisterInfoProc: TF1AddInRegisterInfoProc; RegisterFunctionProc: TF1AddInRegisterFunctionProc; nReserved1,nReserved2: Integer): HRESULT stdcall; function GetInRange(var pResult: OleVariant; nReserved: Integer; nArgs: Integer; pArgs: pOleVariantArray): HRESULT; stdcall; implementation {$M+} {$TYPEINFO ON}function F1AddInInit(RegisterInfoProc: TF1AddInRegisterInfoProc; RegisterFunctionProc: TF1AddInRegisterFunctionProc; nReserved1,nReserved2: Integer): HRESULT stdcall; var hr: HRESULT; begin hr := S_OK; if (SUCCEEDED(hr)) then hr := RegisterFunctionProc('myadd',0,GetInRange,2); if (SUCCEEDED(hr)) then hr := RegisterInfoProc('Delphi F1book Add_In','',0,0);Result := hr; end;function CheckReturnValue(hr: HRESULT): HRESULT; begin if FAILED(hr) then Result := E_OUTOFMEMORY else Result := S_OK; end;function GetInRange(var pResult: OleVariant; nReserved: Integer; nArgs: Integer; pArgs: pOleVariantArray): HRESULT; stdcall; begin if nArgs = 2 then begin if (TvarData(pArgs[0]).VType = varDouble) and (TvarData(pArgs[1]).VType = varDouble) then begin pResult := TvarData(pArgs[0]).VDouble + TvarData(pArgs[1]).VDouble; Result := S_OK; Exit; end; end; Result := MakeErrorResult(pResult, F1_E_VALUE); end;function MakeErrorResult(var pResult: OleVariant; hrEval: HRESULT = S_OK): HRESULT; begin if hrEval <> S_OK then begin varClear(pResult); TvarData(pResult).vType := varError; TvarData(pResult).vError := hrEval; end; Result := S_OK; end;end.
在界面上显示的sheetname好像是没有办法改变字体和字号的,但是如果做报表打印的 时候是可以改变的.可以在F1Book的PrintHeader中设置格式字符串,和Excel的做法 基本是一样的,你可以先在excel中的表头中设置自定义表头,增加一些直观影响(因为 那个在Excel中是所见即所得的,比较直观).下面是F1book中的表头和脚注格式化字符 串的说明:Headers and footers can contain text and special formatting codes. These codes allow you to format and align the text and to insert worksheet-specific information, like page numbers and the worksheet name. The alignment codes (&L, &C, and &R) must go before font-related codes (like &B for bold and &I for italic). Codes for printing worksheet-specific information like worksheet title go last. If you put the codes in the wrong order, Formula One may ignore some of them. Separate codes with spaces. By default, headers and footers are centered unless you specify &L or &R.Format Code Description &L Left-aligns the characters that follow. &C Centers the characters that follow. &R Right-aligns the characters that follow. &B Use a bold font. &I Use an italic font. &U Underline the header. &S Strikeout the header. &O Ignored. &H Ignored. &"fontname" Use the specified font. &nn Use the specified font size (must be a two digit number). &D Prints the current date. &T Prints the current time. &F Prints the workbook name. &A Prints the worksheet name. &P Prints the page number. &P+number Prints the page number plus number. &P-number Prints the page number minus number. && Prints an ampersand. &N Prints the total number of pages in the document. 将选中的单元格加上蓝色的双线框 fb.SetBorder(6,6,6,6,6,-1,clBlue,clBlue,clBlue,clBlue,clBlue);你看一下Formula One中关于SaveFileDlgEx的例程: Dim fInfo As New F1FileSpec ~~~~~~ 注意到了吗 F1Book1.SaveFileDlgEx "", fInfo F1Book1.WriteEx fInfo.Name, fInfo.Type在Delphi中生成这个F1FileSpec对象要自己做. use comobj; procedure TForm1.Button1Click(Sender: TObject); var pFileSpec: F1FileSpec; begin pFileSpec := CreateComObject(CLASS_F1FileSpec) as IF1FileSpec; F1Book61.SaveFileDlgEx('Save Account', pFileSpec); F1Book61.WriteEx(pFileSpec.Name, pFileSpec.type_); end; SetBorder的具体用法可以参考F1book的联机帮助,有详细介绍
代码公布如下,希望对大家有帮助unit F1AddInUnit;interface
uses windows,dialogs,Sysutils,TTF160_TLB;const
F1_E_NULL = $80040001; // #NULL!
F1_E_DIVZERO = $80040002; // #DIV/0!
F1_E_VALUE = $80040003; // #VALUE!
F1_E_REF = $80040004; // #REF!
F1_E_NAME = $80040005; // #NAME?
F1_E_NUM = $80040006; // #NUM!
F1_E_NA = $80040007; // #N/A F1ADDIN_ARRAY = 0; // Not implemented in Formula One 6.1
F1ADDIN_AREA = 1;
F1ADDIN_AREA3D = 2;
F1ADDIN_REGION = 3;type
TOleVariantArray=array[0..1024] of OleVariant;
pOleVariantArray=^TOleVariantArray; TF1ADDIN_FUNCTION = function(var pResult: OleVariant;
nReserved: Integer;
nArgs: Integer;
pArgs: pOleVariantArray): HRESULT stdcall; TF1AddInRegisterFunctionProc = function(pwszName: LPCWSTR;
nReserved: Integer;
pFunction: TF1ADDIN_FUNCTION;
nArgs: Integer): HRESULT stdcall;
TF1AddINRegisterInfoProc = function(pwszName,pwszDescription: LPCWSTR;
nReserved1,nReserved2: Integer): HRESULT stdcall; function MakeErrorResult(var pResult: OleVariant; hrEval: HRESULT = S_OK): HRESULT;
function F1AddInInit(RegisterInfoProc: TF1AddInRegisterInfoProc;
RegisterFunctionProc: TF1AddInRegisterFunctionProc;
nReserved1,nReserved2: Integer): HRESULT stdcall;
function GetInRange(var pResult: OleVariant;
nReserved: Integer;
nArgs: Integer;
pArgs: pOleVariantArray): HRESULT; stdcall;
implementation
{$M+}
{$TYPEINFO ON}function F1AddInInit(RegisterInfoProc: TF1AddInRegisterInfoProc;
RegisterFunctionProc: TF1AddInRegisterFunctionProc;
nReserved1,nReserved2: Integer): HRESULT stdcall;
var
hr: HRESULT;
begin
hr := S_OK;
if (SUCCEEDED(hr)) then
hr := RegisterFunctionProc('myadd',0,GetInRange,2);
if (SUCCEEDED(hr)) then
hr := RegisterInfoProc('Delphi F1book Add_In','',0,0);Result := hr;
end;function CheckReturnValue(hr: HRESULT): HRESULT;
begin
if FAILED(hr) then
Result := E_OUTOFMEMORY
else
Result := S_OK;
end;function GetInRange(var pResult: OleVariant;
nReserved: Integer;
nArgs: Integer;
pArgs: pOleVariantArray): HRESULT; stdcall;
begin
if nArgs = 2 then begin
if (TvarData(pArgs[0]).VType = varDouble) and (TvarData(pArgs[1]).VType = varDouble) then begin
pResult := TvarData(pArgs[0]).VDouble + TvarData(pArgs[1]).VDouble;
Result := S_OK;
Exit;
end;
end;
Result := MakeErrorResult(pResult, F1_E_VALUE);
end;function MakeErrorResult(var pResult: OleVariant; hrEval: HRESULT = S_OK): HRESULT;
begin
if hrEval <> S_OK then begin
varClear(pResult);
TvarData(pResult).vType := varError;
TvarData(pResult).vError := hrEval;
end;
Result := S_OK;
end;end.
时候是可以改变的.可以在F1Book的PrintHeader中设置格式字符串,和Excel的做法
基本是一样的,你可以先在excel中的表头中设置自定义表头,增加一些直观影响(因为
那个在Excel中是所见即所得的,比较直观).下面是F1book中的表头和脚注格式化字符
串的说明:Headers and footers can contain text and special formatting codes. These codes allow
you to format and align the text and to insert worksheet-specific information, like
page numbers and the worksheet name.
The alignment codes (&L, &C, and &R) must go before font-related codes
(like &B for bold and &I for italic). Codes for printing worksheet-specific
information like worksheet title go last. If you put the codes in the wrong
order, Formula One may ignore some of them. Separate codes with spaces. By
default, headers and footers are centered unless you specify &L or &R.Format Code Description
&L Left-aligns the characters that follow.
&C Centers the characters that follow.
&R Right-aligns the characters that follow.
&B Use a bold font.
&I Use an italic font.
&U Underline the header.
&S Strikeout the header.
&O Ignored.
&H Ignored.
&"fontname" Use the specified font.
&nn Use the specified font size (must be a two digit number).
&D Prints the current date.
&T Prints the current time.
&F Prints the workbook name.
&A Prints the worksheet name.
&P Prints the page number.
&P+number Prints the page number plus number.
&P-number Prints the page number minus number.
&& Prints an ampersand.
&N Prints the total number of pages in the document.
将选中的单元格加上蓝色的双线框
fb.SetBorder(6,6,6,6,6,-1,clBlue,clBlue,clBlue,clBlue,clBlue);你看一下Formula One中关于SaveFileDlgEx的例程:
Dim fInfo As New F1FileSpec
~~~~~~
注意到了吗
F1Book1.SaveFileDlgEx "", fInfo
F1Book1.WriteEx fInfo.Name, fInfo.Type在Delphi中生成这个F1FileSpec对象要自己做.
use comobj;
procedure TForm1.Button1Click(Sender: TObject);
var
pFileSpec: F1FileSpec;
begin
pFileSpec := CreateComObject(CLASS_F1FileSpec) as IF1FileSpec;
F1Book61.SaveFileDlgEx('Save Account', pFileSpec);
F1Book61.WriteEx(pFileSpec.Name, pFileSpec.type_);
end;
SetBorder的具体用法可以参考F1book的联机帮助,有详细介绍