插入表格后,如何确定表格中文字的文字样式啊?
大家好,插入一个表格很简单啊,但是如何人为指定表格中的文字字体,比如想插入的表格中的文字均使用“宋体”,这该怎么整呢?我写的代码如下:
public void InsertNow()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
PromptPointResult pr = ed.GetPoint("\nEnter table insertion point: ");
if (pr.Status != PromptStatus.OK) return;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
CreateTable( pr.Value);
trans.Commit();
}
}
public void CreateTable(Point3d ptInsert)
{
Table tb = new Table();
tb.NumRows = 5;
tb.NumColumns = 3;
tb.SetRowHeight(100);
tb.SetColumnWidth(500);
tb.Position = ptInsert;
// 定义一个数组,表示要插入到表格中的内容
string[,] str = new string;
str = "Part No."; str = "Name ";
str = "Material "; str = "1876-1";
str = "Flange"; str = "Perspex";
str = "0985-4"; str = "Bolt";
str = "Steel"; str = "3476-K";
str = "Tile"; str = "Ceramic";
str = "8734-3"; str = "Kean"; str = "Mostly water";
//通过循环把内容插入到表格中
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 3; j++)
{
tb.SetTextHeight(i, j, 50);
tb.SetTextString(i, j, str);
tb.SetAlignment(i, j, CellAlignment.MiddleCenter);
}
}
AppendEntity(tb);
}
public static ObjectId AppendEntity(Entity ent)
{
Database db = HostApplicationServices.WorkingDatabase;
ObjectId entId;
using (Transaction trans = db.TransactionManager.StartTransaction())
{
BlockTable bt = (BlockTable)trans.GetObject(db.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(bt, OpenMode.ForWrite);
entId = btr.AppendEntity(ent);
trans.AddNewlyCreatedDBObject(ent, true);
trans.Commit();
}
return entId;
}
页:
[1]