Skip to content

Instantly share code, notes, and snippets.

View kinuasa's full-sized avatar

@kinuasa kinuasa

View GitHub Profile
@kinuasa
kinuasa / FullWidthToHalfWidth.ps1
Created October 19, 2023 07:03
全角文字を半角に変換するPowerShellスクリプト
Add-Type -AssemblyName 'Microsoft.VisualBasic'
$str = [Microsoft.VisualBasic.Strings]::StrConv('令和5年10月19日 01:23:45', [Microsoft.VisualBasic.VbStrConv]::Narrow, 1041)
Write-Output $str
@kinuasa
kinuasa / DisplayDateInJapaneseCalendar.robin
Last active October 18, 2023 02:32
日付を和暦で表示するPower Automate for desktopフロー(令和対応) 関連ポスト:https://twitter.com/kinuasa/status/1714469344816894202
/# ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
日付を和暦で表示するフロー
Power Automate for desktop バージョン 2.37.00181.23279 で動作確認
☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#/
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
Scripting.RunPowershellScript.RunPowershellScript Script: $'''$ci = New-Object System.Globalization.CultureInfo(\"ja-JP\", $true)
$ci.DateTimeFormat.Calendar = New-Object System.Globalization.JapaneseCalendar
Write-Output ([DateTime]\"%CurrentDateTime%\").ToString(\"ggy年M月d日 HH:mm:ss\", $ci)''' ScriptOutput=> PowershellOutput ScriptError=> ScriptError
Display.ShowMessageDialog.ShowMessage Message: PowershellOutput.Trimmed Icon: Display.Icon.None Buttons: Display.Buttons.OK DefaultButton: Display.DefaultButton.Button1 IsTopMost: True ButtonPressed=> ButtonPressed
@kinuasa
kinuasa / DisplayDateInJapaneseCalendar.ps1
Created October 18, 2023 01:59
日付を和暦で表示するPowerShellスクリプト(令和対応)
$ci = New-Object System.Globalization.CultureInfo("ja-JP", $true)
$ci.DateTimeFormat.Calendar = New-Object System.Globalization.JapaneseCalendar
Write-Output ([DateTime]"2023/01/11 1:23:45").ToString("ggy年M月d日 HH:mm:ss", $ci)
@kinuasa
kinuasa / GetPdfCheckboxValue.ps1
Created October 12, 2023 07:22
PdfSharpを使ってPDF上のチェックボックスがチェックされているかを取得するPowerShellスクリプトです。 関連Webサイト:https://powerusers.microsoft.com/t5/Power-Automate-Desktop/How-to-find-a-check-box-is-checked-or-not/td-p/2394252
[void][Reflection.Assembly]::LoadFile("C:\System\Lib\PdfSharp.dll")
$doc = [PdfSharp.Pdf.IO.PdfReader]::Open("C:\Test\PDF\checkbox.pdf", [PdfSharp.Pdf.IO.PdfDocumentOpenMode]::ReadOnly)
$fields = $doc.AcroForm.Fields
$names = $fields.Names
for($i=0; $i -lt $names.Count; $i++){
$field = $fields[$names[$i]]
if($field -is [PdfSharp.Pdf.AcroForms.PdfCheckBoxField]){
Write-Output("Name:{0}, Checked:{1}" -f $field.Name, $field.Checked)
}
}
@kinuasa
kinuasa / GetUserInputSample.ts
Last active October 12, 2023 01:04
実行時にユーザーからの入力を取得するOffice スクリプトです。 関連記事:https://www.ka-net.org/blog/?p=15946
/**
* ユーザー入力のサンプルスクリプトです。
* @param food リストに追加する食べ物を選択します。
* @param price 食べ物の価格を入力します。既定値:99円
* @param memo 備考を入力します。
* @author kinuasa
*/
function main(workbook: ExcelScript.Workbook,
food: "Potato" | "Garlic" | "Tomato" | "Green pepper",
price: number = 99,
Dim ps
Set ps = GetObject("winmgmts:Win32_ProcessStartup")
ps.ShowWindow = 0
GetObject("winmgmts:Win32_Process").Create "PowerShell -Command ""Add-Type -AssemblyName 'Microsoft.VisualBasic';[Microsoft.VisualBasic.Interaction]::MsgBox('こんにちは、世界');""", , ps
SET PDFFolderPath TO $'''C:\\Test\\PDF\\請求書'''
/# ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
顧客名取得
☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★#/
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Test\\Excel\\顧客リスト.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''顧客リスト'''
Excel.ReadFromExcel.ReadCell Instance: ExcelInstance StartColumn: $'''A''' StartRow: 2 ReadAsText: False CellValue=> ExcelData
Excel.CloseExcel.Close Instance: ExcelInstance
/# ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★☆★
請求書の顧客名入力後ブックを保存して閉じる
@kinuasa
kinuasa / CreateQRcodes.ps1
Created September 7, 2023 07:19
QRCoderを使ってQRコードを作成するPowerShellスクリプト
# QRCoder( https://github.com/codebude/QRCoder )を使ってQRコードを作成するPowerShellスクリプト
[void][System.Reflection.Assembly]::LoadFile("C:\System\Lib\QRCoder.dll")
$qrGenerator = New-Object QRCoder.QRCodeGenerator
$qrCodeData = $qrGenerator.CreateQrCode("https://www.google.com/search?q=こんにちは", [QRCoder.QRCodeGenerator+ECCLevel]::Q)
$qrCode = New-Object QRCoder.QRCode($qrCodeData)
$qrCodeImage = $qrCode.GetGraphic(5, "#000000", "#ffffff", $true)
#画像ファイルとして保存
#$qrCodeImage.Save("C:\Test\PNG\QR.png")
@kinuasa
kinuasa / AddPdfDropdownItems.vb
Last active September 5, 2023 01:50
Acrobatを使ってPDFのドロップダウンリストに項目を追加するVBAマクロ 関連記事:https://www.ka-net.org/blog/?p=15855
Option Explicit
'Acrobatを使ってPDFのドロップダウンリストに項目を追加するVBAマクロ
'参考:https://www.ka-net.org/blog/?p=6637
Public Sub Sample_AddDropdownItems()
Const PDSaveFull = &H1
Dim app As Object
Set app = CreateObject("AcroExch.App")
Dim avdoc As Object
@kinuasa
kinuasa / Modules.DialogSample.cs
Last active August 22, 2023 05:29
Power Automate for desktopのカスタム アクションで入力パラメーターとしてダイアログを使ってファイルやフォルダーを指定する方法 関連記事:https://www.ka-net.org/blog/?p=15796
using System;
using System.IO;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Attributes;
using Microsoft.PowerPlatform.PowerAutomate.Desktop.Actions.SDK.Types;
namespace Modules.DialogSample
{
[Action(Id = "Action1", Order = 1)]
[Throws("ActionError")]