有几个表格方面的资料
Creating table using the Table.InsertColumns and Table.InsertRows is quite tricky and below are certain scenarios that can be useful :
Scenario 1: Using only table.InsertColumns :
Along with the specified number of columns, a single default row(without cells) is created at row index 0.
Scenario 2: Using only table.InsertRows :
Along with the specified number of rows,a single default column is created (with cells) at column index 0.
for example, table.InsertRows(0, 5, 3); creates table as shown below:
Scenario 3: Using index to create rows or columns :
Here, the method is table.InsertRows(int row,double height,int rows)
int row = row index
double height = rows(exculding default row)
int rows = number of rows inserted
As in the above example, table.InsertRows(0, 5, 3); creates a table with 4 rows( 3 + 1 default row) and 1 column at index 0.
Since first parameter(index) is 0, every row is inserted at position 0 and pushes the previously inserted row(if any) below. So we can find the default row at the bottom most position after creation.
Scenario 4: We can use table.InsertRows in a loop to create rows of varying height :
Rows of varying height can be created as follows :
- List<double> rowHeight = new List<double>();
- rowHeight.Add(10);
- rowHeight.Add(20);
- rowHeight.Add(30);
- int nRows = rowHeight.Count;
- for (int iRow = 0; iRow < nRows; iRow++)
- {
- table.InsertRows(0, rowHeight[iRow], 1);
- }
NOTE : the default row and column can be deleted if not required using DeleteColumns and DeleteRows API
下面代码查询每个CELL的STYLES
- [CommandMethod("GetRowType")]
- public void GetRowType()
- {
- Document doc = Application.DocumentManager.MdiActiveDocument;
- Database db = doc.Database;
- Editor ed = doc.Editor;
- PromptEntityOptions peo = new PromptEntityOptions("\nSelect Table: ");
- peo.SetRejectMessage("\nInvalid selection...");
- peo.AddAllowedClass(typeof(Table), true);
- PromptEntityResult per = ed.GetEntity(peo);
- if (per.Status != PromptStatus.OK)
- return;
- using (Transaction Tx = db.TransactionManager.StartTransaction())
- {
- Table table = Tx.GetObject(per.ObjectId, OpenMode.ForRead) as Table;
- for (int row = 0; row < table.Rows.Count; row++)
- {
- ed.WriteMessage("\nRow[{0}]: {1}", row, table.Cells[row, -1].Style);
- }
- Tx.Commit();
- }
- }
|