Morphology of cell nuclei and data transfer to Excel

Everything OAD-related that won't fit in the other categories: share general aspects of macro programming and discuss the OAD environment
Post Reply
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Morphology of cell nuclei and data transfer to Excel

Post by user-4 »

Code: Select all

#######################################################
## M I S C E L L A N E O U S
##
## Macro name: Morphology of cell nuclei and data transfer to Excel
## Required files: 018 - morphology of nuclei.zvi
##
## LOAD IMAGE, SEGMENT NUCLEI, MEASURE SIZE OF NUCLEI
## SEND DATA TO EXCEL AND GENERATE DATALIST AND CHART
## 
#######################################################
##
##
#import clr
clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel

excel = Excel.ApplicationClass()

#######################################################
# 1 Demo
# 0 work
demo = 0

#######################################################
## LOAD IMAGE, SEGMENT NUCLEI, MEASURE SIZE OF NUCLEI
##
## UC 34 - Morphology of cell nuclei
#######################################################
##
##
## Remove all open images
Zen.Application.Documents.RemoveAll()
##
## Load the image automatically (example image of DVD 36)
## Display the image
image = Zen.Application.LoadImage ('C:\\OAD\\Input\\ZVI Images\\018 - morphology of nuclei.zvi')
#-----------------------------------------
if demo == 1:
    Zen.Application.Documents.Add(image)
#-----------------------------------------
## Set channel color for DAPI
image.SetChannelColor(0,ZenColors.Blue)
##
## Load measurement program
## Measure automatically (Run Silent)
## Show results in Analysis view
ias=ZenImageAnalysisSetting()
ias.Load("UseCase 03 - Morphology of cell nuclei.czias")
Zen.Analyzing.Analyze(image,ias)
##
## Create data list with results
regTable = Zen.Analyzing.CreateRegionTable(image)
#-----------------------------------------
if demo == 1:
    Zen.Application.Documents.Add(regTable)
#-----------------------------------------
##
## Save data list automatically
regTableName = regTable.Name
#-----------------------------------------
if demo == 1:
    regTable.Save("C:\\OAD\\Output\\CSV Tables\\" + regTable.Name + ".csv")
#-----------------------------------------
##
## Save measured image automatically
if demo == 1:
    fileNameWE = image.Name.Substring(0,image.Name.Length-4)
    newFileName = fileNameWE + '.czi'
    imageName = "C:\\OAD\\Output\\CZI Images\\" + newFileName
    image.Save(imageName)
##
#######################################################


#######################################################
## Transfer Data to Excel
##
#######################################################
##

if demo == 1:
    excel.Visible = True

excel.DisplayAlerts = False

workbook = excel.Workbooks.Add()
worksheet = workbook.Worksheets[1]

excel.Cells(1,1).Value = "Region ID"
excel.Cells(1,2).Value = "Area[µm²]"
excel.Cells(1,3).Value = "Form Cicle"
excel.Cells(1,4).Value = "FeretRatio"
excel.Cells(1,5).Value = "Ellipse Angle[°]"
excel.Cells(1,6).Value = "Ellipse Major[µm²]"
excel.Cells(1,7).Value = "Ellipse Minor[µm²]"

for Row in range(0,regTable.RowCount):
    for Col in range(0,regTable.ColumnCount):
        excel.Cells(Row+2,Col+1).Value = regTable.GetValue(Row,Col)


xlLine = 4
msoFalse = 0
msoScaleFromTopLeft = 0

excel.Cells.Select()
excel.Cells.EntireColumn.AutoFit()


excel.Rows("1:1").Select()
excel.Selection.Font.Bold = True
excel.Range("A1").Select
excel.ActiveSheet.Shapes.AddChart().Select()
excel.ActiveChart.ChartType = xlLine
excel.ActiveChart.SetSourceData(excel.Range("Sheet1!$A$1:$G$32"))
ActiveShape = excel.ActiveSheet.Shapes(excel.ActiveSheet.Shapes.Count)
ActiveShape.Left = 500
ActiveShape.Top =50
ActiveShape.ScaleWidth(1.4416666667, msoFalse, msoScaleFromTopLeft)
ActiveShape.ScaleHeight(1.8420140712, msoFalse, msoScaleFromTopLeft)


excel.Range("A1").Select()

if demo == 0:
    excel.Visible = True
##
#######################################################
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6033 »

Hi,
I wonder if someone knows if there might be a simple way to bring the excel window in topmost position and not minimized?

Best regards
Fredrik Olsson
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

bring the excel window in topmost position and not minimized
This worked in my case:

Code: Select all

clr.AddReferenceByName('Microsoft.Office.Interop.Excel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c')
from Microsoft.Office.Interop import Excel

excel = Excel.ApplicationClass()

excel.Visible = True

xlMaximized = -4137

excel.Application.WindowState = xlMaximized

workbook = excel.Workbooks.Add()
user-6033
Posts: 89
Joined: Thu Jan 01, 1970 1:00 am

Post by user-6033 »

Hi,

I tried it but for me it seems as the active window is still Zen Core, which stays as the topmost window.

Best regards

Fredrik Olsson
user-4
Posts: 397
Joined: Thu Jan 01, 1970 1:00 am

Post by user-4 »

Sorry, but I tried some Versions of Zen Core (including 2.6) and there was not a single case where Excel (in my case 2013) stays 'in the back'.

I always tried 'Free Examination' and 'Run Job Template' to cover both main cases. But even in 'Create Job Template' and 'Manage Templates' the code shown obove worked for me.

From my point of view there are probably other relevant factors like Operation System (Windows 7 in my case), not evident problems with Installation of Excel, etc.

If it is important for you, there are code examples in the internet how to put a Window in topmost position. But this topic is not part of OAD any more
Teen Gosht
Posts: 5
Joined: Thu Nov 23, 2023 9:49 am

Re: Morphology of cell nuclei and data transfer to Excel

Post by Teen Gosht »

The Microsoft AZ-104 Exam Questions PDF is a comprehensive resource designed to help candidates prepare for the AZ-104 exam, which focuses on Microsoft Azure administration. This PDF contains a collection of practice questions that cover various topics, including managing Azure identities and governance, implementing and managing storage, configuring virtual networking, and more. It serves as a valuable study aid, allowing individuals to assess their knowledge, identify areas of improvement, and familiarize themselves with the format and types of questions that may appear on the Official Microsoft Exam. This resource aims to support candidates in their preparation for successfully passing the AZ-104 exam and obtaining certification as an Azure Administrator.

Visit Page: https://www.dumpsleader.com/AZ-104-exam-dumps.html
Post Reply