起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 272|回复: 6

【结贴】对word文档的操作**

[复制链接]
发表于 2008-2-26 11:48:36 | 显示全部楼层 |阅读模式
有没有根据服务器上某一word文档模板创建一个新的word文档保存到数据库中的代码样例?
回复

使用道具 举报

 楼主| 发表于 2008-2-26 13:46:30 | 显示全部楼层
如图:

b1.jpg

147.16 KB, 下载次数: 206

回复 支持 反对

使用道具 举报

发表于 2008-2-27 13:19:14 | 显示全部楼层
知识中心支持模版创建,但是需要购买。而且模版是存放在文档服务器上的,并不存放在数据库里面。
回复 支持 反对

使用道具 举报

发表于 2008-3-4 13:17:08 | 显示全部楼层
??
回复 支持 反对

使用道具 举报

发表于 2008-5-13 11:10:49 | 显示全部楼层
由于长时间没有回复,先结贴了,有问题请开新帖。
回复 支持 反对

使用道具 举报

发表于 2008-5-13 11:15:12 | 显示全部楼层
//upcase button event
procedure TWBSCBD.ButtonUpcaseClick(Sender: TObject);
var
    //selWordName : String;
    wordName : String;
    dataSet : TSQLDataSet;
    infoType : String;
begin
  Screen.Cursor := crHourGlass;
  selWordName := EditName.Text.Trim();

  if trim(selWordName) = '' then
      JSDialogs.ShowMsg('请选择需要上传的文件名称!','提示:')
  else
  begin
      //JSDialogs.ShowMsg(wordName,'');
      infoType := CB_InfoType.Text.Trim();
      //upcase word into table
        dataSet := DataSetBrokerHT.DataSet as TSQLDataSet;


      if not dataSet.Active then
         dataSet.Open;

      dataSet.Locate('ContractID' ,[ContractID], []);
      wordName := rootPath + '\' + dataSet.FieldByName('ContractName').AsString +'.doc';
      dataSet.Edit;
      //JSDialogs.ShowMsg(DataSetBrokerHTLX.DataSet.FieldByName('ContractType').AsString,'提示:') ;
      TBlobField(dataSet.FieldByName('ContractContent')).LoadFromFile(wordName);
      dataSet.FieldByName('wordName').AsString := selWordName;
      dataSet.ApplyUpdates;
      //清空 word
      TUnStructureDocUtils.DelExistFile(wordName);
  end;
  Screen.Cursor := crDefault;
end;
回复 支持 反对

使用道具 举报

发表于 2008-5-13 11:18:54 | 显示全部楼层
uses
  Business.System, Business.Model, Business.Forms, Business.Data
  ,GJL,
  DocOffice ,DocLib ,
  Business.System.SysUtils
   ,Business.Forms.Forms ,Business.Forms.Controls, sictrpt;

===============

FWordOleExtend: TWordOleExtend;
    rootPath : String;
    selWordName ,ContractID: String;

============


{打开WORD 合同}
procedure TWBSCBD.EditModle();
Var
    selectedModel ,selectedDoc : String;
    newWordName ,infoType : String;
    isSelectModel, isSelectDoc : boolean;
    atts : TStrings;
    lBizURL : TBizURL;
    datas : Vector;
begin
    WebB_Word.Navigate('about:blank');

    selectedModel := DataSetBrokerHTMB.DataSet.FieldByName('MDName').AsString;

    infoType := CB_InfoType.Text.Trim();
    lBizURL := TBizURL.Create;

    selectedDoc := DataSetBrokerHT.DataSet.FieldByName('ContractName').AsString;
    ContractID := DataSetBrokerHT.DataSet.FieldByName('ContractID').AsString;
    lBizURL.URL := htTableURL;

    selWordName := selectedDoc;
    //JSDialogs.ShowMsg(selWordName,'提示:');
    //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
      DataSetBrokerHTMB.DataSet.Locate('MDName' ,[selectedModel], []);

      TBlobField(DataSetBrokerHTMB.DataSet.FieldByName('Content')).SaveToFile(newWordName);
      //给宏赋值
      atts := TStringList.Create;
      //lBizURL := TBizURL.Create;
      //lBizURL.URL := cTableURL;
      atts := getAttName(lBizURL ,infoType);
      TUnStructureDocUtils.OpenWordDoc(FWordOleExtend, newWordName, False);

      datas := getAttValue(atts , selectedDoc, FWordOleExtend,ContractID);
      TUnStructureDocUtils.ShowWordFieldCodes(FWordOleExtend, False);
      TUnStructureDocUtils.SaveWordDoc(FWordOleExtend);
      TUnStructureDocUtils.CloseWordDoc(FWordOleExtend);
      TUnStructureDocUtils.DestroyWordOleExtend(FWordOleExtend);
      atts.Clear;
      //open word
      //TUnStructureDocUtils.OpenWordDoc(FWordOleExtend, newWordName, True); //way 1
      WebB_Word.Navigate(newWordName);  //way 2

      //TUnStructureDocUtils.ShowWordFieldCodes(FWordOleExtend, True);
    end
    else
      JSDialogs.ShowMsg('请选择合同模版名称和选择合同名称!','提示:');


    ButtonClose.Enabled := True;
    ButtonUpcase.Enabled := False;
end;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-12 14:30 , Processed in 0.042586 second(s), 19 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表