快来拿分呀!-------Word问题!(100分)

  • 主题发起人 主题发起人 TrustMe
  • 开始时间 开始时间
T

TrustMe

Unregistered / Unconfirmed
GUEST, unregistred user!
我用 MSWord.TextToTable(ConvertFrom := 2, NumColumns := ColNames.count);
函数传到word里的表格在打印预览时没有线,请问如何才能画上线?
 
odoc.tables.add(Range:=msword.Selection.Range, NumRows:=row+1,NumColumns:=col);
//odoc.tables.add(Range:=oDoc.Range(Start:=0, End:=0), NumRows:=row+1,NumColumns:=col);
vTable:=MSWord.ActiveDocument.Tables.Item(1);
vTable.PreferredWidthType := wdPreferredWidthPercent;
vTable.PreferredWidth := 80;
vTable.Rows.Alignment :=wdAlignRowCenter;
for j:=1 to row+1 do
for i:=1 to col do
begin
if j=1 then
vTable.Cell(j, i).Range.Text :=listview1.Columns[i-1].Caption
else
if i<=listview1.Items.Item[j-2].SubItems.Count+1 then
if i=1 then
vTable.Cell(j, i).Range.Text :=listview1.Items.Item[j-2].Caption
else
vTable.Cell(j, i).Range.Text :=listview1.Items.Item[j-2].SubItems[i-2];
end;
用这个,好好看看吧
 
MSWord:=CreateOLEObject('Word.Application');//连接Word
msword.documents.add;
msword.visible:=true;
msword.ActiveDocument.PageSetup.TopMargin:=2/0.035;
msword.ActiveDocument.PageSetup.BottomMargin := 2/0.035;
msword.ActiveDocument.PageSetup.LeftMargin := 2/0.035;
msword.ActiveDocument.PageSetup.RightMargin := 2/0.035;
msword.activedocument.range(start:=0,end:=0);
msword.Selection.Font.Bold:=wdToggle;
msword.Selection.TypeText(Text:='yubing');
msword.Selection.Font.Bold:=wdToggle;
msword.Selection.Font.Bold:=wdToggle;
msword.Selection.ParagraphFormat.Alignment:=wdAlignParagraphCenter;
msword.ActiveDocument.Range.InsertAfter(Text:='Titleffffffffffffff');
msword.Selection.TypeParagraph;
msword.Selection.ParagraphFormat.Alignment:=wdAlignParagraphJustify;
//插入页眉
If msword.ActiveWindow.View.SplitSpecial <> wdPaneNone Then
msword.ActiveWindow.Panes(2).Close;
//If msword.ActiveWindow.ActivePane.View.Type=wdNormalView Or msword.ActiveWindow.ActivePane.View.Type=wdOutlineView Then
msword.ActiveWindow.ActivePane.View.Type:=wdPrintView;
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
msword.Selection.TypeText(Text:='hjgkj');
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekMainDocument;
//插入页脚
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
If msword.Selection.HeaderFooter.IsHeader = True Then
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageFooter
else
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekCurrentPageHeader;
msword.Selection.TypeText(Text:='safsdfas');
msword.ActiveWindow.ActivePane.View.SeekView:=wdSeekMainDocument;

//MSWord.ActiveDocument.Range.InsertAfter(Text:='Titleffffffffffffff');
odoc:=msword.activedocument;
if (row<>0) and (col<>0) then
begin
odoc.tables.add(Range:=msword.Selection.Range, NumRows:=row+1,NumColumns:=col);
//odoc.tables.add(Range:=oDoc.Range(Start:=0, End:=0), NumRows:=row+1,NumColumns:=col);
vTable:=MSWord.ActiveDocument.Tables.Item(1);
vTable.PreferredWidthType := wdPreferredWidthPercent;
vTable.PreferredWidth := 80;
vTable.Rows.Alignment :=wdAlignRowCenter;
for j:=1 to row+1 do
for i:=1 to col do
begin
if j=1 then
vTable.Cell(j, i).Range.Text :=listview1.Columns[i-1].Caption
else
if i<=listview1.Items.Item[j-2].SubItems.Count+1 then
if i=1 then
vTable.Cell(j, i).Range.Text :=listview1.Items.Item[j-2].Caption
else
vTable.Cell(j, i).Range.Text :=listview1.Items.Item[j-2].SubItems[i-2];
end;
end;
//MSWord.Selection.Tables(1).Select;
//MSWord.Selection.Tables.PreferredWidthType := wdPreferredWidthPercent;
//MSWord.Selection.Tables.PreferredWidth := 80;
//MSWord.Selection.Columns.PreferredWidth:=CentimetersToPoints(3.2);

//msword.Selection.MoveDown(Unit:=wdLine, Count:=row+1);
msword.Selection.GoTo(What:=wdGoToLine, Which:=wdGoToFirst, Count:=row+3, Name:='');
msword.Selection.TypeText(Text:='yubing');
MSWord.Selection.ParagraphFormat.Alignment:=wdAlignParagraphRight;


MSWord.ActiveDocument.Range.InsertAfter(Text:='ssdd');

MSword.ActiveDocument.saveas(FileName:=filename,FileFormat:=wdFormatDocument,
LockComments:=False, Password:='', AddToRecentFiles:=True, WritePassword:='',
ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False,
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False);
MSword.ActiveDocument.close;
msword.quit;
 
to yubing8:
谢谢!
关于这个问题,我还开了一个贴子,你去那里,我把分(50)都加给你。
http://www.delphibbs.com/delphibbs/dispq.asp?lid=2130278
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
489
import
I
D
回复
0
查看
2K
DelphiTeacher的专栏
D
后退
顶部