第一行默认是标题,可设置行【RowType】进行设置类型
Document doc = Application.DocumentManager.MdiActiveDocument;
using (Transaction tr = doc.TransactionManager.StartOpenCloseTransaction())
{
BlockTable bt = tr.GetObject(doc.Database.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
Table table = new Table();
//设置表格大小(必须先创建表格类型再设置表格属性)
table.SetSize(5, 3);
//设置行高
table.SetRowHeight(50);
table.SetColumnWidth(200);
// 设置表格的行数和列数
// 设置表格的位置和大小
table.Position = new Autodesk.AutoCAD.Geometry.Point3d(0, 0, 0);
//从(2,0)单元格合并至(2,1)单元格,行列下表从0开始
var cellRange = CellRange.Create(table, 2, 0, 2, 1);
table.MergeCells(cellRange);
btr.AppendEntity(table);
tr.AddNewlyCreatedDBObject(table,true);
tr.Commit();
}