I need to have a task ran with task scheduler without having a user logged on. However, this script uses COMObject Excel.application which needs a user logged on to interact with excel.
I am new to python I was able to use spire.xls but it is not giving me the same result.
This is the powershell script but I am not sure if there are modules in python that can do similar.
$savepath = "D:ExactSharedLDS"
$dToday = Get-Date -Format "yyyyMMddHHmmss"
$path = "C:Excel"
$filename = "ORDERS_US06_" + $dToday
$xlTxt = -4158
$excelFiles = Get-ChildItem -Path $path -include *.xls, *.xlsx -recurse
$objExcel = New-Object -ComObject excel.application
$objExcel.visible = $true
foreach ($wb in $excelFiles) {
$wb = $objExcel.workbooks.open($wb.fullname, 3)
$wb.RefreshAll()
Start-Sleep -Seconds 5
$wb.SaveAs("$savepath" + $filename + ".csv", $xlTxt)
$wb.Saved=$true
$objExcel.ActiveSheet.Save()
$objExcel.Workbooks.close()
}
$objExcel.Quit()
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($filename)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($excelFiles)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($savepath)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($dToday)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($path)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($objExcel)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($xlTxt)
[System.Runtime.Interopservices.Marshal]::ReleaseComObject($wb)
New contributor
Brunozu96 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.