• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

DelphiNote

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Delphi Note

源数据库:

名称:info

字段:iddnameeagesexcitydepartmentposition

目标数据库:

名称:leave

字段:iddnameetype

1、 修改操作。(原代码)

CREATE TRIGGER test_upd on  info

FOR UPDATE

AS

 if update(namee)

 update leave

 set leave.namee=i.namee

 from inserted i

 where leave.idd=i.idd

2、 删除操作。(原代码)

CREATE TRIGGER test_del on  [info]

FOR DELETE

AS

declare @id char(10)

select @id= idd from deleted

delete from leave where idd=@id

3、 插入操作。(原代码)

CREATE TRIGGER test_INS ON info

FOR INSERT

AS

insert into leave

(idd,namee)

SELECT i.idd,i.namee FROM inserted i

2ADO的认识

Microsoft的数据存取技术演变:

1、 ODBC仅支持关系数据库,以及传统的数据库类型,无法符合日渐复杂的数据存取应用,也无法让脚本语言使用,。

2、 DAOMicrosoft为能让程序员存取Access数据库,产生了DAOData Access Object),能够存取Xbase的数据库及Excel文件,并且结ODBC存取关系数据库。但去目的是存取Access数据库,因此只对Access数据库非常有效率,先已处于维护状态。

3、 RDO由于DAO在结合ODBC存取关系数据库时表现的不好,所以Microsoft推出了RDO,不过目前也逐渐被放弃了。

4、 OLEDB是很底层化的,使用复杂的,可以存取传统的关系数据库、Excel文件、EmailInternet/Intranet上的电子签名信息。

5、 ADO成功的封装了OLE-DB的大部分功能,可以让应用程序或WEB应用程序存取各种不通的数据源。大大简化了数据存取工作。

3TdatabaseTUpdateSql组件的作用。

       TdatabaseBDEQueryTable连接的中间通道。这样程序修改时,只要修改Datebase的属性就可以了。通过其Database的属性设定公用的别名。

       TupdateSql是用来进行网络数据库数据的修改。Query1.Applyupdates;Query1.CommitUpdates;另外,被修改的Server端数据库表要有key

4、开发Activex控件。

<>转换ActiveX控件

第一步 选择菜单FileNew项,出现项目对话框,选择Activex页,选择ActiveX Control

第二步 在出现的向导对话框(ActiveX Control Wizard)中,从控件列表中选择转换的控件。

第三步 注册ActiveX。选择菜单RunRegister ActiveX Server。即生成一个OCX文件,存储于当前路径。

第四步 Web配置选项。选择菜单ProjectWeb deploymentOption。设定路径。

第五步 生成HTML文档。选择菜单ProjectWeb Deploy。然后,在HTML dir所指示的目录下,外面可以看到HTML文件已经生成。

<>开发新的ActiveX控件

第一步 建立一个ActiveX Form。选择菜单FileNew,出现项目对话框,选择Activex页,选择ActiveForm

第二步 ActiveForm Wizard对话框中输入各种名称。

第三步 ActiveX Wizard上,加入控件,譬如加入一个Button、一个Image组件,在buttonOnClick事件中,有如下的处理:

            Image1.Canvas.Ellipse(0,0,Image1.Width,Image1.Height);

第四步 编译。按Ctrl+F9组合健,或选择ProjiectCompileFormProj1

第五步 注册ActiveX,生成OCX文件,选择菜单RunRegister ActiveX Server

第六步 Web配置选项。选择菜单ProjectWeb Deploy

第七步 生成HTML文档。选择菜单ProjectWeb Deploy

 

 

5、恢复SQL.mdf.log文件。

EXEC sp_attach_db @dbname = N'AAA', //AAA为要建立的数据库名

   @filename1 = N'c:"ooo"aaa.mdf',

@filename2 = N'c:"ooo"aaa_log.ldf'

6bmpjpg的转换和数据库中bmpjpg格式图形的存储。

Demo1

