Network Automation Software We are currently migrating this forum
over to our HelpSystems domain. Please
post all new threads in our new
HelpSystems Community Portal.
Post to the HelpSystems Forum
You are not currently logged on. You must be logged on in order to post. Log on
Or Create a new account
AutoMate Discussion
Decrease font size
Increase font size
Topic Title: Copy data from file and paste to excel
Topic Summary:
Created On: 05/31/2012 08:13 AM
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
View similar topics View similar topics
View topic in raw text format. Print this topic.
 05/31/2012 08:13 AM
User is offline View Users Profile Print this message

Author Icon
Luiz FelipeAlcoforado
Student (5-19 posts)

Posts: 7
Joined: 05/31/2012

Hi,

I have some .txt files that I want to paste to excel.

The problem is that before I paste the data to excel, I want it to find the first empyt row.


I am not sure if I was clear, but if you need any other information, I will be here.



 Category Survey
 06/01/2012 11:32 AM
User is offline View Users Profile Print this message

Author Icon
Ricardo Castaneda
HelpSystems

Posts: 3424
Joined: 01/11/2008

Hi Luiz,

Would it be possible to provide an example of what the .txt will look like and what you would like the result to be?

 Category Survey


-------------------------

Ricardo Castaneda | Principal Support Analyst
AutoMate | Division of HelpSystems
HelpSystems, LLC | T: +1.213.738.1700
 06/01/2012 11:54 AM
User is offline View Users Profile Print this message

Author Icon
Luiz FelipeAlcoforado
Student (5-19 posts)

Posts: 7
Joined: 05/31/2012

Hi,

 

Follow attached one example of .txt file...

I want to insert each value in one columm of the excel...like for example:

Customer : XXXX
Quantity : 10000

 

XXXX goes to cell A1

10000 goes to cell B1

 

Next file that the Automate will import should see that cells A1 and B1 are not empyt and fill the new values on cell A2 and B2 and so on.

 

Thanks a lot for your support.



 Category Survey


InputFile.txt
InputFile.txt  (0 KB)

 06/04/2012 11:23 PM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

Luiz Felipe,
you can set the cursor on the first empty row with keystrokes as below.
The selected cell is then column A on the first empty row, and you can paste or type your data in there as in my example.

 Category Survey
AutoMate 7 version:
Windows version:



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 06/05/2012 07:30 AM
User is offline View Users Profile Print this message

Author Icon
Luiz FelipeAlcoforado
Student (5-19 posts)

Posts: 7
Joined: 05/31/2012

Hello Jean,

Thanks a lot for your great support...

I understood this part, but how do I open the .txt file and copy the exact value that I need and them paste to the Excel Row?

 



 Category Survey
 06/05/2012 08:36 AM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

Using find with regular expressions to parse the header would do it as below, assuming the file is read into a variable

 Category Survey
AutoMate 7 version:
Windows version:



Task Steps: (Right click, Select All, Copy to copy to the clipboard. Steps can then be pasted into the AutoMate Task Builder)


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 06/05/2012 08:44 AM
User is offline View Users Profile Print this message

Author Icon
Luiz FelipeAlcoforado
Student (5-19 posts)

Posts: 7
Joined: 05/31/2012

sorry to ask you that so many questions Jean...I am unexperienced  in Automate.

If for example I have many TXT files in a folder with this same structure...

Is that possible to load file by file on the hdr variable?



 Category Survey
 06/05/2012 08:51 AM
User is offline View Users Profile Print this message

Author Icon
Luiz FelipeAlcoforado
Student (5-19 posts)

Posts: 7
Joined: 05/31/2012

Hi Jean,

I could solve it by using this code:

 

<AMVARIABLE NAME="File_Name">C:\Vivo_Automate\Input Files</AMVARIABLE>
<AMVARIABLE NAME="Linha">2</AMVARIABLE>
<AMVARIABLE NAME="Campo_Customer"></AMVARIABLE>
<AMVARIABLE NAME="Campo_Quantity"></AMVARIABLE>
                    <!--  -->
<!-- Loop até importar todos os arquivos da pasta -->
<AMLOOP TYPE="FOLDER" FOLDER="C:\Vivo_Automate\Input Files\" RESULTVARIABLE="File_Name">
                    <!--  -->
<AMEXCELOPENWORKBOOK WORKBOOK="C:\Vivo_Automate\Planilha\Inputs_Vivo.xls" />
                    <!--  -->
     <AMFILESYSTEM ACTIVITY="read_file" FILE="%File_Name%" RESULTVARIABLE="Campo_Quantity" MAXBYTES="4" POSITION="164" NEWPOSITIONVARIABLE="Campo_Quantity" BYTESVARIABLE="Campo_Quantity" />
     <AMFILESYSTEM ACTIVITY="read_file" FILE="%File_Name%" RESULTVARIABLE="Campo_Customer" MAXBYTES="4" POSITION="147" NEWPOSITIONVARIABLE="Campo_Customer" BYTESVARIABLE="Campo_Customer" />
               <!--  -->
     <AMINPUT KEYSTROKES="{CTRL}{HOME}{CTRL}{DOWN}{DOWN}" LOCKKEYBOARD="YES" />
     <!--  -->
     <AMINPUT>%Campo_Customer%{TAB}%Campo_Quantity%{ENTER}</AMINPUT>
     <!--  -->
<AMEXCELCLOSEWORKBOOK />
          <!--  -->
</AMLOOP>



 Category Survey
 06/05/2012 10:15 AM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

Luiz,
your solution is quite correct.
It relies on the fact that the quantity and customer data are in a fixed position.
My earlier proposal with FINDTEXT and regexes was yielding the same result even if the file format changes slightly, or the length of the data is variable (I see you assume it is always 4, but I'm pretty sure it may vary, as in your sample the quantity is 10000).

Also you better open the Excel before the loop, and close it after the loop end, so that it happens only once, and runs faster.

 Category Survey
AutoMate 7 version:
Windows version:


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 06/05/2012 10:39 AM
User is offline View Users Profile Print this message

Author Icon
Luiz FelipeAlcoforado
Student (5-19 posts)

Posts: 7
Joined: 05/31/2012

Thanks a lot for your advise Jean.

I will follow this best practices!

 

In your code example, you set the file in a variable, but for example if I have different .txt files in the folder (with the same structure)...
how should I set the different files one by one?



 Category Survey
 06/05/2012 12:22 PM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

You just have to read the whole file (inside the loop) into the "hdr" variable.
Then the FINDTXT's will find the values from the "hdr" variable.
Tell me if you need more.

BTW, when you include task steps into a reply in the forum, use the "Reply" link, and in the message window, use the "Attach code" button. This way the code can be copied from that code window and pasted directly into the task builder.
This also avoids some problems with some AML tags that may jeopardize the full message.

 Category Survey
AutoMate 7 version:
Windows version:


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
 06/05/2012 12:25 PM
User is offline View Users Profile Print this message

Author Icon
Luiz FelipeAlcoforado
Student (5-19 posts)

Posts: 7
Joined: 05/31/2012

Great...

It is working now!!

Thanks a lot for your great support Jean!!

The problem was solved.

 



 Category Survey
 06/05/2012 12:35 PM
User is offline View Users Profile Print this message

Author Icon
JeanDelfosse
Supreme Guru (1000+)

Posts: 8883
Joined: 03/30/2005

You're welcome, Luiz

 Category Survey
AutoMate 7 version:
Windows version:


-------------------------
Jean Delfosse - Automate Beta Tester
Win7 Pro 64 bits -Win XP Pro SP3 32 bits - AM8, AM7, BPA10, BPA9, BPA8, BPA7, AM6 Enterprise, AM4
Statistics
18258 users are registered to the AutoMate Discussion forum.
There are currently 0 users logged in.
The most users ever online was 5551 on 01/08/2018 at 11:11 AM.
There are currently 1173 guests browsing this forum, which makes a total of 1173 users using this forum.

FuseTalk Enterprise Edition v4.0 - © 1999-2020 FuseTalk Inc. All rights reserved.

Sitemap Network Automation Software Blog