1. 程式人生 > >合併表格(Table)單元格

合併表格(Table)單元格

Imports ZwSoft.ZwCAD.Runtime
Imports ZwSoft.ZwCAD.ApplicationServices
Imports ZwSoft.ZwCAD.DatabaseServices
Imports ZwSoft.ZwCAD.EditorInput


Public Class Class1
    <CommandMethod("MergeCells")> _
    Public Sub MergeCells()
        Dim ZcDoc As Document = Application.DocumentManager.MdiActiveDocument
        Dim ZcDB As Database = ZcDoc.Database
        Dim ZcEd As Editor = ZcDoc.Editor


        Dim peo As New PromptEntityOptions(vbLf & "Select a table to merge!")
        peo.SetRejectMessage(vbLf & "Must be a table!")
        peo.AddAllowedClass(GetType(Table), True)


        Dim per As PromptEntityResult = ZcEd.GetEntity(peo)
        If per.Status <> PromptStatus.OK Then
            Return
        End If




        Using ZcTrans As Transaction = ZcDB.TransactionManager.StartTransaction()
            Dim tbl As Table = DirectCast(ZcTrans.GetObject(per.ObjectId, OpenMode.ForWrite), Table)
            Dim columns As Int16 = tbl.NumColumns
            tbl.MergeCells(New TableRegion(0, 0, 0, columns - 1))


            ZcTrans.Commit()
        End Using
    End Sub
End Class