使用vb6将表创建为Word [英] Create Table into a Word using vb6

查看:103
本文介绍了使用vb6将表创建为Word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在创建一个将在Word文档中编写的项目,我想添加布局,我创建了一个包含2列& 1行.现在我的问题是,如何在第一个表的单元格内创建另一个表.

关于这个问题,有人可以帮忙吗?

这是我的代码:

Hi, I''m creating a project that will write in word document, i want to add layout, i create a table with 2 columns & 1 rows. Now my problem is, how can i create another table in inside the cell of my first table.

Anybody can help please regarding this problem???

here is my code:

Public Sub WriteFO(RecordHandler As ADODB.Recordset, wdPath As String)
    
    If Dir(wdPath, vbDirectory) <> "" Then
        ''ctr = CountExcelRows(ExcelPath) + 1
    Else
       FileCopy App.Path & "\tmp\Temp.doc", wdPath
    End If
    
    Dim ImageFilename As Variant

    ''Word Declaration
    Dim wordApp As Word.Application
    Dim wordDoc As Word.Document
    Dim wordDoc1 As Word.Document
    ''Initialize Word
    Set wordApp = New Word.Application ''CreateObject("Word.Application")
    Set wordDoc = wordApp.Documents.Open(wdPath, , True)
    
    Do While Not (RecordHandler.EOF)
        ''Download Images
        ImageFilename = Split(RecordHandler.Fields("ILink"), "/")
        DownloadURL RecordHandler.Fields("ILink"), My & "\rsc\" & ImageFilename(UBound(ImageFilename))
        
        ''Insert Details
        Dim wordTable As Word.Table
        Dim wordTable1 As Word.Table
        Set wordTable = wordDoc.Tables.Add(wordDoc.Bookmarks.Item("\endofdoc").Range, 1, 2)
        Set wordTable1 = wordTable.Tables.Add(wordDoc.Tables, 2, 1)
        wordTable.Range.ParagraphFormat.SpaceAfter = 6
        
        wordTable.Cell(1, 1).Range.InlineShapes.AddPicture My & "\rsc\" & ImageFilename(UBound(ImageFilename)), False, True, wordTable.Range
        ''wordTable.Cell(1, 2).Range.Text = RecordHandler.Fields("ILink")
        wordTable.Cell(1, 2).Range.Tables.Add wordTable1.Range, 2, 1
        ''wordTable.Cell(1, 2).Range.Tables.Add wordTable1.Range, 3, 1
        
        ''Insert New Table
        Dim wordPar2 As Word.Paragraph
        Set wordPar2 = wordDoc.Content.Paragraphs.Add
        wordPar2.Range.Text = vbNewLine
        ''wordPar2.Range.Font.Italic = True
        wordPar2.Range.InsertParagraphAfter
        
        ''Colum Resize
        wordTable.Columns.Item(1).AutoFit
        wordTable.Columns.Item(2).AutoFit
        ''Hide Borders
        Hideborders wordTable
        RecordHandler.MoveNext
    Loop
    
    wordDoc.SaveAs "C:\Sample.doc"
    wordDoc.Close True
    wordApp.Quit True
    
    Set wordDoc = Nothing
    Set wordApp = Nothing
End Sub



任何想法都值得赞赏!



any idea appreciated!!!

推荐答案

简单地创建一个包含所有值的字符串并将其全部一次插入会更容易.这要快得多.您可以使用制表符char(vbTab)分隔每个值,并使用换行符(vbNewLine)分隔每一行.然后将该字符串作为新书签插入,选择该字符串,然后使用ConvertToTable将其转换为表.

http://msdn.microsoft.com/en-us/library/aa171893%28v = office.11​​%29.aspx [ ^ ]

祝你好运!
It is way easier to simply create a string of all the values and insert them all at once. This is much faster. You separate each value using a tab char (vbTab) and each line with a new line (vbNewLine). Then insert that string as a new bookmark, select that and convert it to a table using ConvertToTable.

http://msdn.microsoft.com/en-us/library/aa171893%28v=office.11%29.aspx[^]

Good luck!


这篇关于使用vb6将表创建为Word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