下載app免費(fèi)領(lǐng)取會(huì)員
網(wǎng)友投稿
更多Revit API 里目前好像還沒(méi)有明細(xì)表導(dǎo)出Excel的API
所以導(dǎo)出Excel的策略是,先讀取明細(xì)表,然后再
寫(xiě)到Excel中,讀取可以用
ViewSchedule.GetCellText(SectionType pType, int row, int column);
寫(xiě)入Excel方法就很多了,讀者可以隨意選
下面是一個(gè)簡(jiǎn)單的例子,寫(xiě)入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)歸腿腿教學(xué)網(wǎng)及原創(chuàng)作者所有,未經(jīng)授權(quán),謝絕轉(zhuǎn)載。
上一篇:二次開(kāi)發(fā)教程:Revit開(kāi)發(fā)之判斷參數(shù)是否為項(xiàng)目參數(shù)
下一篇:二次開(kāi)發(fā)教程:Revit開(kāi)發(fā)設(shè)置模型線(xiàn)顏色
推薦專(zhuān)題