[表格] 求教:如何合并单元格
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();
}
}
}
}
页:
[1]