var blobstream:tblobstream;
    filestream:tfilestream;
begin
  table1.insert;
blobstream:=table1.createblobstream(table1.fieldbyname('picture'),bmreadwrite);
filestream:=tfilestream.create('d:"picture.jpg',fmread);
  blobstream.copyfrom(filestream,filestream.size);
  table1.post;
要是想保存
var blobstream:tblobstream;
    filestream:tfilestream;
begin
  blobstream:=table1.createblobstream(table1.fieldbyname('picture'),bmread);
  filestream:=tfilestream.create('d:"picture.jpg',fmcreate or fmwrite);
  filestream.copyfrom(filestream,filestream.size);
就可以了,加分吧

 

demo2

var
bs: TBlobStream;
begin
bs:=Table1.FieldByName('c1').CreateBlobStream(
Table1.FieldByName('c1'), bmWrite);
Graphic.SaveToStream(bs);
end;

 

7、控制EXCEL

全面控制 Excel
首先创建 Excel 对象,使用ComObj:
var ExcelID: Variant;
ExcelID := CreateOleObject( 'Excel.Application' );
1) 显示当前窗口:
ExcelID.Visible := True;
2) 更改 Excel 标题栏:
ExcelID.Caption := '应用程序调用 Microsoft Excel';
3) 添加新工作簿:
ExcelID.WorkBooks.Add;
4) 打开已存在的工作簿:
ExcelID.WorkBooks.Open( 'C:"Excel"Demo.xls' );
5) 设置第2个工作表为活动工作表:
ExcelID.WorkSheets[2].Activate;  

ExcelID.WorksSheets[ 'Sheet2' ].Activate;
6) 给单元格赋值:
ExcelID.Cells[1,4].Value := '第一行第四列';
7) 设置指定列的宽度(单位:字符个数),以第一列为例:
ExcelID.ActiveSheet.Columns[1].ColumnsWidth := 5;
8) 设置指定行的高度(单位:磅)(1磅=0.035厘米),以第二行为例:
ExcelID.ActiveSheet.Rows[2].RowHeight := 1/0.035; // 1厘米
9) 在第8行之前插入分页符:
ExcelID.WorkSheets[1].Rows[8].PageBreak := 1;
10) 在第8列之前删除分页符:
ExcelID.ActiveSheet.Columns[4].PageBreak := 0;
11) 指定边框线宽度:
ExcelID.ActiveSheet.Range[ 'B3:D4' ].Borders[2].Weight := 3;
1-    2-   3-    4-   5-( " )     6-( / )
12) 清除第一行第四列单元格公式:
ExcelID.ActiveSheet.Cells[1,4].ClearContents;
13) 设置第一行字体属性:
ExcelID.ActiveSheet.Rows[1].Font.Name := '隶书';
ExcelID.ActiveSheet.Rows[1].Font.Color  := clBlue;
ExcelID.ActiveSheet.Rows[1].Font.Bold   := True;
ExcelID.ActiveSheet.Rows[1].Font.UnderLine := True;
14) 进行页面设置:
a.页眉:
    ExcelID.ActiveSheet.PageSetup.CenterHeader := '报表演示';
b.页脚:
    ExcelID.ActiveSheet.PageSetup.CenterFooter := '&P';
c.页眉到顶端边距2cm
    ExcelID.ActiveSheet.PageSetup.HeaderMargin := 2/0.035;
d.页脚到底端边距3cm
    ExcelID.ActiveSheet.PageSetup.HeaderMargin := 3/0.035;
e.顶边距2cm
    ExcelID.ActiveSheet.PageSetup.TopMargin := 2/0.035;
f.底边距2cm
    ExcelID.ActiveSheet.PageSetup.BottomMargin := 2/0.035;
g.左边距2cm
    ExcelID.ActiveSheet.PageSetup.LeftMargin := 2/0.035;
h.右边距2cm
    ExcelID.ActiveSheet.PageSetup.RightMargin := 2/0.035;
