下载app免费领取会员
Revit API 里目前好像还没有明细表导出Excel的API
所以导出Excel的策略是,先读取明细表,然后再
写到Excel中,读取可以用
ViewSchedule.GetCellText(SectionType pType, int row, int column);
写入Excel方法就很多了,读者可以随意选
下面是一个简单的例子,写入Excel用的是NPOI
关键代码如下:
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();
}
本文版权归腿腿教学网及原创作者所有,未经授权,谢绝转载。