蒹葭_Keirll 发表于 2014-10-21 20:18:39

求教:如何合并单元格

初学C#开发AutoCAD,想使用MergeCells函数对“表格”图元的单元格进行合并,请问应该如何做?

liuxu042 发表于 2014-10-23 16:30:45

需要定制可联系我,qq:379539186

wz0406 发表于 2020-2-8 11:54:28

using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;



namespace TableStyleEditing

{

public class Commands

{

   

    public void UnmergeTableTitle()

    {

      var doc = Application.DocumentManager.MdiActiveDocument;

      if (doc == null) return;

      var ed = doc.Editor;



      // Select a table



      var peo = new PromptEntityOptions("\nSelect table");

      peo.SetRejectMessage("\nMust be a table.");

      peo.AddAllowedClass(typeof(Table), false);

      var per = ed.GetEntity(peo);

      if (per.Status != PromptStatus.OK)

      return;



      using (var tr = doc.TransactionManager.StartTransaction())

      {

      var table = tr.GetObject(per.ObjectId, OpenMode.ForWrite) as Table;

      if (table != null)

      {

          // Get the first row



          var row = table.Rows;



          // If it is merged, unmerge it



          if (row.IsMerged.HasValue && row.IsMerged.Value)

          {

            table.UnmergeCells(row);

            ed.WriteMessage("\nUnmerged first row.");

          }

          else

          {

            ed.WriteMessage("\nFirst row is not merged.");

          }

      }

      tr.Commit();

      }

    }

}

}

wz0406 发表于 2020-2-8 11:55:42

   var row = table.Rows;是取的第一行的区域,如何定义何意区域

wz0406 发表于 2020-2-8 14:04:56

Tb.MergeCells(ROWS(1))'行合并;   Tb.MergeCells(Tb.Columns(2))'列合并;可是任意的单位格区域怎么定义呢

LL_Zz 发表于 2020-2-14 20:50:30

protected CellRange(
    Table table,
    int topRow,
    int leftColumn,
    int bottomRow,
    int rightColumn
);
public virtual void MergeCells(
    CellRange range
);
传入一个CellRange对象,要合并的行的收尾索引和要合并列的首尾索引。
页: [1]
查看完整版本: 求教:如何合并单元格