明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1565|回复: 5

[表格] 求教:如何合并单元格

[复制链接]
发表于 2014-10-21 20:18 | 显示全部楼层 |阅读模式
初学C#开发AutoCAD,想使用MergeCells函数对“表格”图元的单元格进行合并,请问应该如何做?
发表于 2014-10-23 16:30 | 显示全部楼层
需要定制可联系我,qq:379539186
发表于 2020-2-8 11:54 | 显示全部楼层
using Autodesk.AutoCAD.ApplicationServices;

using Autodesk.AutoCAD.DatabaseServices;

using Autodesk.AutoCAD.EditorInput;

using Autodesk.AutoCAD.Runtime;



namespace TableStyleEditing

{

  public class Commands

  {

    [CommandMethod("UTT")]

    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[0];



          // 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();

      }

    }

  }

}
发表于 2020-2-8 11:55 | 显示全部楼层
     var row = table.Rows[0];是取的第一行的区域,如何定义何意区域
发表于 2020-2-8 14:04 | 显示全部楼层
Tb.MergeCells(ROWS(1))'行合并;   Tb.MergeCells(Tb.Columns(2))'列合并;可是任意的单位格区域怎么定义呢
发表于 2020-2-14 20:50 | 显示全部楼层
protected CellRange(
    Table table,
    int topRow,
    int leftColumn,
    int bottomRow,
    int rightColumn
);
public virtual void MergeCells(
    CellRange range
);
传入一个CellRange对象,要合并的行的收尾索引和要合并列的首尾索引。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-4-27 06:16 , Processed in 0.325190 second(s), 27 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表