Bumblebee issues with text format

Hi!
I’m trying to use bumblebee to format my excel without succes!
I don’t understand what I’m doing wrong

(filepath is the same that I’m producing with dynamo)


Probably what is happening is the formatting is trying to run at the same time as creating the spreadsheet, so there isn’t a spreadsheet for it to format. Try using a passthrough node to wait for the data output from the “Data.ExportExcel” node before passing the filepath to the “Conditionally Format Excel” node. If that doesn’t work, then you will also have to place a transaction end node after the passthrough, so that it completes the first transaction before passing the filepath on.

Example

Thank you for your reply,

steel doesn’t work :confused:

You are getting a Success return from the Conditional Format node and it’s not showing any errors being returned by any of the other nodes, so explain what part(s) are not working.

I simplified the node, only to see why doen’s work… the node steel wrighting “success!” without real changes on the excel :confused:

I have to assume that it’s something with the code then. You can use the code below to set the text formatting. If you are wanting to change anything else with the cell itself, you will have to modify the code. It uses Interop which is not the most highly chosen method.

# Import required modules
import clr
clr.AddReference("Microsoft.Office.Interop.Excel")
from Microsoft.Office.Interop import Excel

# Inputs
filePath = IN[0]  # Full path to Excel file
sheetName = IN[1]  # Worksheet name
dataRange = IN[2]  # Range to apply formatting (e.g., "A1:C10")
fontName = IN[3]  # Font name (e.g., "Arial")
fontSize = IN[4]  # Font size (e.g., 12)
fontColor = IN[5]  # Font color in RGB (e.g., 255 for red)
horizontalAlignment = IN[6].ToLower()  # Horizontal alignment (e.g., "Center", "Left", "Right")
verticalAlignment = IN[7].ToLower()  # Vertical alignment (e.g., "Center", "Left", "Right")
bold = IN[8]  # Bold font (True/False)
italic = IN[9]  # Italic font (True/False)
underline = IN[10]  # Underline (True/False)
strikethrough = IN[11]  # Strikethrough (True/False)

# Open Excel
excel = Excel.ApplicationClass()
excel.Visible = False
workbook = excel.Workbooks.Open(filePath)
sheet = workbook.Sheets(sheetName)

# Define the range to format
range_to_format = sheet.Range[dataRange]

# Apply text formatting
range_to_format.Font.Name = fontName
range_to_format.Font.Size = fontSize
range_to_format.Font.Color = fontColor
range_to_format.Font.Bold = bold
range_to_format.Font.Italic = italic
range_to_format.Font.Underline = underline
range_to_format.Font.Strikethrough = strikethrough

# Apply alignment
if horizontalAlignment.lower() == "center":
    range_to_format.HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
elif horizontalAlignment.lower() == "left":
    range_to_format.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
elif horizontalAlignment.lower() == "right":
    range_to_format.HorizontalAlignment = Excel.XlHAlign.xlHAlignRight

if verticalAlignment.lower() == "center":
    range_to_format.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
elif verticalAlignment.lower() == "top":
    range_to_format.VerticalAlignment = Excel.XlVAlign.xlVAlignTop
elif verticalAlignment.lower() == "bottom":
    range_to_format.VerticalAlignment = Excel.XlVAlign.xlVAlignBottom

# Save and close
workbook.Save()
workbook.Close(SaveChanges=True)
excel.Quit()

# Clean up COM objects
import gc
gc.collect()

# Output
OUT = "Formatting Applied"
1 Like

I think I have something on my office that blocks that…

You have a false going into IN[7] and that’s supposed to be “Center” just like IN[6].

Also if you want, you can remove the .ToLower() from the highlighted lines shown below. It’s redundancy here, since the tolower is being taken care of further down in the code.

image