未加星标

Convert Excel Sheet to Json with PowerShell

字体大小 | |
[系统(windows) 所属分类 系统(windows) | 发布者 店小二04 | 时间 2016 | 作者 红领巾 ] 0人收藏点击收藏

This script converts a sheet from an Excel Workbook to a JSON file.

Why?

This is useful as JSON files allow all sorts of things that would break CSV files, like commas.


Convert Excel Sheet to Json with PowerShell

This would not be a pleasant CSV file to deal with:

Hostname,IPAddress,OperatingSystem
DC01,10.0.0.11,10.0.0.15,windows Server 2012 R2

This would look something like the following if parsed as a CSV file:

Hostname: DC01
IPAddress: 10.0.0.11
OperatingSystem: 10.0.0.15
?: Windows Server 2012 R2

Not ideal. JSON will display it like this:

[
{
"Hostname": "DC01",
"IPAddress": "10.0.0.11,10.0.0.15",
"OperatingSystem: "Windows Server 2012 R2"
}
]

It also allows for much more complexity than this, making JSON a great format for working with complicated sets of data. This script barely scratches the surface.

Requirements Windows PowerShell (v5.1 tested, please let me know what versions you’ve got it working on!) Microsoft Excel (2016 tested, as with PowerShell, please let me know what versions you’ve got it working on!) Usage

If you provide no input beyond the name of a spreadsheet, the script will confirm only sheet exists, and output the JSON file into the current directory:

Convert-ExcelSheetToJson -InputFile MyExcelWorkbook.xlsx

You can use the -SheetName parameter to specify a sheet name to export:

Convert-ExcelSheetToJson -InputFile MyExcelWorkbook.xlsx -SheetName Sheet1

Or, you can specify the output file as well:

Convert-ExcelSheetToJson -InputFile MyExcelWorkbook.xlsx -OutputFileName MyConvertedFile.json -SheetName Sheet2

The script also accepts an input file from pipeline:

Get-Item MyExcelWorkbook.xlsx | Convert-ExcelSheetToJson -OutputFileName MyConvertedFile.json -SheetName Sheet2 Where to get it

You can find the script on:

本文系统(windows)相关术语:三级网络技术 计算机三级网络技术 网络技术基础 计算机网络技术

分页:12
转载请注明
本文标题:Convert Excel Sheet to Json with PowerShell
本站链接:http://www.codesec.net/view/482887.html
分享请点击:


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(windows) | 评论(0) | 阅读(28)