Skip to content

Instantly share code, notes, and snippets.

@tatarize
Last active April 10, 2023 21:19
Show Gist options
  • Save tatarize/875b870ff5cf96073bc9d895e8bf1b9f to your computer and use it in GitHub Desktop.
Save tatarize/875b870ff5cf96073bc9d895e8bf1b9f to your computer and use it in GitHub Desktop.

Spreadsheet-to-Keystrokes Script

This script is designed to automate the process of inputting data from a spreadsheet into a program that only allows input one field at a time. By reading an exported file and simulating keystrokes, the script inputs each cell value into the corresponding field in the program.

The script is simple and easy to use, with no complicated setup or configuration required. All you need to do is prepare the data in a tab-delimited text file, open the order entry system, and drag and drop the file onto the script, then select the first field in the program. The script will wait three seconds then automatically input the data for you.

Prerequisites

We are assuming you are running Microsoft Windows with VBScript (it comes standard). If this is inaccurate, a python example is also provided.

Assumptions

We are assuming that you can press tab to move to the next field, and that pressing enter will move to the next line.

Usage

  1. Open your spreadsheet program with the data formatted in the same order as the fields.
  2. Export the data as a text file. For example, in Microsoft Excel, Go to File -> Save As, and select text file. You do not want a string delimiter, and you want Tab delimited export.
  3. Place the script on your desktop with the csv file.
  4. Run the script by dragging the data-text file on to the sendkeys.vbs file (or python for non-windows environments).
  5. The script pauses for three seconds, use this time to select the first field in the program.
  6. Watch as it inputs the spreadsheet data into the program.

Exporting the file will give you 1 tab per cell. So move the cells over to correctly give you the number of tabs.

import time
import sys
import pyautogui
time.sleep(3)
file_name = sys.argv[1]
with open(file_name, 'r') as f:
contents = f.read()
pyautogui.typewrite(contents)
Dim WshShell, file_name, fso, ts, contents
WScript.Sleep 3000
file_name = WScript.Arguments(0)
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(file_name)
contents = ts.ReadAll
ts.Close
Set WshShell = CreateObject("WScript.Shell")
WshShell.SendKeys contents
@tatarize
Copy link
Author

https://gist.github.com/tatarize/37f664e0240bc1548ad3a43c7acc2021

For the updated version:

{wait 500}$1{tab}$2{enter}$3{tab}{tab}$6{tab}{tab}{tab}{tab}{tab}{tab}

Should be the needed filename/ordering, assuming the final part needs 6 tabs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment