Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intermittent Save" with "0" argument(s) when importing multiple csvs #1629

Closed
twhitesc opened this issue Aug 26, 2024 · 7 comments
Closed

intermittent Save" with "0" argument(s) when importing multiple csvs #1629

twhitesc opened this issue Aug 26, 2024 · 7 comments

Comments

@twhitesc
Copy link

twhitesc commented Aug 26, 2024

fantastic overall module.

intermittently we are getting "Save with "0" argument(s)" error as it seems the excel file is locked when it tries to update it with additional csv files. we have roughly 20 csvs that must be imported. fails at different places. 1 out of 10 times it fails.

using a start-sleep in between imports reduced the issue but didn't eliminate it. Any suggestions?

example:

import-csv $General_Daily | 
Export-Excel $xlfile -WorkSheetName "Metrics"  -AutoSize -StartRow 10 -StartColumn 13 -TableName General_Daily -TableStyle Light15 -Title "Combined Program totals - Daily" -TitleBold -TitleSize 14

Start-Sleep -Seconds 3

import-csv $General_Daily_Total |
Export-Excel $xlfile -WorkSheetName "Metrics"  -AutoSize -StartRow 20 -StartColumn 13 -TableName General_Daily_Total  -TableStyle Light15 -NoHeader

Start-Sleep -Seconds 3
 
import-csv $General_Monthly |
Export-Excel $xlfile -WorkSheetName "Metrics"  -AutoSize -StartRow 23 -StartColumn 13 -TableName General_Monthly -TableStyle Light15 -Title "Combined Program totals - Monthly" -TitleBold -TitleSize 14

Start-Sleep -Seconds 3

Thank you

@dfinke
Copy link
Owner

dfinke commented Aug 28, 2024

thanks @twhitesc

Can you show more of the script? what is in $General_Daily? A single file name.

Not sure what the issue might be.

@twhitesc
Copy link
Author

Yes $General_Daily points to a csv file. It worked fine for years. And then in 2024 at some point it started popping up. Happens in background and in foreground. The csv files are no more than 3 KB in size. The excel file doesn't yet exist until this script creates it so it wouldn't be opened by another process/user.

#Data $General_Daily = get-childitem C:\Scripts\ClientReports\$filePath\General-Daily.csv $General_Monthly = get-childitem C:\Scripts\ClientReports\$filePath\General-Monthly.csv $General_Yearly = get-childitem C:\Scripts\ClientReports\$filePath\General-Yearly.csv

#Totals
$General_Daily_Total = get-childitem C:\Scripts\ClientReports$filePath\General-Daily-Total.csv
$General_Monthly_Total = get-childitem C:\Scripts\ClientReports$filePath\General-Monthly-Total.csv
$General_Yearly_Total = get-childitem C:\Scripts\ClientReports$filePath\General-Yearly-Total.csv
$Callback_Disposition_Total = get-childitem C:\Scripts\ClientReports$filePath\Callback-Disposition-Total.csv

`try
{

import-csv $General_Daily | Export-Excel $xlfile -WorkSheetName "Metrics" -AutoSize -StartRow 10 -StartColumn 13 -TableName General_Daily -TableStyle Light15 -Title "Combined Program totals - Daily" -TitleBold -TitleSize 14
Start-Sleep -Seconds 3
import-csv $General_Daily_Total | Export-Excel $xlfile -WorkSheetName "Metrics" -AutoSize -StartRow 20 -StartColumn 13 -TableName General_Daily_Total -TableStyle Light15 -NoHeader
Start-Sleep -Seconds 3
import-csv $General_Monthly | Export-Excel $xlfile -WorkSheetName "Metrics" -AutoSize -StartRow 23 -StartColumn 13 -TableName General_Monthly -TableStyle Light15 -Title "Combined Program totals - Monthly" -TitleBold -TitleSize 14
Start-Sleep -Seconds 3
import-csv $General_Monthly_Total | Export-Excel $xlfile -WorkSheetName "Metrics" -AutoSize -StartRow 33 -StartColumn 13 -TableName General_Monthly_Total -TableStyle Light15 -NoHeader
Start-Sleep -Seconds 3`
$excel = import-csv $Callback_Disposition_Total | Export-Excel $xlfile -WorkSheetName "Callback Disposition" -AutoSize -StartRow 39 -StartColumn 1 -TableName Callback_Disposition_Total -TableStyle Light15 -NoHeader -PassThru
Start-Sleep -Seconds 3
}
catch
{
Write-Host "An error occurred: $($_.Exception.Message)"
}

Close-ExcelPackage $excel

@dfinke
Copy link
Owner

dfinke commented Aug 28, 2024

did you update the ImportExcel module?

not sure why the -passthru is needed here

$excel = import-csv $Callback_Disposition_Total | Export-Excel $xlfile -WorkSheetName "Callback Disposition" -AutoSize -StartRow 39 -StartColumn 1 -TableName Callback_Disposition_Total -TableStyle Light15 -NoHeader -PassThru

then this is not needed:

Close-ExcelPackage $excel

Doesn't look like issues to my eye. Btw, very cool application of the Excel module.

Maybe the module got updated and it introduced an issue.

@twhitesc
Copy link
Author

i didn't update the package until we saw the issue. we've updated it a few times since the issue started.

i believe we do -PassThru as there is a bunch of other excel formatting we do before finally calling Close-ExcelPackage $excel

The error occurs before we get to the final -PassThru line.

@dfinke
Copy link
Owner

dfinke commented Aug 29, 2024

I'd need a small repro of this to see what may be the issue, including data.

If it makes sense, I'd look to go back to a version of ImportExcel that worked.

@twhitesc
Copy link
Author

twhitesc commented Oct 1, 2024

I figured out the issue. Bitdefender was locking the file. Disabling it solved the issue. Thanks for your help.

@twhitesc twhitesc closed this as completed Oct 1, 2024
@dfinke
Copy link
Owner

dfinke commented Oct 1, 2024

Wow - thanks for updating

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants