word合并表格,第一列合并报错“集合所要求的成员不存在”(50分)

  • 主题发起人 lingmao3
  • 开始时间
L

lingmao3

Unregistered / Unconfirmed
GUEST, unregistred user!
myRange:=vDoc.Range(vDoc.Tables.Item(2).Cell(1,1).Range.Start,vDoc.Tables.Item(2).Cell(2,1).Range.End);
myRange.Cells.Merge;
报错“集合所要求的成员不存在”

从第二列开始,合并都没问题了,全部OK
myRange:=vDoc.Range(vDoc.Tables.Item(2).Cell(1,2).Range.Start,vDoc.Tables.Item(2).Cell(2,2).Range.End);
myRange.Cells.Merge;

myRange:=vDoc.Range(vDoc.Tables.Item(2).Cell(1,3).Range.Start,vDoc.Tables.Item(2).Cell(2,3).Range.End);
myRange.Cells.Merge;
 
太难 没做过 但很期待你成功~
 
是不是应该, 反过来合并
 
求教中.....
 
{
Word 插入表格,
拆分、合并单元格
}
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls
, Word2000
, OleServer
;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1 : TForm1;
Word : TWordApplication;
implementation

{$R *.dfm}

procedure AddTable(WordApp: TWordApplication;ColCount,RowCount:integer);
var
a, b : OleVariant;
begin
a := WdStory;
b := wdMove;
WordApp.Selection.EndKey(a, b);//移动到文档最后
a := wdWord9TableBehavior;
b := wdAutoFitFixed; //加一个5行4列的表格
WordApp.ActiveDocument.Tables.Add(WordApp.Selection.Range, ColCount,RowCount, a, b);

end;

procedure TForm1.Button1Click(Sender: TObject);
var

OleX, RangeStart, RangeEnd, template, NewTemplate, DocType, Vis: OleVariant;
vTable : Variant;

begin
Word := TWordApplication.Create(Application);
Word.ConnectKind := ckRunningOrNew;
newTemplate := False;
vis := True;
DocType := 0;
Template := '';
Word.Documents.Add(Template, NewTemplate, DocType, Vis);
Word.ActiveWindow.Visible := True;
AddTable(Word,5,4);
try
VTable := Word.ActiveDocument.Tables.Item(Word.ActiveDocument.Tables.Count);
except
VTable := Null;
end;
if not VarisNull(VTable) then
begin
// VTable.AutoFitBehavior(wdAutoFitFixed); //固定表格的列宽
VTable.Rows.Item(VTable.Rows.Count).Select;

OleX := 1;
Word.Selection.InsertRowsBelow(OleX);
VTable.Rows.Item(VTable.Rows.Count).Select;
Word.Selection.Cells.Merge; //合并选中区域

VTable.Cell(VTable.Rows.Count, 1).Split(1, 5); //最后一行拆分成5列
RangeStart := VTable.cell(VTable.Rows.Count, 4).Range.Start;
RangeEnd := VTable.cell(VTable.Rows.Count, 5).Range.end;
Word.ActiveDocument.Range(RangeStart, RangeEnd).Select; //选择第一行的前两列
Word.Selection.Cells.Merge; //合并选中区域

RangeStart := VTable.cell(1, 1).Range.Start;
RangeEnd := VTable.cell(1, 2).Range.end;
Word.ActiveDocument.Range(RangeStart, RangeEnd).Select; //选择第一行的前两列
Word.Selection.Cells.Merge; //合并选中区域
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
if Word <> nil then
FreeAndNil(Word);
end;

end.
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
636
import
I
I
回复
0
查看
734
import
I
I
回复
0
查看
606
import
I
顶部