Files
RevitArchive/RevitAddins/GlobalVariables.cs

43 lines
1.2 KiB
C#
Raw Permalink Normal View History

2026-02-23 14:58:05 +08:00

using Autodesk.Windows;
using OfficeOpenXml;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Timers;
namespace RevitAddins
{
public static class GlobalVariables
{
public static IntPtr RevitWindowPtr => ComponentManager.ApplicationWindow;
public static string AddInPath = typeof(GlobalVariables).Assembly.Location;
public static string DirAssembly = Path.GetDirectoryName(AddInPath);
public static Timer Timer { get; } = new();
public static void TrimLastEmptyRows(this ExcelWorksheet worksheet)
{
while (worksheet.IsLastRowEmpty())
{
worksheet.DeleteRow(worksheet.Dimension.End.Row, 1);
}
}
public static bool IsLastRowEmpty(this ExcelWorksheet worksheet)
{
List<bool> empties = [];
for (var index = 1; index <= worksheet.Dimension.End.Column; index++)
{
var value = worksheet.Cells[worksheet.Dimension.End.Row, index].Value;
empties.Add(value == null || string.IsNullOrWhiteSpace(value.ToString()));
}
return empties.All(e => e);
}
}
}