684 lines
31 KiB
C#
684 lines
31 KiB
C#
using Autodesk.Revit.DB;
|
|
using Autodesk.Revit.DB.Architecture;
|
|
using Autodesk.Revit.DB.Electrical;
|
|
using Autodesk.Revit.UI;
|
|
using Autodesk.Revit.UI.Selection;
|
|
using OfficeOpenXml;
|
|
using OfficeOpenXml.Style;
|
|
using RookieStation.ProjectConfig;
|
|
using RookieStation.Statistics.Models;
|
|
using RookieStation.Utils;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Data.Common;
|
|
using System.Data.SQLite;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Forms;
|
|
|
|
namespace RookieStation.Statistics.ExecuteCmds
|
|
{
|
|
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
|
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
|
internal class CmdExportBudgetInventory : IExternalCommand
|
|
{
|
|
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
|
|
{
|
|
UIApplication uiapp = commandData.Application;
|
|
UIDocument uidoc = uiapp.ActiveUIDocument;
|
|
Autodesk.Revit.ApplicationServices.Application app = uiapp.Application;
|
|
Document doc = uidoc.Document;
|
|
DocumentSet docset = uiapp.Application.Documents;
|
|
SaveFileDialog sfd = new SaveFileDialog()
|
|
{
|
|
Filter = "Excel文件|*.xlsx",
|
|
FileName = $"{UserConstant.SchoolName}菜鸟驿站工程预算清单"
|
|
};
|
|
string destinationFileName = string.Empty;
|
|
if (sfd.ShowDialog() == DialogResult.OK)
|
|
{
|
|
destinationFileName = sfd.FileName;
|
|
}
|
|
if (destinationFileName == string.Empty)
|
|
{
|
|
return Result.Cancelled;
|
|
}
|
|
//实例化SQL辅助类
|
|
var sql = SQLiteUtil.GetInstance();
|
|
sql.CreateDb(UserConstant.DbFolder + "Inventory.db");
|
|
//var tablecontent = sql.QueryTable("菜鸟驿站工程预算清单");
|
|
//string[] values = new string[] { "", "装饰装修项目", "Null", "测试", "测试描述", "m2", "Area" };
|
|
//sql.InsertValue("'CaiNiaoInventory'", values);
|
|
|
|
var tableRows = sql.QueryTable("CaiNiaoInventory");
|
|
var items = GetQuantity(doc, tableRows);
|
|
sql.CloseConncetion();
|
|
var itemGroups = items.GroupBy(i => i.RootCategory).Select(s => s.Where(q => q.Quantity != 0.0));//分成三组
|
|
|
|
using (ExcelPackage package = new ExcelPackage())
|
|
{
|
|
ExcelWorksheet sheet = CreateTableHeader(doc, package);
|
|
int row = 4;
|
|
List<int> rows = new List<int>();
|
|
for (int i = 0; i < itemGroups.Count(); i++)
|
|
{
|
|
int startRow = row + 1;//用于根分类下一行,做汇总计算的起始行
|
|
|
|
#region 根分类
|
|
|
|
var rootItem = itemGroups.ElementAt(i);
|
|
if (rootItem.Count() == 0)
|
|
{
|
|
continue;
|
|
}
|
|
sheet.Cells[row, 1].Value = NumberToChineseDigital(i + 1);
|
|
sheet.Cells[row, 2].Value = rootItem.FirstOrDefault().RootCategory;
|
|
using (var range = sheet.Cells[row, 1, row, 10])
|
|
{
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.Font.Bold = true;
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 10;
|
|
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
|
|
range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.DarkGray);
|
|
range.Style.Border.BorderAround(ExcelBorderStyle.Thin);
|
|
}
|
|
|
|
row += 1;
|
|
|
|
#endregion 根分类
|
|
|
|
var subGroupys = rootItem.GroupBy(s => s.SubCategory);//装饰装修分成六组
|
|
for (int j = 0; j < subGroupys.Count(); j++)//每个子分类
|
|
{
|
|
#region 子分类
|
|
|
|
int subStartRow = row;
|
|
//子分类标题
|
|
if (subGroupys.ElementAt(j).ElementAt(0).SubCategory != "")
|
|
{
|
|
sheet.Cells[row, 1].Value = NumberToChar(j + 1);
|
|
sheet.Cells[row, 2].Value = subGroupys.ElementAt(j).Key;
|
|
sheet.Cells[row, 3].Formula = $"SUM({sheet.Cells[subStartRow + 1, 9].Address}:{sheet.Cells[subStartRow + subGroupys.ElementAt(j).Count(), 9].Address})";
|
|
sheet.Cells[row, 3].Style.Numberformat.Format = "#,##0.00";
|
|
sheet.Cells[row, 3].Style.Font.Color.SetColor(System.Drawing.Color.Red);
|
|
using (var range = sheet.Cells[row, 1, row, 10])
|
|
{
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.Font.Bold = true;
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 10;
|
|
range.Style.Fill.PatternType = ExcelFillStyle.Solid;
|
|
range.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.LightGray);
|
|
range.Style.Border.BorderAround(ExcelBorderStyle.Thin);
|
|
}
|
|
row += 1;
|
|
}
|
|
|
|
#endregion 子分类
|
|
|
|
#region 子项
|
|
|
|
for (int k = 0; k < subGroupys.ElementAt(j).Count(); k++)
|
|
{
|
|
var subitem = subGroupys.ElementAt(j).ElementAt(k);
|
|
sheet.Cells[row, 1].Value = k + 1;
|
|
sheet.Cells[row, 2].Value = subitem.ItemName;
|
|
sheet.Cells[row, 3].Value = subitem.Description;
|
|
sheet.Cells[row, 4].Value = subitem.Unit;
|
|
sheet.Cells[row, 5].Value = subitem.Quantity;
|
|
sheet.Cells[row, 5].Style.Font.Color.SetColor(System.Drawing.Color.Red);
|
|
if (subitem.Unit == "套" || subitem.Unit == "个")
|
|
{
|
|
sheet.Cells[row, 5].Style.Numberformat.Format = "0";
|
|
}
|
|
else
|
|
{
|
|
sheet.Cells[row, 5].Style.Numberformat.Format = "0.00";
|
|
}
|
|
sheet.Cells[row, 8].Formula = $"SUM({sheet.Cells[row, 6].Address}:{sheet.Cells[row, 6].Address})";
|
|
sheet.Cells[row, 9].Formula = $"{sheet.Cells[row, 5].Address}*{sheet.Cells[row, 8].Address}";
|
|
sheet.Cells[row, 10].Value = subitem.Remarks;
|
|
using (var range = sheet.Cells[row, 1, row, 10])
|
|
{
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 10;
|
|
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
|
}
|
|
using (var range = sheet.Cells[row, 6, row, 9])
|
|
{
|
|
range.Style.Numberformat.Format = "#,##0.00";
|
|
}
|
|
row += 1;
|
|
}
|
|
//if (subGroupys.ElementAt(j).ElementAt(0).SubCategory != null)
|
|
//{
|
|
// sheet.Cells[row, 1, row, 8].Merge = true;
|
|
// sheet.Cells[row, 1].Value = rootItem.FirstOrDefault().SubCategory + "合计";
|
|
// sheet.Cells[row, 9].Formula = string.Format("=SUM({0}:{1})", sheet.Cells[startrow, 9].Address, sheet.Cells[row - 1, 9].Address);
|
|
|
|
// using (var range = sheet.Cells[row, 1, row, 10])
|
|
// {
|
|
// range.Style.Font.Name = "宋体";
|
|
// range.Style.Font.Bold = true;
|
|
// range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
// range.Style.Font.Size = 10;
|
|
// range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
|
// range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
|
// range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
|
// range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
|
// }
|
|
//}
|
|
|
|
#endregion 子项
|
|
|
|
//var sg = subGroupys.ElementAt(j);
|
|
|
|
//sheet.Cells[5, 1].Value = NumberToChar(j + 1);
|
|
}
|
|
|
|
#region 合计项
|
|
|
|
sheet.Cells[row, 1, row, 8].Merge = true;
|
|
sheet.Cells[row, 1].Value = rootItem.FirstOrDefault().RootCategory + "合计";
|
|
sheet.Cells[row, 9].Formula = $"SUM({sheet.Cells[startRow, 9].Address}:{sheet.Cells[row - 1, 9].Address})";
|
|
sheet.Cells[row, 9].Style.Numberformat.Format = "#,##0.00";
|
|
rows.Add(row);//记录汇总的行号
|
|
using (var range = sheet.Cells[row, 1, row, 10])
|
|
{
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.Font.Bold = true;
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 10;
|
|
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
|
}
|
|
row += 1;
|
|
|
|
#endregion 合计项
|
|
}
|
|
|
|
#region 预算总价
|
|
|
|
sheet.Cells[row, 1, row, 8].Merge = true;
|
|
sheet.Cells[row, 1].Value = "预算总价(一+二+三)";
|
|
string formula = $"SUM({sheet.Cells[rows[0], 9].Address}";
|
|
|
|
sheet.Cells[2, 4].Formula = $"{sheet.Cells[row, 9].Address}";//表头预算总价合计
|
|
|
|
for (int i = 1; i < rows.Count; i++)
|
|
{
|
|
formula += "+" + sheet.Cells[rows[1], 9].Address;
|
|
if (i == rows.Count - 1)
|
|
{
|
|
formula += "+" + sheet.Cells[rows[1], 9].Address + ")";
|
|
}
|
|
}
|
|
sheet.Cells[row, 9].Formula = formula;
|
|
sheet.Cells[row, 9].Style.Numberformat.Format = "#,##0.00";
|
|
using (var range = sheet.Cells[row, 1, row, 10])
|
|
{
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.Font.Bold = true;
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 10;
|
|
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
|
}
|
|
row += 1;
|
|
|
|
#endregion 预算总价
|
|
|
|
sheet.Cells[row, 1, row, 8].Merge = true;
|
|
sheet.Cells[row, 1].Value = "※本清单根据施工图生成,仅作为财务模型预算参考,不包含拆除、户外、空调、消防等其他专业预算;";
|
|
using (var range = sheet.Cells[row, 1, row, 10])
|
|
{
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Left;
|
|
range.Style.Font.Size = 10;
|
|
}
|
|
using (var range = sheet.Cells[sheet.Dimension.Start.Row, sheet.Dimension.Start.Column, sheet.Dimension.End.Row, sheet.Dimension.End.Column])
|
|
{
|
|
range.AutoFitColumns();
|
|
}
|
|
sheet.Calculate();
|
|
using (Stream stream = new FileStream(destinationFileName, FileMode.Create))
|
|
{
|
|
package.SaveAs(stream);
|
|
}
|
|
}
|
|
System.Diagnostics.Process.Start(destinationFileName);
|
|
|
|
return Result.Succeeded;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数字转汉字
|
|
/// </summary>
|
|
/// <param item.ItemName="n"></param>
|
|
/// <returns></returns>
|
|
private string NumberToChineseDigital(int n)
|
|
{
|
|
switch (n)
|
|
{
|
|
case 1:
|
|
return "一";
|
|
|
|
case 2:
|
|
return "二";
|
|
|
|
case 3:
|
|
return "三";
|
|
|
|
case 4:
|
|
return "四";
|
|
|
|
default:
|
|
return "无";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数字转字母
|
|
/// </summary>
|
|
/// <param item.ItemName="n"></param>
|
|
/// <returns></returns>
|
|
private string NumberToChar(int n)
|
|
{
|
|
switch (n)
|
|
{
|
|
case 1:
|
|
return "A";
|
|
|
|
case 2:
|
|
return "B";
|
|
|
|
case 3:
|
|
return "C";
|
|
|
|
case 4:
|
|
return "D";
|
|
|
|
case 5:
|
|
return "E";
|
|
|
|
case 6:
|
|
return "F";
|
|
|
|
case 7:
|
|
return "G";
|
|
|
|
default:
|
|
return "Invalid";
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取量
|
|
/// </summary>
|
|
/// <param item.ItemName="doc"></param>
|
|
/// <param item.ItemName="li"></param>
|
|
/// <returns></returns>
|
|
private static List<SubItem> GetQuantity(Document doc, List<string[]> li)
|
|
{
|
|
double similarity = 0.8;
|
|
List<SubItem> items = new List<SubItem>();
|
|
for (int i = 0; i < li.Count; i++)
|
|
{
|
|
SubItem item = new SubItem()
|
|
{
|
|
RootCategory = li[i][1],
|
|
SubCategory = li[i][2],
|
|
ItemName = li[i][3],
|
|
Description = li[i][4],
|
|
Unit = li[i][5],
|
|
};
|
|
string revitType = li[i][6].ToLower();
|
|
if (revitType == "wall")
|
|
{
|
|
double wallTotalArea = 0.0;
|
|
double wallTotalLength = 0.0;
|
|
var walls = new FilteredElementCollector(doc).OfClass(typeof(Wall)).Cast<Wall>();
|
|
|
|
foreach (var wall in walls)
|
|
{
|
|
if (CommonUtils.levenshtein(item.ItemName, wall.Name) > similarity)
|
|
{
|
|
if (item.Unit == "m" && wall.Name.Contains("踢脚线"))
|
|
{
|
|
item.Remarks += wall.Name + "\r\n";
|
|
wallTotalLength += wall.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
|
|
}
|
|
else if (item.Unit == "m2" && !wall.Name.Contains("踢脚线"))
|
|
{
|
|
item.Remarks += wall.Name + "\r\n";
|
|
wallTotalArea += wall.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
|
|
}
|
|
}
|
|
}
|
|
|
|
if (wallTotalArea == 0.0)
|
|
{
|
|
item.Quantity = RsRevitUtils.ConvertFeetToMetre(wallTotalLength);
|
|
}
|
|
else
|
|
{
|
|
item.Quantity = RsRevitUtils.ConvertSquareFeetToSquareMetre(wallTotalArea);
|
|
}
|
|
items.Add(item);
|
|
}
|
|
else if (revitType == "floor")
|
|
{
|
|
double floorTotalArea = 0.0;
|
|
var floors = new FilteredElementCollector(doc).OfClass(typeof(Floor)).Cast<Floor>();
|
|
|
|
foreach (var floor in floors)
|
|
{
|
|
//if (item.ItemName.Intersect(floor.Name).Count() >= 3)
|
|
//{
|
|
//}
|
|
if (CommonUtils.levenshtein(item.ItemName, floor.Name) > similarity)
|
|
{
|
|
floorTotalArea += floor.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
|
|
item.Remarks += floor.Name + "\r\n";
|
|
}
|
|
}
|
|
item.Quantity = RsRevitUtils.ConvertSquareFeetToSquareMetre(floorTotalArea);
|
|
items.Add(item);
|
|
}
|
|
else if (revitType == "ceiling")
|
|
{
|
|
double ceilingTotalArea = 0.0;
|
|
var ceilings = new FilteredElementCollector(doc).OfClass(typeof(Ceiling)).Cast<Ceiling>();
|
|
|
|
foreach (var ceiling in ceilings)
|
|
{
|
|
if (CommonUtils.levenshtein(item.ItemName, ceiling.Name) > similarity)
|
|
{
|
|
ceilingTotalArea += ceiling.get_Parameter(BuiltInParameter.HOST_AREA_COMPUTED).AsDouble();
|
|
item.Remarks += ceiling.Name + "\r\n";
|
|
}
|
|
}
|
|
item.Quantity = RsRevitUtils.ConvertSquareFeetToSquareMetre(ceilingTotalArea);
|
|
|
|
items.Add(item);
|
|
}
|
|
else if (revitType == "familyinstance")
|
|
{
|
|
var instances = new FilteredElementCollector(doc).OfClass(typeof(FamilyInstance)).Cast<FamilyInstance>();
|
|
int count = 0;
|
|
double length = 0.0;
|
|
double area = 0.0;
|
|
string unit = item.Unit;
|
|
|
|
foreach (var instance in instances)
|
|
{
|
|
string familyName = instance.Symbol.FamilyName;
|
|
string tempname = CommonUtils.GetChineseWord(item.ItemName);
|
|
if (CommonUtils.levenshtein(tempname, familyName) > similarity)
|
|
{
|
|
if (unit == "m")
|
|
{
|
|
if (familyName.Contains("接待台"))
|
|
{
|
|
length += RsRevitUtils.ConvertFeetToMetre(instance.Symbol.GetParameters("台面长度").FirstOrDefault().AsDouble());
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
if (familyName.Contains("腰封玻璃贴"))
|
|
{
|
|
var cur = RsRevitUtils.GetLocationCurveByElement(instance);
|
|
length += RsRevitUtils.ConvertFeetToMetre(cur.Length);
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
if (familyName.Contains("亚克力水晶字"))
|
|
{
|
|
length += instance.GetParameters("文字").FirstOrDefault().AsString().Length * 116.4 / 1000;
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
if (familyName.Contains("精工背发光字"))
|
|
{
|
|
double l = Convert.ToDouble((instance.Symbol.Name.Substring(0, instance.Symbol.Name.IndexOf('m')))) / 1000;
|
|
length += l;
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
if (familyName.Contains("立体发光字"))
|
|
{
|
|
double l = Convert.ToDouble((instance.Symbol.Name.Substring(0, instance.Symbol.Name.IndexOf('m')))) / 1000;
|
|
length += l;
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
}
|
|
else if (unit == "m2")
|
|
{
|
|
if (familyName.Contains("卷帘") || familyName.Contains("玻璃隔断"))
|
|
{
|
|
var a = instance.Symbol.get_Parameter(BuiltInParameter.FAMILY_HEIGHT_PARAM).AsDouble() * instance.Symbol.get_Parameter(BuiltInParameter.FURNITURE_WIDTH).AsDouble();
|
|
|
|
area += RsRevitUtils.ConvertSquareFeetToSquareMetre(a);
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
}
|
|
else if (unit == "套" || unit == "个")
|
|
{
|
|
if (familyName.Contains("仓储货架"))
|
|
{
|
|
if (item.ItemName.Contains(instance.Symbol.GetParameters("长度").FirstOrDefault().AsValueString()))
|
|
{
|
|
count += 1;
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
}
|
|
else if (familyName.Contains("明装筒灯"))
|
|
{
|
|
if (item.Description.Contains(instance.Symbol.Name))
|
|
{
|
|
count += 1;
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
count += 1;
|
|
item.Remarks += familyName + "\r\n";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
switch (unit)
|
|
{
|
|
case "m":
|
|
item.Quantity = length;
|
|
break;
|
|
|
|
case "m2":
|
|
item.Quantity = area;
|
|
break;
|
|
|
|
case "个":
|
|
item.Quantity = count;
|
|
break;
|
|
|
|
case "套":
|
|
item.Quantity = count;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
items.Add(item);
|
|
}
|
|
else if (revitType == "cabletray")
|
|
{
|
|
double ctTotalLength = 0.0;
|
|
|
|
var cts = new FilteredElementCollector(doc).OfClass(typeof(CableTray)).Cast<CableTray>();
|
|
foreach (var ct in cts)
|
|
{
|
|
ctTotalLength += ct.get_Parameter(BuiltInParameter.CURVE_ELEM_LENGTH).AsDouble();
|
|
item.Remarks += ct.Name + "\r\n";
|
|
}
|
|
item.Quantity = RsRevitUtils.ConvertFeetToMetre(ctTotalLength);
|
|
|
|
items.Add(item);
|
|
}
|
|
else if (revitType == "curtainsystem")
|
|
{
|
|
double area = 0.0;
|
|
|
|
var curtainSystems = new FilteredElementCollector(doc).OfClass(typeof(CurtainSystem)).OfCategory(BuiltInCategory.OST_CurtaSystem).Cast<CurtainSystem>();
|
|
foreach (var curtainSystem in curtainSystems)
|
|
{
|
|
if (item.ItemName == curtainSystem.Name)
|
|
{
|
|
item.Remarks += curtainSystem.Name + "\r\n";
|
|
var geometryElement = curtainSystem.get_Geometry(new Options());
|
|
foreach (GeometryObject geomObj in geometryElement)
|
|
{
|
|
var solid = geomObj as Solid;
|
|
if (solid != null)
|
|
{
|
|
area += solid.SurfaceArea / 2;
|
|
}
|
|
}
|
|
}
|
|
//else//如果没有找到同名族类型,则按面积计算
|
|
//{
|
|
// var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).Cast<Room>();
|
|
// foreach (var room in rooms)
|
|
// {
|
|
// area += room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble();
|
|
// }
|
|
//}
|
|
}
|
|
item.Quantity = RsRevitUtils.ConvertSquareFeetToSquareMetre(area);
|
|
|
|
items.Add(item);
|
|
}
|
|
else//无法统计的量,采用总场地面积计
|
|
{
|
|
double otherArea = 0.0;
|
|
var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).Cast<Room>();
|
|
foreach (var room in rooms)
|
|
{
|
|
otherArea += room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble();
|
|
}
|
|
|
|
item.Quantity = RsRevitUtils.ConvertSquareFeetToSquareMetre(otherArea);
|
|
|
|
items.Add(item);
|
|
}
|
|
}
|
|
|
|
return items;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 表头
|
|
/// </summary>
|
|
/// <param item.ItemName="doc"></param>
|
|
/// <param item.ItemName="package"></param>
|
|
/// <returns></returns>
|
|
private static ExcelWorksheet CreateTableHeader(Document doc, ExcelPackage package)
|
|
{
|
|
var rooms = new FilteredElementCollector(doc).OfCategory(BuiltInCategory.OST_Rooms).Cast<Room>();
|
|
|
|
double area = 0.0;
|
|
foreach (var room in rooms)
|
|
{
|
|
area += RsRevitUtils.ConvertSquareFeetToSquareMetre(room.get_Parameter(BuiltInParameter.ROOM_AREA).AsDouble());
|
|
}
|
|
ExcelWorksheet sheet = package.Workbook.Worksheets.Add("工程预算清单");
|
|
sheet.Cells["A1:J1"].Merge = true;
|
|
using (var range = sheet.Cells[1, 1, 1, 10])
|
|
{
|
|
range.Style.Font.Bold = true;
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 18;
|
|
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
|
//var c = sheet.MergedCells[1, 2];
|
|
}
|
|
|
|
sheet.SetValue(1, 1, "菜鸟驿站工程预算清单");
|
|
sheet.SetValue(2, 1, "项目");
|
|
sheet.Cells["D2:E2"].Merge = true;
|
|
sheet.SetValue(2, 2, Properties.Settings.Default.ConstrctionOrg);
|
|
sheet.Cells[2, 2].Style.Font.Color.SetColor(System.Drawing.Color.Red);
|
|
sheet.SetValue(2, 3, "预算总价");
|
|
//sheet.SetValue(2, 4, "-");
|
|
sheet.Cells[2, 4].Style.Numberformat.Format = "#,##0.00";
|
|
sheet.Cells[2, 4].Style.Font.Color.SetColor(System.Drawing.Color.Red);
|
|
sheet.SetValue(2, 6, "项目面积");
|
|
sheet.Cells["F2:G2"].Merge = true;
|
|
sheet.SetValue(2, 8, area);
|
|
sheet.Cells[2, 8].Style.Numberformat.Format = "#,##0.00";
|
|
sheet.Cells[2, 8].Style.Font.Color.SetColor(System.Drawing.Color.Red);
|
|
sheet.SetValue(2, 9, "预算日期");
|
|
sheet.SetValue(2, 10, DateTime.Now.ToString("D"));
|
|
sheet.Cells[2, 10].Style.Font.Color.SetColor(System.Drawing.Color.Red);
|
|
using (var range = sheet.Cells[2, 1, 2, 10])
|
|
{
|
|
range.Style.Font.Bold = true;
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 10;
|
|
range.AutoFitColumns();
|
|
//range.Style.Border.BorderAround(ExcelBorderStyle.Thin);
|
|
//var c = sheet.MergedCells[1, 2];
|
|
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
|
}
|
|
|
|
sheet.SetValue(3, 1, "序号");
|
|
sheet.SetValue(3, 2, "项目名称");
|
|
sheet.SetValue(3, 3, "项目特征");
|
|
sheet.SetValue(3, 4, "单位");
|
|
sheet.SetValue(3, 5, "工程量");
|
|
sheet.SetValue(3, 6, "主材费");
|
|
sheet.SetValue(3, 7, "人工费");
|
|
sheet.SetValue(3, 8, "综合单价");
|
|
sheet.SetValue(3, 9, "总计");
|
|
sheet.SetValue(3, 10, "备注");
|
|
using (var range = sheet.Cells[3, 1, 3, 10])
|
|
{
|
|
range.Style.Font.Bold = true;
|
|
range.Style.Font.Name = "宋体";
|
|
range.Style.HorizontalAlignment = ExcelHorizontalAlignment.Center;
|
|
range.Style.Font.Size = 9;
|
|
range.AutoFitColumns();
|
|
//range.Style.Border.BorderAround(ExcelBorderStyle.Thin);
|
|
//var c = sheet.MergedCells[1, 2];
|
|
range.Style.Border.Top.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Bottom.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Left.Style = ExcelBorderStyle.Thin;
|
|
range.Style.Border.Right.Style = ExcelBorderStyle.Thin;
|
|
}
|
|
|
|
sheet.Cells[2, 2].Style.Font.Bold = false;
|
|
sheet.Cells[2, 8].Style.Font.Bold = false;
|
|
sheet.Cells[2, 10].Style.Font.Bold = false;
|
|
sheet.View.FreezePanes(4, 1);
|
|
sheet.View.ZoomScale = 120;
|
|
return sheet;
|
|
}
|
|
}
|
|
} |