Pyrevit and excel

Hi @aaronrumple

i have a follow-up question:
i’m trying to export schedule data to excel.
I found a topic about this here:
Schedule data to sheets in an xlsm file - Revit API - pyRevit Forums

Here they reference some code of you.
guRoo/guRoo.tab/Tools.panel/Export.pulldown/ScheduleXcl.pushbutton/ScheduleXcl_script.py at main · aussieBIMguru/guRoo

snippet:

# Create list with schedule data with rows as second level lists
data = []

for i in range(numbRows):
	rows = []
	for j in range(numbCols):
		content = sched.GetCellText(DB.SectionType.Body, i, j)
		rows.append(content)
	data.append(rows)

When i use the ‘GetCellText’ methode i only get the value of text parameters.
Ang not even all of them only a few it seems.

In c# this seems to work fine, but python seems to be missmapping the variabletype i guesse?
Any feedback on this?

Did you ever encouter this problem?

Below my code i’m testing on right now:

# -*- coding: utf-8 -*-

# imports
# ===================================================

# .NET Imports
import clr
clr.AddReference("System")
from System.Collections.Generic import List

clr.AddReference('Microsoft.Office.Interop.Excel')
from Microsoft.Office.Interop import Excel

# Autodesk + pyrevit imports
from Autodesk.Revit.DB import *
from pyrevit import revit, script, forms

# bbpy imports
from Selection.Views import Getbyname_schedule
from excelUtils import open_excel_file_BySelection

# Variables
# ===================================================
doc = revit.doc
uidoc = revit.uidoc

# Main
# ===================================================
if __name__ == '__main__':
    schedule = Getbyname_schedule('994.00_QTO-Generic Models', doc=doc)
    if schedule is None:
        print('Schedule not found')
        script.exit()
        
    try:
        table_data = schedule.GetTableData()
        table_section = table_data.GetSectionData(SectionType.Body)
        numbRows = table_section.NumberOfRows
        numbCols = table_section.NumberOfColumns
    except:
        forms.alert("No data in table to export.", title= "Script cancelled")
        script.exit()
    
    # select excel folder location (Sheet1)
    workbook, excel_app = open_excel_file_BySelection()
    
    # get schedule data
    scheduleData = [[table_section.GetCellText(row, col) for col in range(numbCols)] for row in range(numbRows)]
    
    # write data to excel
    for worksheet in workbook.Worksheets:
        if worksheet.Name == "Sheet1":
            # This is the worksheet you're interested in
            for i, row in enumerate(scheduleData):
                for j, cell in enumerate(row):
                    worksheet.Cells[i+1, j+1].Value2 = cell
            break
    
    
    print('data written to excel')
    
    # close excel 
    workbook.Close(True)  # Close + saving changes
    excel_app.Quit()