{打开WORD 合同}
procedure TNDFDHTCT.EditModle(dataSet : TSQLDataSet);
Var
selectedModel : String;
selectedDoc : String;
newWordName : String;
mID : Integer;
isSelectModel, isSelectDoc : boolean;
atts : TStrings;
lBizURL : TBizURL;
begin
WebB_Word.Navigate('about:blank');
selectedModel := DEdit_CModel.Text.Trim();
selectedDoc := Edit_Name.Text.Trim();
//JSDialogs.ShowMsg(selectedName,'提示:');
//word Operater
if FWordOleExtend <> nil then
TUnStructureDocUtils.DestroyWordOleExtend(FWordOleExtend);
FWordOleExtend := TUnStructureDocUtils.CreateWordOleExtend('');
//create file directory
if not DirectoryExists(rootPath) then
begin
if not DirectoryExists(rootPath ) then
CreateDir(rootPath ) ;
end;
if trim(selectedModel) = '' then
isSelectModel := false
else
isSelectModel := True;
if trim(selectedDoc) = '' then
isSelectDoc := false
else
isSelectDoc := True;
if isSelectModel and isSelectDoc then
begin
newWordName := rootPath + '\' + selectedDoc +'.doc';
if FileExists(newWordName) then
//delete word
TUnStructureDocUtils.DelExistFile(newWordName);
//download word
if not DataSetBrokerHTMB.DataSet.Active then
DataSetBrokerHTMB.DataSet.Open;
mID := DataSetBrokerHTMB.DataSet.FieldByName('MID').AsInteger;
//JSDialogs.ShowMsg(SysUtils.IntToStr(mID),''); 都能提示!!!!!!!!
//下面抛的异常 ,如果第一次选id=1的话,第2次为2就错误,为1 就没有任何问题
DataSetBrokerHTMB.DataSet.Locate('MID' ,mID, []);
TBlobField(DataSetBrokerHTMB.DataSet.FieldByName('ContractContent')).SaveToFile(newWordName);
//给宏赋值
atts := TStringList.Create;
lBizURL := TBizURL.Create;
lBizURL.URL := cTableURL;
atts := getAttName((DataSetBrokerJBXX.DataSet as TSQLDataSet), lBizURL);
TUnStructureDocUtils.OpenWordDoc(FWordOleExtend, newWordName, False);
getAttValue(atts , selectedDoc, FWordOleExtend);
TUnStructureDocUtils.ShowWordFieldCodes(FWordOleExtend, False);
TUnStructureDocUtils.SaveWordDoc(FWordOleExtend);
TUnStructureDocUtils.CloseWordDoc(FWordOleExtend);
TUnStructureDocUtils.DestroyWordOleExtend(FWordOleExtend);
atts.Clear;
//upcase word
dataSet.Edit;
TBlobField(dataSet.FieldByName('ContractContent')).LoadFromFile(newWordName);
dataSet.FieldByName('wordflag').AsInteger := 1;
dataSet.ApplyUpdates;
//open word
//TUnStructureDocUtils.OpenWordDoc(FWordOleExtend, newWordName, True); //way 1
WebB_Word.Navigate(newWordName); //way 2
//TUnStructureDocUtils.ShowWordFieldCodes(FWordOleExtend, True);
end
else
JSDialogs.ShowMsg('请选择合同模版名称和选择合同名称!','提示:');
end; |