在delphi中如何用ole打开一个已存在的word文档,并修改某个书签???(50分)

  • 主题发起人 主题发起人 hnhjg
  • 开始时间 开始时间
H

hnhjg

Unregistered / Unconfirmed
GUEST, unregistred user!
请各位大虾帮帮忙。
 
在word里做个宏看看不就得了
 
这是我用BCB调用Excel 例子。供参考

void TFormExport1::WriteExcelPL1()
{
String sSQL;
sSQL=" SELECT Pull_List.Part_No As Part_No, Material_List.Description as Description, Pull_List.Req_qty as Req_Qty, Material_List.Unit as Unit, Pull_List.Contract_No as Contract_NO, Pull_List.PO_NO as PO_NO FROM Open_Order RIGHT JOIN (Pull_List LEFT JOIN Material_List ON Pull_List.Part_No = Material_List.Part_NO) ON (Open_Order.Part_No = Pull_List.Part_No) AND (Open_Order.PO_No = Pull_List.PO_NO) AND (Open_Order.Contract_No = Pull_List.Contract_No) " ;
sSQL=sSQL+" WHERE ((Pull_List.Pull_List_No)=" +sPull_List_No+ ") ORDER BY Pull_List.Part_No ";
DM->Query1->Close();
DM->Query1->RequestLive=false;
DM->Query1->SQL->Clear();
DM->Query1->SQL->Add(sSQL);
DM->Query1->Prepare();
DM->Query1->Open();
Variant Ex,Wb,Sh1;
Ex=Variant::CreateObject("Excel.Application");
Ex.PGet("WorkBooks").PR("Add");
Wb=Ex.PGet("ActiveWorkBook");
Sh1=Wb.PGet("ActiveSheet");
Ex.PGet("ActiveWorkBook").PGet("ActiveSheet").PSet("Name","Pull List1 "+sPull_List_No) ;
Sh1.PGet("Cells",1,1).PSet("Value","Pull_List:");
Sh1.PGet("Cells",1,2).PSet("Value",sPull_List_No);

Sh1.PGet("Cells",2,1).PSet("Value","S/NO");
Sh1.PGet("Cells",2,2).PSet("Value","Material");
Sh1.PGet("Cells",2,3).PSet("Value","Description");
Sh1.PGet("Cells",2,4).PSet("Value","Req Qty");
Sh1.PGet("Cells",2,5).PSet("Value","UOM");
Sh1.PGet("Cells",2,6).PSet("Value","C/NO");
Sh1.PGet("Cells",2,7).PSet("Value","PO/NO");

DM->Query1->First();
for (int i=1;i<=DM->Query1->RecordCount;i++)
{
Sh1.PGet("Cells",i+2,1).PSet("Value",i);
Sh1.PGet("Cells",i+2,2).PSet("Value",DM->Query1->FieldByName("Part_No")->AsString);
Sh1.PGet("Cells",i+2,3).PSet("Value",DM->Query1->FieldByName("Description")->AsString);
Sh1.PGet("Cells",i+2,4).PSet("Value",DM->Query1->FieldByName("Req_Qty")->AsInteger);
Sh1.PGet("Cells",i+2,5).PSet("Value",DM->Query1->FieldByName("UNIT")->AsString);
Sh1.PGet("Cells",i+2,6).PSet("Value",DM->Query1->FieldByName("Contract_No")->AsString);
Sh1.PGet("Cells",i+2,7).PSet("Value",DM->Query1->FieldByName("Po_NO")->AsString);
DM->Query1->Next();
}
DM->Query1->Close();
// Ex.PSet("Visible", "true");
Wb.PR("SaveAs",SaveDialog1->FileName);
Ex.PR("Quit");
Ex=Unassigned;
}
 
我知道!EMAIL:cdyxl@163.com
 
看看这个
http://www.delphibbs.com/delphibbs/dispq.asp?lid=759711
 
后退
顶部