整理代码
This commit is contained in:
85
ShrlAlgoToolkit.RevitAddins/RvView/ExportSchedulesCmd.cs
Normal file
85
ShrlAlgoToolkit.RevitAddins/RvView/ExportSchedulesCmd.cs
Normal file
@@ -0,0 +1,85 @@
|
||||
|
||||
using Autodesk.Revit.DB;
|
||||
|
||||
using Autodesk.Revit.UI;
|
||||
|
||||
using Nice3point.Revit.Toolkit.External;
|
||||
|
||||
using Sai.RvKits.Assists;
|
||||
|
||||
using System.IO;
|
||||
|
||||
using WPFluent.Controls;
|
||||
|
||||
namespace ShrlAlgo.RvKits.RvView;
|
||||
|
||||
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
|
||||
[Autodesk.Revit.Attributes.Regeneration(Autodesk.Revit.Attributes.RegenerationOption.Manual)]
|
||||
public class ExportSchedulesCmd : ExternalCommand
|
||||
{
|
||||
public override void Execute()
|
||||
{
|
||||
var list = Document.OfCollector().OfClass(typeof(ViewSchedule)).OfCategory(BuiltInCategory.OST_Schedules).Cast<ViewSchedule>().ToList();
|
||||
if (!list.Any())
|
||||
{
|
||||
ErrorMessage = "当前项目不存在明细表";
|
||||
Result = Result.Failed;
|
||||
return;
|
||||
}
|
||||
var browserWindow = new VistaFolderBrowserDialog();
|
||||
browserWindow.ShowDialog();
|
||||
var selectedPath = browserWindow.SelectedPath;
|
||||
if (selectedPath == null || !Directory.Exists(selectedPath))
|
||||
{
|
||||
//var manager = new NotificationMessageManager();
|
||||
//manager.CreateMessage().Accent("#1751C3").Background("#333").HasBadge("净高").HasMessage("未选择文件夹").Queue();
|
||||
Result = Result.Cancelled;
|
||||
return;
|
||||
}
|
||||
|
||||
var path = $"{selectedPath}\\导出的明细表.xlsx";
|
||||
|
||||
EPPlusHelper.WriteExcel(
|
||||
path,
|
||||
m =>
|
||||
{
|
||||
foreach (var viewSchedule in list)
|
||||
{
|
||||
if (!viewSchedule.CanHaveTypeAssigned())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var sheet = m.Workbook.Worksheets.Add(viewSchedule.Name);
|
||||
var td = viewSchedule.GetTableData();
|
||||
|
||||
//TableSectionData tdb = td.GetSectionData(SectionType.Header);
|
||||
//int hc = tdb.NumberOfColumns;
|
||||
//int hr = tdb.NumberOfRows;
|
||||
//for (int i = 0; i < hr; i++)
|
||||
//{
|
||||
// for (int j = 0; j < hc; j++)
|
||||
// {
|
||||
// //Autodesk.Revit.DB.CellType ctype = tdd.GetCellType(i, j);
|
||||
// string str = viewSchedule.GetCellText(SectionType.Header, i, j);
|
||||
// sheet.Cells[i + 1, j + 1].Value = str;
|
||||
// }
|
||||
//}
|
||||
var tdd = td.GetSectionData(SectionType.Body);
|
||||
var c = tdd.NumberOfColumns;
|
||||
var r = tdd.NumberOfRows;
|
||||
for (var i = 0; i < r; i++)
|
||||
{
|
||||
for (var j = 0; j < c; j++)
|
||||
{
|
||||
sheet.Cells[i + 1, j + 1].Value = viewSchedule.GetCellText(SectionType.Body, i, j);
|
||||
}
|
||||
}
|
||||
|
||||
EPPlusHelper.SetStyle(sheet, 1, sheet.Dimension.Rows, 1, sheet.Dimension.Columns);
|
||||
}
|
||||
}
|
||||
);
|
||||
ShrlAlgo.Toolkit.Core.Assist.WinDialogHelper.OpenFolderAndSelectFile(path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user