- 积分
- 603
- 明经币
- 个
- 注册时间
- 2011-7-31
- 在线时间
- 小时
- 威望
-
- 金钱
- 个
- 贡献
-
- 激情
-
|
大家好,插入一个表格很简单啊,但是如何人为指定表格中的文字字体,比如想插入的表格中的文字均使用“宋体”,这该怎么整呢?
我写的代码如下:- [CommandMethod("InsertTable")]
- 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[5, 3];
- str[0, 0] = "Part No."; str[0, 1] = "Name ";
- str[0, 2] = "Material "; str[1, 0] = "1876-1";
- str[1, 1] = "Flange"; str[1, 2] = "Perspex";
- str[2, 0] = "0985-4"; str[2, 1] = "Bolt";
- str[2, 2] = "Steel"; str[3, 0] = "3476-K";
- str[3, 1] = "Tile"; str[3, 2] = "Ceramic";
- str[4, 0] = "8734-3"; str[4, 1] = "Kean"; str[4, 2] = "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[i, j]);
- 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[BlockTableRecord.ModelSpace], OpenMode.ForWrite);
- entId = btr.AppendEntity(ent);
- trans.AddNewlyCreatedDBObject(ent, true);
- trans.Commit();
- }
- return entId;
- }
|
|