Last active
December 20, 2023 04:20
-
-
Save kinuasa/42a4cb780c9d6b308c64be871c74f387 to your computer and use it in GitHub Desktop.
PDFtkを使ってPDFフォームへのデータ入力を自動化するPower Automate for desktopフロー(動作確認:バージョン 2.39 ) 関連Webサイト:https://note.com/kinuasa/n/nc93aefd55e87
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SET PdfFolderPath TO $'''C:\\Test\\受領書''' | |
/# ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆ | |
リストファイル読み込み | |
☆★☆★☆★☆★☆★☆★☆★☆★☆★☆#/ | |
Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''%PdfFolderPath%\\受領書発行リスト.xlsx''' Visible: True ReadOnly: True Instance=> ExcelInstance | |
Excel.SetActiveWorksheet.ActivateWorksheetByName Instance: ExcelInstance Name: $'''受領書発行リスト''' | |
Excel.GetFirstFreeColumnRow Instance: ExcelInstance FirstFreeColumn=> FirstFreeColumn FirstFreeRow=> FirstFreeRow | |
Excel.ReadFromExcel.ReadCells Instance: ExcelInstance StartColumn: $'''A''' StartRow: 1 EndColumn: FirstFreeColumn - 1 EndRow: FirstFreeRow - 1 ReadAsText: True FirstLineIsHeader: True RangeValue=> ExcelData | |
Excel.CloseExcel.Close Instance: ExcelInstance | |
/# ☆★☆★☆★☆★☆★☆★☆★☆★☆★☆ | |
PDFフォーム書き込み後別名保存 | |
☆★☆★☆★☆★☆★☆★☆★☆★☆★☆#/ | |
File.GetTempPath TempFile=> TempFile | |
XML.WriteXmlToFile.WriteToFile File: TempFile Xml: $'''<?xml version=\"1.0\" encoding=\"UTF-8\"?> | |
<xfdf xmlns=\"http://ns.adobe.com/xfdf/\" xml:space=\"preserve\"> | |
<fields> | |
<field name=\"日付\"> | |
<value>(日付)</value> | |
</field> | |
<field name=\"宛先\"> | |
<value>(宛先)</value> | |
</field> | |
<field name=\"金額\"> | |
<value>(金額)</value> | |
</field> | |
<field name=\"但し書き\"> | |
<value>(但し書き)</value> | |
</field> | |
</fields> | |
</xfdf>''' Encoding: XML.FileEncoding.UTF8 | |
XML.ReadFromFile File: TempFile Encoding: XML.FileEncoding.UTF8 XmlDocument=> XmlDocument | |
LOOP FOREACH CurrentItem IN ExcelData | |
XML.SetElementValue Document: XmlDocument XPathQuery: $'''//*[local-name()=\'field\' and namespace-uri()=\'http://ns.adobe.com/xfdf/\' and @name=\'日付\']/*[local-name()=\'value\']''' ElementValue: CurrentItem['日付'] | |
XML.SetElementValue Document: XmlDocument XPathQuery: $'''//*[local-name()=\'field\' and namespace-uri()=\'http://ns.adobe.com/xfdf/\' and @name=\'宛先\']/*[local-name()=\'value\']''' ElementValue: CurrentItem['宛先'] | |
XML.SetElementValue Document: XmlDocument XPathQuery: $'''//*[local-name()=\'field\' and namespace-uri()=\'http://ns.adobe.com/xfdf/\' and @name=\'金額\']/*[local-name()=\'value\']''' ElementValue: CurrentItem['金額'] | |
XML.SetElementValue Document: XmlDocument XPathQuery: $'''//*[local-name()=\'field\' and namespace-uri()=\'http://ns.adobe.com/xfdf/\' and @name=\'但し書き\']/*[local-name()=\'value\']''' ElementValue: CurrentItem['但し書き'] | |
XML.WriteXmlToFile.WriteToFile File: TempFile Xml: XmlDocument Encoding: XML.FileEncoding.UTF8 | |
Text.Replace Text: CurrentItem['宛先'] TextToFind: $'''[<>:\\\"\\/\\\\\\|\\?\\*]''' IsRegEx: True IgnoreCase: False ReplaceWith: $'''%''%''' ActivateEscapeSequences: False Result=> PdfFileName | |
System.RunApplication.RunApplicationAndWaitToComplete ApplicationPath: $'''C:\\Program Files (x86)\\PDFtk\\bin\\pdftk.exe''' CommandLineArguments: $'''\"%PdfFolderPath%\\受領書.pdf\" fill_form \"%TempFile.FullName%\" output \"%PdfFolderPath%\\作成済み\\%PdfFileName%.pdf\" need_appearances''' WorkingDirectory: PdfFolderPath WindowStyle: System.ProcessWindowStyle.Normal Timeout: 0 ProcessId=> AppProcessId ExitCode=> AppExitCode | |
END | |
File.Delete Files: TempFile.FullName |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment