下載app免費領(lǐng)取會員
Revit API 里目前好像還沒有明細表導出Excel的API
所以導出Excel的策略是,先讀取明細表,然后再
寫到Excel中,讀取可以用
ViewSchedule.GetCellText(SectionType pType, int row, int column);
寫入Excel方法就很多了,讀者可以隨意選
下面是一個簡單的例子,寫入Excel用的是NPOI
關(guān)鍵代碼如下:
Document doc = commandData.Application.ActiveUIDocument.Document;
ViewSchedule v = doc.ActiveView as ViewSchedule;
TableData td = v.GetTableData();
TableSectionData tdb = td.GetSectionData(SectionType.Header);
string head = v.GetCellText(SectionType.Header, 0, 0);
TableSectionData tdd = td.GetSectionData(SectionType.Body);
int c = tdd.NumberOfColumns;
int r = tdd.NumberOfRows;
HSSFWorkbook work = new HSSFWorkbook();
ISheet sheet = work.CreateSheet("mysheet");
for (int i = 0; i < r; i++)
{
IRow row = sheet.CreateRow(i);
for (int j = 0; j < c; j++)
{
Autodesk.Revit.DB.CellType ctype = tdd.GetCellType(i, j);
ICell cell = row.CreateCell(j);
string str = v.GetCellText(SectionType.Body, i, j);
cell.SetCellValue(str);
}
}
using (FileStream fs = File.Create("d:\\excel.xls"))
{
work.Write(fs);
fs.Close();
}
本文版權(quán)歸腿腿教學網(wǎng)及原創(chuàng)作者所有,未經(jīng)授權(quán),謝絕轉(zhuǎn)載。
上一篇:二次開發(fā)教程:Revit開發(fā)之判斷參數(shù)是否為項目參數(shù)