Hi @studio-a-int,
I used sample SAX approach code in this page .
https://learn.microsoft.com/en-us/office/open-xml/spreadsheet/how-to-parse-and-read-a-large-spreadsh...
// The SAX approach.
static void ReadExcelFileSAX(string fileName)
{
using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
{
WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart ?? spreadsheetDocument.AddWorkbookPart();
WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
OpenXmlReader reader = OpenXmlReader.Create(worksheetPart);
string text;
while (reader.Read())
{
if (reader.ElementType == typeof(CellValue))
{
text = reader.GetText();
Console.Write(text + " ");
}
}
Console.WriteLine();
Console.ReadKey();
}
}
I tried a sample macro in Revit 2025. The code is below.
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Mechanical;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
using System;
using System.Linq;
namespace HelloWorld
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("972CCC9D-F011-4430-B5C5-F757BFE97FD4")]
public partial class ThisApplication
{
private void Module_Startup(object? sender, EventArgs e)
{
SampleMacro();
}
private void Module_Shutdown(object? sender, EventArgs e)
{
}
// Comment out below method to add a sample Macro
public void SampleMacro()
{
string fileName = @"C:\Worksets.xlsx";
using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(fileName, false))
{
WorkbookPart workbookPart = spreadsheetDocument.WorkbookPart ?? spreadsheetDocument.AddWorkbookPart();
WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
OpenXmlReader reader = OpenXmlReader.Create(worksheetPart); // This line prevents Macro manager to run macro.
// string text;
// while (reader.Read())
// {
// if (reader.ElementType == typeof(CellValue))
// {
// text = reader.GetText();
// //Console.Write(text + " ");
// TaskDialog.Show("Hello World!", text + " ");
// }
// TaskDialog.Show("Hello World!", "Exit the function SampleMacro()");
// }
}
}
}
}
When I uncomment the line "OpenXmlReader reader = OpenXmlReader.Create(worksheetPart); // This line prevents Macro manager to run macro."
It prevent macro manager to run macro. Waht could be the problem?