Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
ElectronicsDataHandling
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ResearchIT
ElectronicsDataHandling
Commits
a16794d8
Commit
a16794d8
authored
2 years ago
by
Flavio Ackermann
Browse files
Options
Downloads
Patches
Plain Diff
Improved Excel file handling, CSV file handling
parent
2713ba30
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Sources/Invoke-ElectronicsDataPointExtraction.ps1
+6
-2
6 additions, 2 deletions
Sources/Invoke-ElectronicsDataPointExtraction.ps1
Sources/Module/ElectronicsDataHandling/ElectronicsDataHandling.psm1
+29
-24
29 additions, 24 deletions
...dule/ElectronicsDataHandling/ElectronicsDataHandling.psm1
with
35 additions
and
26 deletions
Sources/Invoke-ElectronicsDataPointExtraction.ps1
+
6
−
2
View file @
a16794d8
Import-Module
-Name
"
$PSScriptRoot
\Module\ElectronicsDataHandling"
Convert-ElectronicsDataFile
\ No newline at end of file
Start-Transcript
-Path
"
$PSScriptRoot
\..\Log\
$(
Get-Date
-Format
"yyyy-MM-dd-HHmmss"
)
.log"
Import-Module
-Name
"
$PSScriptRoot
\Module\ElectronicsDataHandling"
-Force
Convert-ElectronicsDataFile
-Verbose
Stop-Transcript
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Sources/Module/ElectronicsDataHandling/ElectronicsDataHandling.psm1
+
29
−
24
View file @
a16794d8
...
...
@@ -77,7 +77,7 @@ function Import-RequiredModules {
Write-Verbose
"Imported module '
$ModuleName
'"
}
catch
{
Write-Warning
"Module '
$ModuleName
' could not be imported"
b
re
ak
re
turn
}
}
}
...
...
@@ -107,7 +107,9 @@ function Convert-ElectronicsDataFile {
$OutputFilePath
)
begin
{
begin
{}
process
{
Import-RequiredModules
#region Select input file
...
...
@@ -122,9 +124,15 @@ function Convert-ElectronicsDataFile {
$null
=
$FileBrowser
.
ShowDialog
()
$SourceFile
=
Get-Item
-Path
$FileBrowser
.
FileName
Write-Verbose
"Source file is '
$(
$SourceFile
.
FullName
)
'
`n
$SourceFile
"
Write-Verbose
"Source file is '
$(
$SourceFile
.
FullName
)
'"
}
$FileExtension
=
$SourceFile
.
Extension
if
(
$FileExtension
-notmatch
'.txt|.xlsx|.csv'
)
{
Write-Warning
"File format is not supported: '
$FileExtension
'"
return
}
#endregion
Write-Output
"What"
#region Select output file
if
(
-not
(
$OutputFilePath
))
{
...
...
@@ -145,31 +153,25 @@ function Convert-ElectronicsDataFile {
$SaveStatus
=
$SaveFileDialog
.
ShowDialog
()
if
(
$SaveStatus
-eq
'Cancel'
)
{
Write-
Verbose
'Save file dialog got cancelled'
b
re
ak
Write-
Warning
'Save file dialog got cancelled'
re
turn
}
$OutputFile
=
New-Item
-Path
$SaveFileDialog
.
FileName
-Force
$OutputFilePath
=
$SaveFileDialog
.
FileName
#endregion
$Selector
=
Get-SelectorFromDialog
$FileExtension
=
$SourceFile
.
Extension
if
(
$FileExtension
-notmatch
'.txt|.xlsx'
)
{
Write-Warning
"File format is not supported: '
$FileExtension
'"
break
}
Write-Output
"Importing content from '
$(
$SourceFile
.
FullName
)
'"
switch
(
$FileExtension
)
{
'.
xlsx
'
{
$Data
=
Import-
Excel
-Path
$SourceFile
.
FullName
-NoHeader
}
'.
csv
'
{
$Data
=
Import-
CSV
-Path
$SourceFile
.
FullName
}
'.txt'
{
$Data
=
Get-Content
-Path
$SourceFile
.
FullName
}
'.xlsx'
{
$Data
=
Import-Excel
-Path
$SourceFile
.
FullName
-NoHeader
}
# -AsText *}
}
}
process
{
$i
=
0
$Result
=
$Data
|
ForEach-Object
{
if
(
$i
%
$Selector
-eq
0
)
{
...
...
@@ -177,20 +179,23 @@ function Convert-ElectronicsDataFile {
}
$i
++
}
}
end
{
switch
(
$FileExtension
)
{
'.
xlsx
'
{
$Result
|
Export-
Excel
-Path
$OutputFile
-NoHeader
'.
csv
'
{
$Result
|
Export-
CSV
-Path
$OutputFile
Path
-NoTypeInformation
}
'.txt'
{
$Result
|
Set-Content
-Path
$OutputFile
$null
=
New-Item
-Path
$OutputFilePath
-Force
$Result
|
Set-Content
-Path
$OutputFilePath
}
'.xlsx'
{
$Result
|
Export-Excel
-Path
$OutputFilePath
-NoHeader
-ClearSheet
}
}
Write-Verbose
"Created file '
$OutputFile
'"
Invoke-Item
-Path
$OutputFile
.
DirectoryName
Write-Verbose
"Created file '
$OutputFile
Path
'"
Invoke-Item
-Path
(
Get-Item
-Path
$OutputFile
Path
)
.
DirectoryName
}
end
{}
}
Export-ModuleMember
-Function
Convert-ElectronicsDataFile
\ No newline at end of file
Export-ModuleMember
-Function
Convert-ElectronicsDataFile
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment