I have a code to import data from csv file to iMacros and the part at which i am struck now is the iMacros is printing the values of the excel row wise and i want it to be printed in colulmn wise. I Get this error though I have used the {keyword !Col1}}
VERSION BUILD=10.4.28.1074
'Uses a Windows script to submit several datasets to a website, e. g. for filling an online database
' Specify input file (if !COL variables are used, IIM automatically assume a CSV format of the input file
'CSV = Comma Separated Values in each line of the filE
TAB T=1
SET !DATASOURCE C:\Users\Arun\Desktop\Book2.csv
'Start at line 2 to skip the header in the file
SET !LOOP 1
'Increase the current position in the file with each loop
SET !DATASOURCE_LINE {{!LOOP}}
' Fill web form
URL GOTO=https://docs.google.com/forms/d/e/1FAIpQLSdDj_Rrydyd1ukk56tOL92LAu-jE9qfi1GwsAUTT1gviZNG7w/viewform?c=0&w=1
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:mG61Hd ATTR=NAME:emailAddress CONTENT={{!COL1}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.2005620554 CONTENT={{!COL2}}
TAG POS=1 TYPE=INPUT:EMAIL FORM=ID:mG61Hd ATTR=NAME:entry.1045781291 CONTENT={{!COL3}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.1065046570 CONTENT={{!COL4}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.1166974658 CONTENT={{!COL5}}
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:mG61Hd ATTR=NAME:entry.839337160 CONTENT={{!COL6}}
'Note * is used to ignore leading and trailing blanks that could be in the input data
'
'The precent (%) symbol is used to select the stateid by VALUE as defined in the website select statement and not by its index.
'
'The string ($) symbol is used to select the country by TEXT, not by its index.
'Index would be the position of an entry in the combo box list, e. g. 161 for United States
Take a look at one of the acceptable workarounds given below. Let's suppose that your CSV file doesn't contain any exclamation marks and has a comma as the datasource delimiter.
' fake delimiter
SET !DATASOURCE_DELIMITER "!"
' real delimiter
SET rd ","
SET !DATASOURCE Address.csv
SET !DATASOURCE_LINE 2
SET row2 EVAL("'{{!COL1}}'.split('{{rd}}')[{{!LOOP}}-1];")
SET !DATASOURCE_LINE 3
SET row3 EVAL("'{{!COL1}}'.split('{{rd}}')[{{!LOOP}}-1];")
SET !DATASOURCE_LINE 4
SET row4 EVAL("'{{!COL1}}'.split('{{rd}}')[{{!LOOP}}-1];")
' ...
PROMPT {{row2}}<BR>{{row3}}<BR>{{row4}}
Play this macro in loop mode. It must work in 'iMacros add-on' for Firefox or Chrome. I think my tip should help you.
Related
Essentially, I am taking a column of data from an excel file and breaking it up into small groups. So:
10
20
30
40
50
60
etc...
broken up into:
"10, 20, 30, 40"
"50, 60, 70, 80"
etc
Using AppleScript, I assume you would nest loops, something along the lines of:
tell application "TextEdit"
set theText to text of front document as string
set myParas to every paragraph of theText
set myNum to the number of paragraphs of theText
repeat myNum times
repeat 4 times
end repeat
end repeat
end tell
I'm going to be updating data once a month that comes through as a column of numbers and text. I can strip out all the text easy enough, just would like to know the principle of how to break up or merge the paragraphs into smaller blocks.
For many complicated reasons, I am stuck with AppleScript and textEdit, so other alternates (such as massaging with javascript or textWrangler or whatever) is not an option.
Also, maybe textEdit can do this on it's own but the script I will be using will have lots of other operations based on the above result, so AppleScript has to do all the heavy lifting.
You can specify the step size in a repeat loop, so you could do something like:
tell application "TextEdit" to set theText to text of front document
set paras to paragraphs of theText
set step to 4 -- number of items in a group
repeat with i from 1 to (count paras) by step
try
buildString(items i thru (i + step - 1) of paras)
on error errmess number errnum -- index out of bounds
log errmess
if errnum is -128 then error number -128 -- quit
buildString(items i thru -1 of paras) -- just to the end
end try
end repeat
to buildString(someList)
set tempTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to ", "
set output to someList as text
set AppleScript's text item delimiters to tempTID
display dialog output -- show it
return output
end buildString
I am using the values from Microsoft Excel for Mac 2016 and photoshop CC 2017 to automate creating the text of a person's name + their ID number along with their associated photo within Photoshop. When I go to change the text:
tell application "photoshop cc 2017"
--some code
set font of text object of art layer 1 to "GothamRounded-Bold"
Part of the value specifically, the last name gets cut off. My question is: Is this a known bug? Or what am I doing wrong? Here is the sourcing of the cells from Excel:
tell application "Microsoft Excel"
--this gets the full name of a person from a cell
set fullname to value of column 1 of row u of sheet 1 of active workbook as text
--this gets the person's id number
set personid to value of column 2 of row u of sheet 1 of active workbook as text
--this removes the .0 from the excel value
set num to first character of personid
--this combines the two to make the caption
set idfullname to num & space & fullname
For instance,
what should be "3 Will Morris", gets reformatted as "3 Will". However, if I leave it in the default font: Myriad Pro, the full name and number get sourced perfectly. I've also tried using some delays, to no avail. Any suggestions would be greatly appreciated.
I want to highlight the strings before and after '--'. Example good -- bad here i want to highlight good and bad. when ever the -- is comes then before and after the strings are become highlight. Is it possible.
Let's assume you have the following text in a field "mytext":
This text comes before -- this text comes after.
LiveCode (as most applications) does not allow discontinuous selections, so the 'select' command only works on continuous runs of text.
select word 1 to 3 of fld "mytext"
But you can simulate selection highlighting by setting the backgroundColor property of separate text runs:
put wordOffset("--",fld "mytext") into tWordIndex
set the backgroundColor of word 1 to tWordIndex - 1 of fld "mytext" to the hiliteColor
set the backgroundColor of word tWordIndex + 1 to -1 of fld "mytext" to the hiliteColor
Of course you can use any valid text chunk expression in the two 'set' statements, depending on what part of the text preceding and following the " -- " you want to "highlight".
To clear the backgroundColor from the field do this:
set the backgroundColor of char 1 to -1 of fld "mytext" to empty
The tab delimited text file that i am trying to import looks like this (4 fields, Field 3 is multiline)... and about 100,000 rows of data:
Below is just a sample... but please give a general solution where the multiline text could be in multiple fields... like say fld3, fld6 and fld7 of a total 10 fields.
Field 1 <tab> Field 2 <tab> Field 3.1
Field 3.2
Field 3.3<tab>Field 4
Field 1 <tab> Field 2 <tab> Field 3.1
Field 3.2
Field 3.3<tab>Field 4
Field 1 <tab> Field 2 <tab> Field 3.1
Field 3.2
Field 3.3<tab>Field 4
But, actually when it was was exported to the above text file from the database... it had 3 lines of actual... that looked like this... 4 Fields. Field 3 is multiline.
Field 1 <tab> Field 2 <tab> Field 3.1(CR)Field 3.2(CR)Field 3.3<tab>Field 4
Field 1 <tab> Field 2 <tab> Field 3.1(CR)Field 3.2(CR)Field 3.3<tab>Field 4
Field 1 <tab> Field 2 <tab> Field 3.1(CR)Field 3.2(CR)Field 3.3<tab>Field 4
where is Tab, and (CR) is carriage return. When importing the tab delimited text file into Excel, i want all 3 lines in Field 3 (Field 3.1, Field 3.2 and Field 3.3) be in one cell, but multiline. So basically i want excel to ignore carriage return with in Field 3. How do i do that???
For your info... The text fields are NOT in double quotes... Please tell me what is the best way to convert the plain text tab delimited text file to Excel 4 columns like this:
does anyone know of a solution. it would be greatly appreciated.
Additional Comment
Please note that what I have is only the resulting Text File... as shown on the very top of this message.... with text "Field 3.2" in Line 2, "Field 3.3" and "Field 4" in Line 3 with separating them.
Also... not necessarily Field 3 will be always multiline... it may be multiline with 2, 3 or more lines... or even nothing or single line. Field 3 will never have a with in itself.
Additional Comments with Sample File for someone to Test - Update 25Jun2013 09:05 UTC
pls note copy paste will not work.. as tabs are lost.. you will have to add it yourselves.
File with Quotes around the multiline field:
f1hdr f2hdr f3hdr
f11 "f12
part of f12" f13
f21 "f22part of f22
part f22
part f22
part f22" f23
f31 "f32aaa" f33
f41 "f42bbb" f43
File without Quotes around the multiline field:
f1hdr f2hdr f3hdr
f11 f12
part of f12 f13
f21 f22part of f22
part f22
part f22
part f22 f23
f31 f32aaa f33
f41 f42bbb f43
Open the file with quotes in Excel... Open File Dialog... Hold Shift... and Click Open.. show the file nicely with multiline.
But opening the file without quotes.. doesn't work.. it breaks.
I have no idea why holding shift works. I knew of this from here: Import multiline csv files into Excel internationally
Now.. it still remains to be answered...
1) How to add the quotes around the text file in easier fashion before importing to Excel... Why Shift Open works? What if I want to control each delimited columns using text import wizard?
2) How to add the quotes around the fields by default in SQL Server 2015. This is in addition to above Q1. We still need a solution where we can't export the file again. But, for any new export.. someone could user the answer from Q2.
3) Any other methods which may be even simpler?
Here's what I came up with. If you can guarantee the last column will never have a carriage return, then this should work ok.
What this does is read the text file in VBA and brings it into the workbook. You have to specify how many fields to expect (in the test scenario, 4). This is so it can keep track of when it's ready to start a new row.
It's a little confusing because of the carriage returns, but step through the code and I think you'll be able to figure it out. Let me know if you have any questions.
Option Explicit
Const fieldCount = 4
Sub import()
Application.ScreenUpdating = False
Dim fileNumber As Integer
Dim data As String
Dim curCol As Long, curRow As Long
Dim dataCols As Long
Dim i As Long
Dim sh As Excel.Worksheet
Dim arr() As String
Dim hasCarriageReturn As Boolean
fileNumber = FreeFile()
Open "C:\test.txt" For Input As #fileNumber
curCol = 1
curRow = 1
Set sh = ThisWorkbook.Worksheets("Sheet1")
While Not EOF(fileNumber)
' if we reached the "correct" last column, then move to next row
If (curCol > fieldCount) Then
curCol = 1
curRow = curRow + 1
hasCarriageReturn = False
End If
Line Input #fileNumber, data
arr = Split(data, vbTab)
dataCols = UBound(arr)
If (dataCols = fieldCount - 1) Then
' full row has no carriage returns
hasCarriageReturn = False
For i = 0 To dataCols
sh.Cells(curRow, curCol).Value = arr(i)
curCol = curCol + 1
Next
ElseIf (dataCols = 0 And hasCarriageReturn = True) Then
' if there is only 1 value in the row, append it to the current column
sh.Cells(curRow, curCol - 1).Formula = sh.Cells(curRow, curCol - 1).Formula & Chr(10) & arr(0)
ElseIf (dataCols = 0 And hasCarriageReturn = False) Then
' carriage return begins in the first field
sh.Cells(curRow, curCol).Formula = sh.Cells(curRow, curCol).Formula & Chr(10) & arr(0)
curCol = curCol + 1
hasCarriageReturn = True
ElseIf (hasCarriageReturn) Then
' append first item to field 3, then rest goes in other columns
sh.Cells(curRow, curCol - 1).Formula = sh.Cells(curRow, curCol - 1).Formula & Chr(10) & arr(0)
For i = 1 To dataCols
sh.Cells(curRow, curCol).Value = arr(i)
curCol = curCol + 1
Next
hasCarriageReturn = False
Else
' process row and note that it has carriage returns
For i = 0 To dataCols
sh.Cells(curRow, curCol).Value = arr(i)
curCol = curCol + 1
Next
hasCarriageReturn = True
End If
Wend
Application.ScreenUpdating = True
End Sub
for the time being what i did was.. used gvim (same like 'vi') and replaced all
\t with "\t" (this is to have the fields wrapped in quotes...then.. e.g. :%s/\t/"\t"/g
\r\n with "\r (this is to have the real end of line to have a quote in the end... then e.g. :%s/\r\n/"\r/g
line start ^20 with ^"20 (this is for beginning of line first field in quotes... the line starts with 2013... so replacing with with "2013...) e.g. :%s/^2013/"2013/g
saved the file.. as file.txt
Open Excel
Select the File... and hold shift and click "open" (courtesy of: Import multiline csv files into Excel internationally)
All fields are nicely imported (in General Format) and multilines are processed correctly and put in correct fields.
This is truly wonderful... However with 1 caveat.
Some of the fields are text but with leading 0s.. e.g. '000327511' or '032'.. and i wanted the leading zero intact.. without excel converting to number. I can't preserve the leading 0 using the "shift + open" method.
If I use the normal text import wizard... then the multiline cannot be made to work.. catch 22 situation. Pity!!!
However.. this is a nice temporary solution until someone can find a permanent fix all one.
No code involved at all... just a few typing to replace with vi and click.. click..
Wish someone can improve this method slightly.
Import to Libre Office Calc. Libre Office Calc does not interpret line breaks in between two tabs as a next row command. The content after line break will appear in the next line within the same cell. Save the spreadsheet as ms excel xls/xlsx format.
Ignore the warning that pops up before it is saved at your own risk and/or proof-read the same spreadsheet after import. During the proof read make sure you're using Excel.
I have a field "data" with Unicode text in it which displays properly. I want to copy a chunk of it and put it into another field called "someData".
I tried the following script in a button
on mouseUp
put word 2 of line 1 of the unicodeText of field "data" into t
set the unicodeText of field "someData" to t
end mouseUp
Non Unicode text displays fine in the field "someData" but Unicode text does not.
You could probably get away with UTF8 encoding then parsing then re-encoding
on mouseUp
put word 2 of line 1 of uniDecode(the unicodeText of field "data","UTF8") into t
set the unicodeText of field "someData" to uniEncode(t,"UTF8")
end mouseUp
on mouseUp
put unicode the unicodeText of word 2 of field "data" into field "someData"
end mouseUp
should work.
Marek
Here is another one-liner you can test:
set the unicodeText of field 2 to the unicodeText of word 2 of field 1
I am no expert in unicode, but there may be a clue in that LC treats most unicode stuff as properties. Because of this, one may set, say, the uniCodeText of a field:
set the unicodeText of fld 1 to "U+400"
But one cannot set that property, or any property, in a variable. Consider the following two handlers. It is assumed there exist two fields, "fld 1" and "fld 2".
on mouseUp
set the useUnicode to "true"
set the unicodeText of fld 1 to "U+400" -- an example
set the unicodeText of fld "f2" to the uniCodeText of fld 1
end mouseUp
on mouseUp
set the useUnicode to "true"
set the unicodeText of fld 1 to "U+400"
put fld 1 into temp
set the unicodeText of fld "f2" to temp
end mouseUp
The first works, the second does not. In your example, you try to put displayed uniCode into a variable. I don't think you can "put" that sort of thing. You have to set a property.
Now that said, check out the "put uniCode" command. This might get around the property thing. Write back if it does.
Craig Newman