mirror of
https://github.com/dfinke/ImportExcel.git
synced 2025-12-15 07:43:23 +00:00
Compare commits
12 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c641eea10a | ||
|
|
99de9a9854 | ||
|
|
3121c5eaed | ||
|
|
d02f757568 | ||
|
|
a693725949 | ||
|
|
5e19d0ca1a | ||
|
|
204b82144f | ||
|
|
91eefbd48b | ||
|
|
f86556a89d | ||
|
|
14e1dfd8db | ||
|
|
1d961c679e | ||
|
|
7026803415 |
56
.vscode/launch.json
vendored
56
.vscode/launch.json
vendored
@@ -1,56 +0,0 @@
|
||||
{
|
||||
// Use IntelliSense to learn about possible attributes.
|
||||
// Hover to view descriptions of existing attributes.
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Pester Tests",
|
||||
"script": "Import-Module -Name '.\\' -Force ; Invoke-Pester", // Change to '.\\ModuleName.psd1' if Git name different
|
||||
"args": [""],
|
||||
"cwd": "${workspaceFolder}"
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Launch Current File",
|
||||
"script": "${file}",
|
||||
"args": [],
|
||||
"cwd": "${file}"
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Launch Current File in Temporary Console",
|
||||
"script": "${file}",
|
||||
"args": [],
|
||||
"cwd": "${file}",
|
||||
"createTemporaryIntegratedConsole": true
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Launch Current File w/Args Prompt",
|
||||
"script": "${file}",
|
||||
"args": [
|
||||
"${command:SpecifyScriptArgs}"
|
||||
],
|
||||
"cwd": "${file}"
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "attach",
|
||||
"name": "PowerShell Attach to Host Process",
|
||||
"processId": "${command:PickPSHostProcess}",
|
||||
"runspaceId": 1
|
||||
},
|
||||
{
|
||||
"type": "PowerShell",
|
||||
"request": "launch",
|
||||
"name": "PowerShell Interactive Session",
|
||||
"cwd": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
RootModule = 'ImportExcel.psm1'
|
||||
|
||||
# Version number of this module.
|
||||
ModuleVersion = '7.1.2'
|
||||
ModuleVersion = '7.2.1'
|
||||
|
||||
# ID used to uniquely identify this module
|
||||
GUID = '60dd4136-feff-401a-ba27-a84458c57ede'
|
||||
@@ -78,7 +78,9 @@ Check out the How To Videos https://www.youtube.com/watch?v=U3Ne_yX4tYo&list=PL5
|
||||
'Open-ExcelPackage',
|
||||
'PieChart',
|
||||
'Pivot',
|
||||
'Remove-Worksheet'
|
||||
'Read-Clipboard',
|
||||
'ReadClipboardImpl',
|
||||
'Remove-Worksheet',
|
||||
'Select-Worksheet',
|
||||
'Send-SQLDataToExcel',
|
||||
'Set-CellStyle',
|
||||
|
||||
@@ -19,7 +19,7 @@ function ConvertFrom-ExcelSheet {
|
||||
[string[]]$AsDate = @()
|
||||
)
|
||||
|
||||
$Path = (Resolve-Path $Path).Path
|
||||
$Path = (Resolve-Path $Path).ProviderPath
|
||||
$xl = New-Object -TypeName OfficeOpenXml.ExcelPackage -ArgumentList $Path
|
||||
$workbook = $xl.Workbook
|
||||
|
||||
|
||||
90
Public/Read-Clipboard.ps1
Normal file
90
Public/Read-Clipboard.ps1
Normal file
@@ -0,0 +1,90 @@
|
||||
function Read-Clipboard {
|
||||
<#
|
||||
.SYNOPSIS
|
||||
Read text from clipboard and pass to either ConvertFrom-Csv or ConvertFrom-Json.
|
||||
Check out the how to video - https://youtu.be/dv2GOH5sbpA
|
||||
|
||||
.DESCRIPTION
|
||||
Read text from clipboard. It can read CSV or JSON. Plus, you can specify the delimiter and headers.
|
||||
|
||||
.EXAMPLE
|
||||
Read-Clipboard # Detects if the clipboard contains CSV, JSON, or Tab delimited data.
|
||||
|
||||
.EXAMPLE
|
||||
Read-Clipboard -Delimiter '|' # Converts data using a pipe delimiter
|
||||
|
||||
.EXAMPLE
|
||||
Read-Clipboard -Header 'P1', 'P2', 'P3' # Specify the header columns to be used
|
||||
|
||||
#>
|
||||
param(
|
||||
$Delimiter,
|
||||
$Header
|
||||
)
|
||||
|
||||
if ($IsWindows) {
|
||||
$osInfo = Get-CimInstance -ClassName Win32_OperatingSystem
|
||||
if ($osInfo.ProductType -eq 1) {
|
||||
$cvtParams = @{
|
||||
Data = Get-Clipboard -Raw
|
||||
}
|
||||
|
||||
if ($Delimiter) {
|
||||
$cvtParams.Delimiter = $Delimiter
|
||||
}
|
||||
|
||||
if ($Header) {
|
||||
$cvtParams.Header = $Header
|
||||
}
|
||||
|
||||
ReadClipboardImpl @cvtParams
|
||||
}
|
||||
else {
|
||||
Write-Error "This command is only supported on the desktop."
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Error "This function is only available on Windows desktop"
|
||||
}
|
||||
}
|
||||
|
||||
function ReadClipboardImpl {
|
||||
param(
|
||||
[Parameter(Mandatory)]
|
||||
[ValidateNotNullOrEmpty()]
|
||||
[String] $data,
|
||||
$Delimiter,
|
||||
$Header
|
||||
)
|
||||
|
||||
if (!$PSBoundParameters.ContainsKey('Delimiter') -and !$PSBoundParameters.ContainsKey('Header')) {
|
||||
try {
|
||||
ConvertFrom-Json $data
|
||||
}
|
||||
catch {
|
||||
$dataLines = @($data -split "`r`n?" | Select-Object -First 1)
|
||||
|
||||
if ($dataLines[0].indexOf(',') -gt -1) {
|
||||
ConvertFrom-Csv $data
|
||||
}
|
||||
else {
|
||||
ConvertFrom-Csv $data -Delimiter "`t"
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
$cvtParams = @{
|
||||
InputObject = $data
|
||||
}
|
||||
|
||||
if ($Delimiter) {
|
||||
$cvtParams.Delimiter = $Delimiter
|
||||
}
|
||||
|
||||
if ($Header) {
|
||||
$cvtParams.Header = $Header
|
||||
}
|
||||
|
||||
ConvertFrom-Csv @cvtParams
|
||||
}
|
||||
}
|
||||
6
PublishToGallery.ps1
Normal file
6
PublishToGallery.ps1
Normal file
@@ -0,0 +1,6 @@
|
||||
$p = @{
|
||||
Name = "ImportExcel"
|
||||
NuGetApiKey = $NuGetApiKey
|
||||
}
|
||||
|
||||
Publish-Module @p
|
||||
37
README.md
37
README.md
@@ -1,14 +1,18 @@
|
||||
# README
|
||||
# PowerShell + Excel = Better Together
|
||||
|
||||
### Donation
|
||||
Automate Excel via PowerShell without having Excel installed. Runs on Windows, Linux and MAC. Creating Tables, Pivot Tables, Charts and much more has just become a lot easier.
|
||||
|
||||
If this project helped you reduce the time to get your job done, let me know.
|
||||
<br/>
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UCSB9YVPFSNCY)
|
||||
[](https://www.powershellgallery.com/packages/ImportExcel) [](https://www.powershellgallery.com/packages/ImportExcel) [](https://github.com/dfinke/ImportExcel/tree/70ab9e46c776e96fb287682d5b9b4b51a0ec3bac/LICENSE.txt)
|
||||
|
||||

|
||||
<br/>
|
||||
|
||||
[](https://www.powershellgallery.com/packages/ImportExcel) [](https://www.powershellgallery.com/packages/ImportExcel) [](https://github.com/dfinke/ImportExcel/tree/70ab9e46c776e96fb287682d5b9b4b51a0ec3bac/LICENSE.txt)
|
||||
Open `ImportExcel` as a remote repo in VS Code, without cloning it.
|
||||
|
||||
[](https://open.vscode.dev/dfinke/importexcel)
|
||||
|
||||
<br/>
|
||||
|
||||
| CI System | Environment | Status |
|
||||
| :--- | :--- | :--- |
|
||||
@@ -17,11 +21,22 @@ If this project helped you reduce the time to get your job done, let me know.
|
||||
| Azure DevOps | Ubuntu | [](https://dougfinke.visualstudio.com/ImportExcel/_build/latest?definitionId=21&branchName=master) |
|
||||
| Azure DevOps | macOS | [](https://dougfinke.visualstudio.com/ImportExcel/_build/latest?definitionId=21&branchName=master) |
|
||||
|
||||
PowerShell Import-Excel -
|
||||
<br/>
|
||||
|
||||
Install from the [PowerShell Gallery](https://www.powershellgallery.com/packages/ImportExcel/).
|
||||
Install from the [PowerShell Gallery](https://www.powershellgallery.com/packages/ImportExcel/).
|
||||
|
||||
This PowerShell Module allows you to read and write Excel files without installing Microsoft Excel on your system. No need to bother with the cumbersome Excel COM-object. Creating Tables, Pivot Tables, Charts and much more has just become a lot easier.
|
||||
```powershell
|
||||
Install-Module -Name ImportExcel
|
||||
```
|
||||
### Donation
|
||||
|
||||
If this project helped you reduce the time to get your job done, let me know, send a coffee.
|
||||
|
||||
<br/>
|
||||
|
||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UCSB9YVPFSNCY)
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
@@ -55,6 +70,10 @@ Plus, wiring the [PowerShell ScriptAnalyzer Excel report](https://github.com/dfi
|
||||
|
||||

|
||||
|
||||
## What's new 7.1.3
|
||||
|
||||
- Changed to `ProviderPath`. Thanks [Trevor Walker](https://github.com/sporkabob)
|
||||
|
||||
## What's new 7.1.2
|
||||
|
||||
- `Get-ExcelFileSummary` - Gets summary information on an Excel file like number of rows, columns, and more
|
||||
|
||||
90
__tests__/Read-Clipboard.tests.ps1
Normal file
90
__tests__/Read-Clipboard.tests.ps1
Normal file
@@ -0,0 +1,90 @@
|
||||
#Requires -Modules Pester
|
||||
# if (-not (Get-command Import-Excel -ErrorAction SilentlyContinue)) {
|
||||
Import-Module $PSScriptRoot\..\ImportExcel.psd1 -Force
|
||||
# }
|
||||
Describe "Read Clipboard" -Tag "Read-Clipboard" {
|
||||
|
||||
It 'Should return $null if it cannot detect data format on the clipboard' {
|
||||
$testData = 'abc'
|
||||
$actual = ReadClipboardImpl $testData
|
||||
$actual.Count | Should -Be 0
|
||||
$actual | Should -BeNullOrEmpty
|
||||
}
|
||||
|
||||
It 'Should return converted csv data' {
|
||||
$testData = @"
|
||||
Region,State,Units,Price
|
||||
West,Texas,927,923.71
|
||||
North,Tennessee,466,770.67
|
||||
East,Florida,520,458.68
|
||||
"@
|
||||
$actual = ReadClipboardImpl $testData
|
||||
$actual.count | Should -Be 3
|
||||
}
|
||||
|
||||
It 'Should return converted tab delimited data' {
|
||||
$testData = @"
|
||||
YEAR PRESIDENT FIRST LADY VICE PRESIDENT
|
||||
2021- Joseph R. Biden Jill Biden Kamala Harris
|
||||
2017-2021 Donald J. Trump Melania Trump Mike Pence
|
||||
2009-2017 Barack Obama Michelle Obama Joseph R. Biden
|
||||
"@
|
||||
$actual = ReadClipboardImpl $testData
|
||||
$actual.count | Should -Be 3
|
||||
}
|
||||
|
||||
It 'Should return converted json data' {
|
||||
$testData = @"
|
||||
[
|
||||
{
|
||||
"YEAR": "2021-",
|
||||
"PRESIDENT": "Joseph R. Biden",
|
||||
"FIRST LADY": "Jill Biden",
|
||||
"VICE PRESIDENT": "Kamala Harris"
|
||||
},
|
||||
{
|
||||
"YEAR": "2017-2021",
|
||||
"PRESIDENT": "Donald J. Trump",
|
||||
"FIRST LADY": "Melania Trump",
|
||||
"VICE PRESIDENT": "Mike Pence"
|
||||
},
|
||||
{
|
||||
"YEAR": "2009-2017",
|
||||
"PRESIDENT": "Barack Obama",
|
||||
"FIRST LADY": "Michelle Obama",
|
||||
"VICE PRESIDENT": "Joseph R. Biden"
|
||||
}
|
||||
]
|
||||
"@
|
||||
$actual = ReadClipboardImpl $testData
|
||||
$actual.count | Should -Be 3
|
||||
}
|
||||
|
||||
It 'Should return converted "|" delimited data' {
|
||||
$testData = @"
|
||||
Region|State|Units|Price
|
||||
West|Texas|927|923.71
|
||||
North|Tennessee|466|770.67
|
||||
East|Florida|520|458.68
|
||||
"@
|
||||
$actual = ReadClipboardImpl $testData -Delimiter '|'
|
||||
$actual.count | Should -Be 3
|
||||
}
|
||||
|
||||
It 'Should return converted data with headers' {
|
||||
$testData = @"
|
||||
West,Texas,927,923.71
|
||||
North,Tennessee,466,770.67
|
||||
East,Florida,520,458.68
|
||||
"@
|
||||
|
||||
$actual = ReadClipboardImpl $testData -Header 'P1', 'P2', 'p3', 'P4'
|
||||
$actual.count | Should -Be 3
|
||||
|
||||
$propertyNames = $actual[0].psobject.Properties.Name
|
||||
$propertyNames[0] | Should -BeExactly 'P1'
|
||||
$propertyNames[1] | Should -BeExactly 'P2'
|
||||
$propertyNames[2] | Should -BeExactly 'p3'
|
||||
$propertyNames[3] | Should -BeExactly 'P4'
|
||||
}
|
||||
}
|
||||
10
changelog.md
Normal file
10
changelog.md
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
# v7.2.1
|
||||
|
||||
- Improve auto-detection of data on the clipboard
|
||||
# v7.2.0
|
||||
|
||||
- Added `Read-Clipboard` support for Windows. Read text from clipboard. It can read CSV or JSON. Plus, you can specify the delimiter and headers.
|
||||
|
||||
### Check out the video
|
||||
<a href="https://youtu.be/dv2GOH5sbpA"><img src="https://img.youtube.com/vi/dv2GOH5sbpA/0.jpg" width="400"></a>
|
||||
Reference in New Issue
Block a user