i.页面水平居中:
    ExcelID.ActiveSheet.PageSetup.CenterHorizontally := 2/0.035;
j.页面垂直居中:
    ExcelID.ActiveSheet.PageSetup.CenterVertically := 2/0.035;
k.打印单元格网线:
    ExcelID.ActiveSheet.PageSetup.PrintGridLines := True;
15) 拷贝操作:
a.拷贝整个工作表:
    ExcelID.ActiveSheet.Used.Range.Copy;
b.拷贝指定区域:
    ExcelID.ActiveSheet.Range[ 'A1:E2' ].Copy;
c.A1位置开始粘贴:
    ExcelID.ActiveSheet.Range.[ 'A1' ].PasteSpecial;
d.从文件尾部开始粘贴:
    ExcelID.ActiveSheet.Range.PasteSpecial;
16) 插入一行或一列:
a. ExcelID.ActiveSheet.Rows[2].Insert;
b. ExcelID.ActiveSheet.Columns[1].Insert;
17) 删除一行或一列:
a. ExcelID.ActiveSheet.Rows[2].Delete;
b. ExcelID.ActiveSheet.Columns[1].Delete;
18) 打印预览工作表:
ExcelID.ActiveSheet.PrintPreview;
19) 打印输出工作表:
ExcelID.ActiveSheet.PrintOut;
20) 工作表保存:
if not ExcelID.ActiveWorkBook.Saved then
   ExcelID.ActiveSheet.PrintPreview;
21) 工作表另存为:
ExcelID.SaveAs( 'C:"Excel"Demo1.xls' );
22) 放弃存盘:
ExcelID.ActiveWorkBook.Saved := True;
23) 关闭工作簿:
ExcelID.WorkBooks.Close;
24) 退出 Excel
ExcelID.Quit;

8、将EXCEL表中的数据导入到库中

 

程序中实现的办法:

如何将Excel文件中的数据倒入Delphi本地库(Paradox)?[2000-04-26]
label PH;
var
msexcel : olevariant;
wbook, wsheet : olevariant;
i,j : integer;
temp : string;
...
begin
MsExcel := CreateOleObject('Excel.Application');
WBook := MsExcel.Application;
WBook.Visible := False;
wbook.workbooks.Open('c:"xxxx.xls');//
打开Excel文档
WSheet := WBook.ActiveSheet;
for i := 1 to WSheet.Rows.count - 1 do
begin
Table1.Append;            //Paradox,其它表当然也可以了
for j := 1 to WSheet.Columns.Count do
begin
temp := wsheet.cells[i, j].value;
if Trim(temp) = '' then    //如果为空则跳出循环,当然,
// 也可以是其它条件
goto PH;
Table1.Fields[j - 1].AsString := temp;
end;
PH:
if Trim(wsheet.cells[i, 1].Value) = '' then break;//跳出循环
end;
...
WBook.SaveAs('c:"xxxx.xls');
MsExcel.quit;
end;
注意:Tabel1的字段数要大于要倒入的Excel文档的列数

 

9、取得字段的属性

找了一些以前写过的代码 :
var fType :TfieldType;
    strType :String;
Adotable1.Fields[0].DataSize 得到 宽度  !
fType :=AdoTable1.Fields[0].Dataset 用于得到field的类型,这个结果不是string,你要自己去转换:
Case fType  of
     ftWideString : strType:='Text';
     ftDate: strType :='Date';
     ftString :strType :='Text';
     ftBoolean:strType :='Boolean';
     ftMemo :strType :='memo';
     ftSmallint :strType:='Integer' ;
     ftUnknown :strType:='Unknown';
end;
另外还有一种 :
var
    i:Integer;
    FieldType:String;

    case varastype(ADOTable1.Fields[i].DataType,varInteger) of
        24: FieldType:='字符型';
        16: FieldType:='备注型';
        3 : FieldType:='数值型';
        11: FieldType:='日期时间型';
        8 : FieldType:='货币型';
        14: FieldType:='自动编号型';
        5 : FieldType:='逻辑型';
        15: FieldType:='OLE对象型';
    end;

10、在query中检索记录

     if query1.Locate('ID','A001',[loCaseInsensitive])then begin

        showmessage('有重复记录。');

注意lacate执行后会将Query的属性置回到readonly状态。

所以query1.Edit要放在locate后。

 

11、把程序加进windows的“启动”中

 

 

procedure TFrmAbout.WriteRegAutoRun(FileName:string);   
var
 Regf:TRegistry;
begin
 Regf:=TRegistry.Create;
 Regf.RootKey:=HKEY_LOCAL_MACHINE;
 
 if Length(FileName)>0 then
   try
    RegF.OpenKey('SOFTWARE"Microsoft"Windows"CurrentVersion"Run',false);
    RegF.WriteString('YourProgram',FileName);
   except
   end;
 RegF.CloseKey;
 RegF.Free;

end;

 

十二、控制Word

启动Word时用如下代码:
begin
try
Wordapplication.Connect;
except
MessageDlg('Word may not be installed', mtError, [mbOk], 0);
Abort;
end;
Wordapplication.Visible := True;
WordApplication.Caption := 'Delphi automation';
end;
Word打开一个指定的文件,需要先放置OpenDialog,然后调用WordApplication.Documents.Open
var
ItemIndex :OleVariant;
FileName, ConfirmConversions, ReadOnly, AddToRecentFiles,
PasswordDocument, PasswordTemplate, Revert,
WritePasswordDocument, WritePasswordTemplate, Format: OleVariant;
begin
if not dlgOpen.Execute then
Exit;

{Open document}
FileName := dlgOpen.FileName;
ConfirmConversions := False;
ReadOnly := False;
AddToRecentFiles := False;
PasswordDocument := '';
PasswordTemplate := '';
Revert := True;
WritePasswordDocument := '';
WritePasswordTemplate := '';
Format := wdOpenFormatDocument;

WordApplication.Documents.Open( FileName, ConfirmConversions,
ReadOnly, AddToRecentFiles, PasswordDocument, PasswordTemplate,
Revert, WritePasswordDocument, WritePasswordTemplate, Format );

{Assign WordDocument component}
ItemIndex := 1;
WordDocument.ConnectTo(WordApplication.Documents.Item(ItemIndex));

{Turn Spell checking of because it takes a long time if enabled and slows down Winword}
WordApplication.Options.CheckSpellingAsYouType := False;
WordApplication.Options.CheckGrammarAsYouType := False;
end;

 

判断Word是否运行

先在Form上添加一个Server组件中的WordApplication,命名为WordApplication1,然后在"关闭WORD"按扭中输入如下代码:
var
    SaveChanges, OriginalFormat, RouteDocument: OleVariant;
begin
    SaveChanges := WdDoNotSaveChanges;
    OriginalFormat := UnAssigned;
    RouteDocument := UnAssigned;
    try
        WordApplication1.Quit(SaveChanges, OriginalFormat, RouteDocument);
        WordApplication1.Disconnect;
    except
    on E: Exception do
        begin
            Showmessage(E.Message);
            WordApplication1.Disconnect;
        end;
    end;
end;
准成,当然了,请按实际情况修改 SaveChanges, OriginalFormat, RouteDocument的内容.

 

如何输出到Word

如果用的是MICROSOFT 旗下的数据库管理系统生成的表例如*.DBF等,可以通过OLE技术直接在WORD文档中显示完整的数据表。
如果用PARADOX表,可以用下面的方法:
var
  msword:variant;
begin
  try
    msword:=createoleobject('word.basic');
    msword.filenew;
    msword.appshow;
    table1.disablecontrols;
    try
      bookmark:=table1.getbookmark;
      try
        msword.bold;
        msword.insert('
报表标题'#13#10);
        msword.insert('字段名1'+#9+....+'字段名n'#13#10);
        table1.first;
        while not table1.eof do
          begin
            msword.insert(table1.fieldbyname(字段名1).asstring+#9+.....+table1.fieldbyname(字段名n).asstring+#13#10);
            msword.next;
          end;
         finally
           table1.gotobookmark(bookmark);
           table1.freebookmark(bookmark);
         end;
       finally
         table1.enablecontrols;
        end;
    except
       showmessage('
没有发现WORD,请安装!');
    end;
end;
//OLE服务器WORD启动后自动写了一个制表文件,此时只要选择全部数据(除标题),然后选插入表格即可作出WORD报表。
//如果有其他好方法请与我联系。
//我想解决的是在程序中自动画出表格。

 

 

控制Word

var
tbl : Table;
i,j:integer;
un_Var,ex_Var,cnt_Var:OleVariant;
row_num,col_num:integer;
st:string;
begin
    // Word中新建一个文档,并添加文本,然后设置粗体和字体大小
    WordApplication1.Connect;
    WordApplication1.Visible := True;
    WordApplication1.Documents.Add(EmptyParam,EmptyParam);
    WordDocument1.Connect;
    WordApplication1.ActiveWindow.View.Type_:= wdNormalView;
    WordApplication1.Selection.Font.Name :='黑体';
    WordApplication1.Selection.Font.Size := 16;
    WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
    WordApplication1.Selection.TypeText('昆明市土地信息系统表格输出');
    WordApplication1.Selection.TypeParagraph;
    WordApplication1.Selection.TypeParagraph;
    WordApplication1.Selection.Font.Name :=  '宋体';
    WordApplication1.Selection.Font.Size :=12;
    WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphRight;
    WordApplication1.Selection.TypeText('日期'+formatdatetime('yyyy""mm""dd""',now));
    WordApplication1.Selection.TypeParagraph;
    WordApplication1.Selection.TypeParagraph;//回车
    WordApplication1.Selection.ParagraphFormat.Alignment := wdAlignParagraphLeft;
    row_num:=table1.RecordCount;
    col_num:=table1.Fields.Count;
    tbl := WordApplication1.ActiveDocument.Tables.Add(WordApplication1.Selection.Range,row_num+1,Col_num);
    un_Var:=wdCharacter;
    cnt_Var:=1;
    ex_Var:=wdMove;
    table1.First;
    for j := 0 to Col_num-1 do    //标题
    begin
            st:=table1.Fields.Fields[j].FieldName;
            WordApplication1.Selection.TypeText(st);
            WordApplication1.Selection.MoveRight(un_Var,cnt_Var,ex_Var);
    end;
    for i := 0 to row_num-1 do    //
    begin
        for j := 0 to Col_num-1 do    //
        begin
            st:=table1.Fields.Fields[j].AsString;
            WordApplication1.Selection.TypeText(st);
            WordApplication1.Selection.MoveRight(un_Var,cnt_Var,ex_Var);
        end;
        WordApplication1.Selection.MoveRight(un_Var,cnt_Var,ex_Var);
        table1.next;
    end;
    WordApplication1.Selection.TypeText('制表人:阎磊');
    WordApplication1.Selection.TypeParagraph;
end;

 

 

可以参考以下代码:
procedure PrintReport4(DSR, AJXZ, CFSJ, JBAQ: PChar); stdcall;
var
 Word, Doc, Fields:OleVariant;
begin
 Word:=CreateOleObject('Word.Application');
 
 Word.Visible:=True;
 
 Word.Documents.Add('C:"Customs"案件呈报表');
 Doc := Word.ActiveDocument;
 
 Fields := Doc.FormFields;
 Fields.Item('DSR').Result := String(DSR);
 Fields.Item('AJXZ').Result := String(AJXZ);
 Fields.Item('CFSJ').Result := String(CFSJ);
 Fields.Item('JBAQ').Result := String(JBAQ);
end;
 
其中案件呈报表就是word模版文件。

 

 

打开WORD文档的一段程序
uses ComObj ;
procedure TForm1.Button1Click(Sender: TObject);
var
 vWord,vDoc,vRange : Variant ;
 sText,sReplace : string ;
 lReturn : Boolean ;
begin
  sText := 'ABCDEFG' ; //原文字串
 sReplace := 'GFEDCBA' ; //新字串
 vWord := CreateOleObject('Word.Application') ;//创建Word线程
 try
    //打开要操作的文件
    vDoc := vWord.Documents.Open('C:"My Documents"AAAc.Doc');
    vDoc.Select ; //选取中整个文档
    vRange := vDoc.Range ; //替换范围
    lReturn := True ;
    while lReturn do
    begin //找到并替代成功则返回 True    共11个参数
      lReturn := vDoc.Range.Find.Execute(sText,,,,,,,,,sReplace,True) ;
    end ;
 finally
    vDoc.Close(True) ; //关闭文并保存
    vWord.Quit(False) ; //退出Word
 end ;
end;
Delphi 3 下通过。
 
 
 
控制WORD文档的一段程序
unit Unit1;
 
interface
 
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,OleCtnrs,ComObj;
 
type
    TForm1 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    ED_WenHao: TEdit;
    ED_BiaoTi: TEdit;
    ED_ShouWenDanWei: TEdit;
    ED_ZhenWen: TMemo;
    ED_FaWenDanWei: TEdit;
    Btn_PrintToWord: TButton;
    Btn_Quit: TButton;
    procedure Btn_PrintToWordClick(Sender: TObject);
    procedure Btn_QuitClick(Sender: TObject);
    private
        { Private declarations }
    public
        { Public declarations }
end;
 
var
    Form1: TForm1;
 
implementation
 
{$R *.DFM}
 
//开始:数据发送到 word事件
procedure TForm1.Btn_PrintToWordClick(Sender: TObject);
vAR
    VarWord: Variant;// 创建 WORD时所用
begin
    try
        // 1. 建立 OleObject,连接 word97
        VarWord:=CreateOleObject('word.basic');
        // 2. 建立 Word97的新文件
        VarWord.FileNew;
        // 3. 设置 Word97的基本状态
        VarWord.ViewZoom75; //设置显示比例为 75%
        VarWord.ViewPage; //改为页面显示方式
        // 4. 将当前数据控件上的信息发送至 Word97
        // 4.1 发送文号数据
        VarWord.CenterPara; //居中
        Varword.font('宋体 '); //设置字体
        VarWord.FontSize(14); //设置字号
        varword.insert(#13+#13+ ED_WenHao.Text+#13+#13+#13);
        // 4.2 发送标题数据
        VarWord.font('黑体 ');
        VarWord.Fontsize(16);
        VarWord.insert( ED_BiaoTi.text+#13);
        // 4.3 发送收文单位数据
        VarWord.LeftPara; //左对齐
        VarWord.Font('宋体 ');
        VarWord.fontSize(14);
        VarWord.Insert(#13+ ED_ShouWenDanWei.Text+': '+#13);
        // 4.5 发送正文数据
        VarWord.fontSize(14);
        VarWord.Insert( ED_ZhenWen.Text+#13);
       // 4.6 发送发文单位数据
        VarWord.RightPara; //右对齐
        VarWord.fontSize(14);
        VarWord.Insert( ED_FaWenDanWei.Text+#13);
        // 5 最后设置
        VarWord.StartOfdocument; //到文首
        VarWord.AppMaxiMize; //设置窗口最大化
        VarWord.AppShow; //显示应用程序
    except
        showmessage('运行 Microsoft Word 失败! ');
    end; //end of try
end;
//end:数据发送到 word事件
 
 
//开始:窗口关闭事件
procedure TForm1.Btn_QuitClick(Sender: TObject);
begin
        close;
end;
//End:窗口关闭事件
 
end.
// 这是主程序的尾部

 

 

 

!我保证你们看到以下的用法一定爽歪歪了!!!
这可是我三天工作的结果。唔。。。
---看最后终结者office。
--------------------------------
如果你们用的office97的server控件,那么用office2000时就要把server上的控件换掉。
做法:
1。在Componet里打开Install Packages.....
2.去掉borland sample automation server components
3.在project中点input type Library....
4.点add加入office2000的类库。(在Microsoft Office/office目录下的)
5。反正是什么Excel9.olb , Msword9.olb 和那些*.olb的东东,有excel的,word的,等。。。
6。palette page:改为servers(因为以前的office的控件完完了)
7。点install就好了。
这样office2000的问题我想应解决了。(如果你用的是什么word.application或excel.application 的控件的话)。
-----------
我的建议:
    先用上面一的方法,再用comobj对象。
use comobj, excel_tlb; //excel_tlb 是新excel控件的pas文件,你把新控件放在窗体上看它用的哪个.pas就好了,当然下面要把这个控件去掉。因为comobj不用这个控件。只用这个.pas如excel_tlb中的函数。
var xl:variant;
在事件里写:
xl:=createoleobject('Excel.Application');
 
然后打开excel或word录一个宏命令,并打开宏命令考入代码。
----以下是宏录下来的宏。
 workbooks.add
 Range("C5:D7").Select
    Sheets("Sheet2").Select
    ActiveWindow.SelectedSheets.Delete
    Charts.Add
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Sheets("Sheet3").Range("A1")
    ActiveChart.Location Where:=xlLocationAsObject, Name:="Sheet3"
-------
现在把它改为以下:
 xl.workbooks.add;
 xl.workbooks.add('d:"test.xls');
 xl.Range['C5:D7'].Select;
 xl.Sheets['Sheet2'].Select;
 xl.ActiveWindow.SelectedSheets.Delete;
 xl.Charts.Add;
 xl.ActiveChart.ChartType := xlColumnClustered;
 xl.ActiveChart.Location(xlLocationAsObject,'Sheet3');
现在运行一下,我保证你们爽歪歪!
看到规律了吗?
前面加上对象名,()改[],= 改:=,有参数时直接用,后加; 。哈哈,满意了吧,
用office的宏命令可是不用你去想编程的,全是手动。这样少写了一大堆代码。
 
bbcoll 如有不明白的朋友讨论可:[email protected]
 

 

 

、存入
 procedure TForm1.Button1Click(Sender: TObject);
var
 CurST:TStringStream;
 Filename:string;
begin
 if OpenDialog1.Execute then
 begin
   Filename:=OpenDialog1.FileName;
   wordOleContainer.CreateObjectFromFile(FileName, False);
   CurST := tstringstream.create('');
   wordOleContainer.savetostream(CurST);
   ADOTable1.Append;
   ADOTable1.FieldByName('doc').AsVariant:=CurST.datastring;
   ADOTable1.Post;
   CurST.free;
   wordOleContainer.DestroyObject;
 end; }
end;
 
//读出
procedure TForm1.BitBtn1Click(Sender: TObject);
var
    CurItemStream:TStringStream;
   CurItem:Variant;
begin
     CurItem:=aDOTable1.FieldByName('doc').AsVariant;
     CurItemStream:= TStringstream.create(CurItem);
     CurItemStream.position:=0;
    wordOleContainer.loadfromstream(CurItemStream);
     CurItemStream.free;
     wordOleContainer.SaveAsDocument('temp.rtf');
     wordOleContainer.DestroyObject;
     sleep(5000);
     richedit1.lines.loadfromfile('temp.rtf');//此处读出rtf可能是乱码,请查看delphi
   //richedit demo

end;

 

sql server中用image或是text字段都行,可以保存任何文件类型,读出时还可以改名
                      

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Delphi接口的底层实现发布时间:2022-07-18
下一篇:
自动化测试框架:Delphi中&quot;包&quot;的妙用发布时间:2022-07-18
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap